Link to home
Start Free TrialLog in
Avatar of vradoi
vradoi

asked on

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

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????????
             
                }
      }
ASKER CERTIFIED SOLUTION
Avatar of Siva Prasanna Kumar
Siva Prasanna Kumar
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial