This week's book giveaway is in the Jobs Discussion forum.
We're giving away four copies of Java Interview Guide and have Anthony DePalma on-line!
See this thread for details.
The moose likes Web Services and the fly likes Web Service Request Validation against WSDL Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Web Services
Bookmark "Web Service Request Validation against WSDL" Watch "Web Service Request Validation against WSDL" New topic

Web Service Request Validation against WSDL

Sudhakar Jampa

Joined: Jan 29, 2005
Posts: 7
Any idea how to do Web Service Request Validation against Schema (WSDL file)in case of a Doc/Wrapped Service.

My idea is to create the XML out of request and validate it with WSDL file I have. But I'm not able to generate XML from my Request Object.

Peer Reynders

Joined: Aug 19, 2005
Posts: 2933
In both JAX-RPC and JAX-WS message header and payload validation would typically happen in a MessageHandler. If validation fails the handler would initiate the SOAPFault and the service application will never see the request.

Writing a Handler in JAX-WS

The SOAPHandler receives a SOAPMessageContext. With SOAPMessageContext.getMessage().getSOAPBody() you can get the javax.xml.soap.SOAPBody which implements org.w3c.dom.Element which ultimately gives you access to the SOAP payload (XML document) which you should be able to validate. Raise a if the validation fails. At this point fault processing begins and the handleFault method is called on the handlers that have already processed the in-bound request in reverse order. That means that your validation handler is the first handler called - so you assemble the fault response in its handleFault method (if it was the one that threw the ProtocolException in the first place). Alternately you could just simply build the fault in handleMessage and give it to the SOAPFaultException that you throw (example).

See JSR-000224 JavaTM API for XML-Based Web Services 2.0 (Final Release) for details.

In JAX-RPC you would use javax.xml.rpc.handler.Handler. You would perform the validation on the handleRequest method. javax.xml.rpc.handler.MessageContext is in fact a javax.xml.rpc.handler.soap.SOAPMessageContext which also has a getMessage() method ultimately giving you access to the SOAP payload. If validation fails you throw a javax.xml.rpc.soap.SOAPFaultException. The handlers handleFault method is immediately invoked by the container where you can assemble the fault response.
[ March 04, 2008: Message edited by: Peer Reynders ]
I agree. Here's the link:
subject: Web Service Request Validation against WSDL
It's not a secret anymore!