Override CXF error handling

后端 未结 3 1085
暗喜
暗喜 2020-12-31 12:44

I am working on some web-services based application and I have a question about Apache CXF unmarshalling. In our project we use CXF 2.4.1 version.

When some SOAP req

3条回答
  •  孤城傲影
    2020-12-31 13:41

    You can certainly generate a better error response than the default using ValidationEventHandler and throwing a Fault that conforms to the JAX-WS Fault spec. But it will only allow you so much customization - there will be some elements that you have no control over. For example, here is the ValidationEventHandler response from one of my apps:

    
       
          
             soap:Client
             Errors in request
             
                
                   
                      
                         topicId
                         java.lang.NumberFormatException: For input string: "" [line:6]
                      
                   
                
             
          
       
    
    

    You can't do anything about the , and elements. But everything from to is custom.

    If you need to have more detailed control over the response then you should change the field type from numeric to string and then do the validation in your code instead of letting the unmarshaller catch the error.

    Yes, I agree, forcing it to be a string would suck but if the response has to be exactly what you spec'd above it will not be possible without diving deeper into CXF than the JAX-WS layer (for example using an interceptor).

提交回复
热议问题