Java Reference
In-Depth Information
Validating a SOAP Payload Against a Schema with
Metro
Problem
You want an easier way to validate your messages against an XML schema than the one you
saw using SAAJ in Validating Your Payload Against a Schema on the Client .
Solution
Use the annotation com.sun.xml.ws.developer.SchemaValidation from Metro on your
service class. You can also use the handler attribute on this annotation to point to a particular
class that implements the Handler interface that can respond to the validation events.
On the client side, create a new SchemaValidationFeature and pass it to your port.
Discussion
If you want to validate payloads against a schema on the client, you can use the schema valid-
ation feature, like this:
SignatureCapture port = null;
try {
final SigCapService service =
new SigCapService(wsdlLocation, QNAME);
port = service.getSignatureCapturePort(
new AddressingFeature(),
new SchemaValidationFeature(
SigCapClientValidationHandler.class));
//invoke service...
Here you have used wsimport to generate artifacts to use in invoking the service. The
variable-length argument list that the generated port proxy accepts allows you to pass zero
or more features that you'd like the JAX-WS runtime to manage for you. Here I'm using
two: WS-Addressing, and schema validation. This will examine the payload of the outbound
SOAP message during marshaling of the Java object to XML, and create an instance of the
SigCapClientValidationHandler class. Inside this handler class, you implement the re-
Search WWH ::




Custom Search