0 Replies Latest reply on Aug 23, 2011 5:34 AM by Alexander Kiselyov

    Handle EndpointServlet-produced SOAP faults (JAX-RPC)

    Alexander Kiselyov Newbie

      Hi All,

       

      I've got very simple question: are developers able to handle SOAP faults (JAX-RPC, JBoss 4.2.3), which are

      results of exceptions that occur outside actual endpoint call?

       

      My services are configured like this:

       

      web.xml extract:

       

         <servlet>

          <servlet-name>ServiceAServlet</servlet-name>

          <servlet-class>org.jboss.wsf.stack.jbws.EndpointServlet</servlet-class> 

          <init-param>

            <param-name>jboss.ws.endpoint</param-name> 

            <param-value>my.package.service.ServiceAImpl</param-value>

          </init-param>

        </servlet>

       

      webservices.xml extract:

       

      <port-component>

          <port-component-name>ServA</port-component-name>

          <wsdl-port>ServAPort</wsdl-port>

          <service-endpoint-interface>my.package.service.ServiceA</service-endpoint-interface>

          <service-impl-bean>

              <servlet-link>ServiceAServlet</servlet-link>

          </service-impl-bean>

          <handler>

              <handler-name>Fault Handler</handler-name>

              <handler-class>my.package.handlers.FaultHideHandler</handler-class>

          </handler>

      </port-component>

       

      Dummy test handler:

       

      public class FaultHideHandler extends GenericHandler {

       

          /*

           * (non-Javadoc)

           *

           * @see javax.xml.rpc.handler.GenericHandler#getHeaders()

           */

          @Override

          public QName[] getHeaders() {

              return new QName[0];

          }

       

       

          /*

           * (non-Javadoc)

           *

           * @see

           * javax.xml.rpc.handler.GenericHandler#handleFault(javax.xml.rpc.handler

           * .MessageContext)

           */

          @Override

          public boolean handleFault(MessageContext context) {

              if (context instanceof SOAPMessageContext) {

                  SOAPMessage message = ((SOAPMessageContext) context).getMessage();

                  try {

                      SOAPBody body = message.getSOAPBody();

                      SOAPFault fault = body.getFault();

                      System.out.println(fault.getFaultCode());

                      System.out.println(fault.getFaultCodeAsName());

                      System.out.println(fault.getFaultCodeAsQName());

                      System.out.println(fault.getFaultString());

                  } catch (SOAPException e) {

                      e.printStackTrace();

                  }

              }

              return true;

          }

      }

       

      When some exception (e.g. related to the message parse) throw, e.g.:

       

      javax.xml.rpc.soap.SOAPFaultException: org.xml.sax.SAXParseException: The element type "int_2" must be terminated by the matching end-tag "</int_2>".

          at org.jboss.ws.core.jaxrpc.SOAPFaultHelperJAXRPC.exceptionToFaultMessage(SOAPFaultHelperJAXRPC.java:189)

          at org.jboss.ws.core.jaxrpc.SOAP11BindingJAXRPC.createFaultMessageFromException(SOAP11BindingJAXRPC.java:63)

          at org.jboss.ws.core.CommonSOAPBinding.bindFaultMessage(CommonSOAPBinding.java:671)

          at org.jboss.wsf.stack.jbws.RequestHandlerImpl.processRequest(RequestHandlerImpl.java:488)

          at org.jboss.wsf.stack.jbws.RequestHandlerImpl.handleRequest(RequestHandlerImpl.java:284)

          at org.jboss.wsf.stack.jbws.RequestHandlerImpl.doPost(RequestHandlerImpl.java:201)

          at org.jboss.wsf.stack.jbws.RequestHandlerImpl.handleHttpRequest(RequestHandlerImpl.java:134)

          at org.jboss.wsf.stack.jbws.EndpointServlet.service(EndpointServlet.java:84)

      ...

       

      client receive comprehensive fault message:

       

      <env:Envelope xmlns:env="http://schemas.xmlsoap.org/soap/envelope/">

         <env:Header/>

         <env:Body>

            <env:Fault>

               <faultcode>env:Client</faultcode>

               <faultstring>org.xml.sax.SAXParseException: The element type "int_2" must be terminated by the matching end-tag "&lt;/int_2>".</faultstring>

            </env:Fault>

         </env:Body>

      </env:Envelope>

       

      but handler isn't triggered. When fault caused by exception, thrown by endpoint implementation itself - it works perfect.

      Modifying standard-jaxrpc-endpoint-config.xml didn't help either.

       

      So, is there some way to do it? Any help is greatly appreciated.