The client part of Spring WS can validate the parsed XML before it sends the XML document.
You only need to specify a validator interceptor in the configuration and reference to it from the Web Service Template bean.
The @Soap Fault annotation below helps the exception resolver to convert the exception to a Soap Fault.
It’s a contract first web service that uses JAXB for the binding.
The focus area is how to configure and use Spring WS.
Create a String Reader with the String and create a Stream Source object with the String Reader.
For all the details, see the source code: When the Payload Validating Interceptor work as expected, the interceptor will throw a Web Service Validation Exception when you try to send a value that’s not valid according to the XSD schema. The validation issues is a minus, but since it’s an open-source project, you always have the chance to replace or extend the classes you want.
Since Spring WS doesn’t use a service contract, you must know the request and response type.
The test below demonstrates how to create and instantiate a request object of a JAXB generated class, call the marshall Send And Receive method with it and how to cast the response object to an object of the JAXB generated response class.
The WSDL file is generated from one or more XSD schemas and some few Spring configuration beans. The request element must end with Request and the response element must end with Response. The WSDL operation will be the element names except the Request/Response part.
Here is the generated WSDL operation: The server code isn’t aware of the WSDL.
This is a different approach than for example CXF that generates an interface your implementation must implement.