I am currently encountering a problem with error codes and messages using Spring WS.
We use Spring WS 2.0 with JAXB2 binding and @Endpoint and @PayloadRoot annotations for convenience.
Our endpoint is as follows:
@Endpoint public class MyEndpoint() { private static final String MY_NAMESPACE=...; @PayloadRoot(namespace=MY_NAMESPACE, localPart="myPart") public MyPartResponse handleMyPart(MyPart myPart) { .... } }
We use soap only as a thin wrap around the POX message defined by XSD. It also means that instead of errors, we use return codes and messages.
Each answer inherits from
<xs:complexType name="ResultBase"> <xs:sequence> <xs:element name="errorCode" type="tns:ErrorCode" /> <xs:element name="errorMessage" type="xs:string" /> </xs:sequence> </xs:complexType>
and adds some features if successful, for example:
<xs:element name="MySpecificResponse"> <xs:complexType> <xs:complexContent> <xs:extension base="tns:ResultBase"> <xs:sequence> <xs:element name="mySpecificElement" type="tns:MySpecificType" /> </xs:sequence> </xs:extension> </xs:complexContent> </xs:complexType> </xs:element>
All exceptions that are thrown inside the handleMyPart method can be clearly displayed.
However, two types of errors remain invisible and generate errors instead of an explicit error message:
- XSD Validation Errors
- Invalid XML Errors
At the end of the day, these are problems that apply to every POX web service using Spring WS . How should these exceptions be caught and then the response object displayed?
Remember that: all response objects are slightly different , since they all inherit from the general, but add some unique additional content to it.
java soap spring-ws web-services jaxb2
Axel fontaine
source share