Web Service Handler: SOAP Fault Handling in the handleRequestI() method.

vradoi
vradoi used Ask the Experts™
on
Hi,
RE: Handling the SOAP fault exception in a custom web service handler as such that the custom SOAP fault is send back to the client.
Platform: WebSphere 6.1.x
WebService: JAX-RPC

Basically, the intention is to validate the incoming SOAP request inside a custom SOAP handler class that extends the: javax.xml.rpc.handler.GenericHandler
Given the handleRequest() method, the SOAP message is validated and if the message has grammer errors then a SOAP fault is created and it is re-directed back to the client.
As is stands, I am looking for an exception handling techique at the handleRequest() level that will force the WebSphere webservice engine to send back to the client the SOAP fault.

Here is an implementation sample:

imports....
public final class SoapNGLHandler extends GenericHandler {

public boolean handleRequest(MessageContext context) {
            
            try {
                  // ******Decompose the SOAP message
                  SOAPMessageContext smc = (SOAPMessageContext) context;
                  ......................................
                  //******Get the Soap body and validate it against the schema
                  String errMsg = validateAgainstWSDL();
           
             if ( errMsg == null ) {
                      return true;
              }
                 
                 //*******Build the SOAP fault that needs to be returned to the client                
                   SOAPFactory fac = SOAPFactory.newInstance();
             QName faultCode = new QName("http://bla.com/faults", "inputMessageValidationFault");  
             Detail detail = fac.createDetail();
             DetailEntry de = detail.addDetailEntry(fac.createName("http://bla.com/faults",  null, "inputMessageValidationFault"));
             de.setValue("1000");  
                 
                  //*******Construct the SOAP fault exception and force the webservice engine to finish processing and return the fault to the client ??????
                  throw new SOAPFaultException(faultCode, "faultString", "faultActor", detail); // is this the right exception or other implementation???
                 
                } catch (Exception e) {
                  e.printStackTrace();
                  throw new WebServiceException(e); // what will be the exception or the other implementation????????
             
                }
      }
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Principal Solutions Architect
Top Expert 2006
Commented:
Hi Vradoi,

By default almost all the frame works do this validation against WSDL, as you are using standard jax RPC

you can use this link for more details :http://www.roseindia.net/javacertification/wsd-guide/jax_rpc_handler.shtml

SOAPFaultExeptions are preferable type of faults, we generally throw this type when events like this happen, incoming SOAP msg doesn't validate, has different encoding than expected, different version.

WebServiceExceptions are generic exceptions like   when a session or context not found, generally these are technical errors as shown below

if (session == null)
            throw new WebServiceException("No session in WebServiceContext");

If your intention is through to just validate the msg and throw appropriate fault you are better off using SOAPFaultExeptions.

Thanks

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial