1 2 Previous Next 15 Replies Latest reply on Aug 30, 2012 5:39 AM by Kishor Pawar

    Sending Custom Response back to the client

    Kishor Pawar Newbie

      Hi,

       

      I am working on Jboss SOA Platform 5.1. I have 5 ESB services running on my Jboss, of which one is used for handling the Execptions(FaultHandlerService) in the ESB.

       

      I have one CXF service which acts as controller for all the 4 ESB services. CXF service does content based routing based on the input request.

      I have used ServiceInvoker to call the ESB services.


      ServiceInvoker si = new ServiceInvoker(esbServiceCategory,esbServiceName);

      Message respEsbMessage = si.deliverSync(esbMessage, 10000L);

       

      If any exception occurs in any of the ESB services, then that exception is given to the FaultHandlerService. This happen bcoz i have set FaultTo inside the CXF service.

       

      LogicalEPR defaultFaultToEpr = new LogicalEPR("Fault-Handler-Service-Category","FaultHandlerService");

      esbMessage.getHeader().getCall().setFaultTo(defaultFaultToEpr);

       

       

      When the exception comes to the FaultHandler Servcie, how can i send it back to the CXF service? This is the jboss-esb.xml for the FaulthandlerService.

      pls. let me know if any information is required.

       

      <?xml version="1.0"?>

      <jbossesb parameterReloadSecs="5"

      xmlns="http://anonsvn.labs.jboss.com/labs/jbossesb/trunk/product/etc/schemas/xml/jbossesb-1.3.0.xsd"

      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://anonsvn.labs.jboss.com/labs/jbossesb/trunk/product/etc/schemas/xml/jbossesb-1.3.0.xsd http://anonsvn.jboss.org/repos/labs/labs/jbossesb/trunk/product/etc/schemas/xml/jbossesb-1.3.0.xsd">

      <services>

        <service category="Fault-Handler-Service-Category"

         description="Handles the exceptions coming from various dispatchers"

         invmScope="GLOBAL" name="FaultHandlerService">

              <actions mep="OneWay">

                    <action class="com.sg.esb.FaultHandler" name="operation" process="throwException">

                         <property name="exceptionMethod" value="catchesException" />

                         <property name="LogName" value="FASLog"/>

                         <property name="ErrorLogName" value="FASErrorLog"/>

                    </action>

              </actions>

        </service>

      </services>

        • 1. Re: Sending Custom Response back to the client
          Iain Boyle Newbie

          Your FaultHandler service is defined as mep=OneWay, this means it will not send any reply - I suspect this is what you want to happen, since the job of a FaultHandler is to deal with the condition and not do something then reply back to the caller. If you do want a repsonse set mep=RequestResponse.

           

          Have you tried doing a static route as the last action in the FaultHandler service to the CXF Service?

           

          If you do route to the CXF service in an error condition, you have to make sure the CXF Service can distinguish if it is called via the FaultHandler or via a "normal" path - if you don't you can end up with a circular loop.

          • 2. Re: Sending Custom Response back to the client
            Kishor Pawar Newbie

            Hi Iain,

             

            Thank you for your reply.

            I tried giving mep=RequestResponse, but it goes into infinite loop, calls the ESB service with the response message from FaultHandlerService.

             

             

            "Have you tried doing a static route as the last action in the FaultHandler service to the CXF Service?"

            Do you want me to check the StaticRouter action like this.

            <action name="routeAction" class="org.jboss.soa.esb.actions.StaticRouter">
                  <property name="destinations">
                      <route-to service-category="ExpressShipping" service-name="ExpressShippingService"/>
                      <route-to service-category="NormalShipping" service-name="NormalShippingService"/>
                 </property>
            </action>
            • 3. Re: Sending Custom Response back to the client
              Iain Boyle Newbie

              > I tried giving mep=RequestResponse, but it goes into infinite loop, calls the ESB service with the response message from FaultHandlerService.

               

              This is why I suggested you make sure the CXF service can "distinguish if it is called via the FaultHandler or via a "normal" path - if you don't you can end up with a circular loop." !

               

              You only need one static route so something similar to the following should work

               

              <action name="routeAction" class="org.jboss.soa.esb.actions.StaticRouter">
                    <property name="destinations">

                        <route-to service-category="NormalShipping" service-name="NormalShippingService"/>

                   </property>

              </action>

              • 4. Re: Sending Custom Response back to the client
                joe_boy12 Novice

                not sure whether its right way or wrong - however I got it working by something like this

                 

                https://community.jboss.org/message/622789#622789

                 

                 

                • 5. Re: Sending Custom Response back to the client
                  Iain Boyle Newbie

                  Hi joe_boy12,

                   

                    The solution you suggest in https://community.jboss.org/message/622789#622789 is a good way of handling exceptions in a pipeline. The first action in pipeline is effectively a no-op, so the first pass processing of the pipeline ignores the action. If the pipeline detects an error, the second pass processing processes the pipeline in reverse looking for OnException methods, hence the first action defined becomes the last action to be processed and is therefore able to handle the exception.

                   

                    You have effectively provided an implemantation of a solution I described in https://community.jboss.org/message/751383#751383

                  • 6. Re: Sending Custom Response back to the client
                    Kishor Pawar Newbie

                    Joe/Iain,

                     

                    I tried implementing the way mentioned in https://community.jboss.org/message/622789#622789. But in the second pass it doesn't go into the OnException method. So it again enters the pipeline with the message from fault handler and ends in infinite loop. What might be wrong?

                    • 7. Re: Sending Custom Response back to the client
                      joe_boy12 Novice

                      Iain - thats correct.

                      • 8. Re: Sending Custom Response back to the client
                        joe_boy12 Novice

                        Kishore,

                         

                        Can you paste your jboss-esb.xml here? as long as I believe it should work.

                        • 9. Re: Sending Custom Response back to the client
                          Kishor Pawar Newbie

                          Joe,

                           

                          This is the jboss-esb.xml of the fault handler service.

                           

                          <?xml version="1.0"?>

                          <jbossesb parameterReloadSecs="5"

                              xmlns="http://anonsvn.labs.jboss.com/labs/jbossesb/trunk/product/etc/schemas/xml/jbossesb-1.3.0.xsd"

                              xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

                              xsi:schemaLocation="http://anonsvn.labs.jboss.com/labs/jbossesb/trunk/product/etc/schemas/xml/jbossesb-1.3.0.xsd http://anonsvn.jboss.org/repos/labs/labs/jbossesb/trunk/product/etc/schemas/xml/jbossesb-1.3.0.xsd">

                              <services>

                                  <service category="Fault-Handler-Service-Category"

                                      description="Handles the exceptions coming from various dispatchers"

                                      invmScope="GLOBAL" name="FaultHandlerService">

                                      <actions mep="RequestResponse">

                                          <action class="com.sg.esb.FaultHandler" name="operation"

                                              process="processException">

                                              <property name="exceptionMethod" value="catchesException" />

                                              <property name="LogName" value="FASLog" />

                                              <property name="ErrorLogName" value="FASErrorLog" />

                                          </action>

                                      </actions>

                                  </service>

                              </services>

                          </jbossesb>

                           

                           

                          and this is the jboss-esb.xml of the esb service that throws exception.

                           

                          <?xml version="1.0"?>

                          <jbossesb parameterReloadSecs="5"

                              xmlns="http://anonsvn.labs.jboss.com/labs/jbossesb/trunk/product/etc/schemas/xml/jbossesb-1.2.0.xsd"

                              xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

                              xsi:schemaLocation="http://anonsvn.labs.jboss.com/labs/jbossesb/trunk/product/etc/schemas/xml/jbossesb-1.2.0.xsd http://anonsvn.jboss.org/repos/labs/labs/jbossesb/trunk/product/etc/schemas/xml/jbossesb-1.2.0.xsd">

                           

                              <services>

                                  <service category="USA-Global-System-Services" description="Global System Services"

                                      invmScope="GLOBAL" name="USGSSDispatcher">

                                      <actions mep="OneWay">

                                          <action class="org.jboss.soa.esb.actions.SystemPrintln" name="print-message">

                                              <property name="message"

                                                  value="----- Before invocation of GSS services ------" />

                                          </action>

                                          <action class="org.jboss.soa.esb.actions.ContentBasedRouter"

                                              name="USA-Global-Services-Router">

                                              <property name="cbrAlias" value="Xpath" />

                                              <property name="ruleLanguage" />

                                              <property name="destinations">

                                                  <route-to destination-name="toGetR2Wfile"

                                                      expression="/soap:Envelope/soap:Body/esb:Execute/esb:Request/esb:MethodName='GetFileFromSystem'"

                                                      service-category="USA-Global-System-Operations" service-name="Global-System-R2W" />

                                              </property>

                                              <property name="namespaces">

                                                  <namespace prefix="soap"

                                                      uri="http://schemas.xmlsoap.org/soap/envelope/" />

                                                  <namespace prefix="esb" uri="http://sg.com/esb/" />

                                              </property>

                                          </action>

                                      </actions>

                                  </service>

                                  <service category="USA-Global-System-Operations" description="R2W functionality"

                                      invmScope="GLOBAL" name="Global-System-R2W">

                                      <actions mep="RequestResponse">

                                          <action class="org.jboss.soa.esb.actions.SystemPrintln" name="print-in">

                                              <property name="message"

                                                  value="------- Inside Global-System-R2W webservice ----------------" />

                                          </action>

                                                          <!-- new addition starts here -->

                                          <action name="startAction"

                                              class="com.sg.esb.gss.action.sharedservices.ErrorHandlingAction"

                                              process="process" />

                                          <!-- new addition ends here -->

                                          <action class="com.sg.esb.gss.action.sharedservices.Report2WebRequest"

                                              name="create-request-map" process="CreateRequestMap">

                                              <property name="exceptionMethod" value="ExceptionHandler" />

                                              <property name="LogName" value="GSSLog" />

                                              <property name="ErrorLogName" value="GSSErrorLog" />

                                          </action>

                                          <action class="org.jboss.soa.esb.actions.soap.SOAPClient"

                                              name="invoke-global-services">

                                              <property name="wsdl"

                                                  value="http://${inspection.r2w.wsdl.url}/SG.WebServices.Global/Files/Inspections.asmx?wsdl" />

                                              <property name="SOAPAction"

                                                  value="http://tempuri.org/GetFileFromR2WFileSystem" />

                                              <property name="responseAsOgnlMap" value="false" />

                                              <property name="operation" value="GetFileFromR2WFileSystem" />

                                          </action>

                                          <action class="com.sg.esb.gss.action.sharedservices.Report2WebResponse"

                                              name="receive-response" process="CreateResponseMap">

                                              <property name="Performer" value="${inspection.r2w.wsdl.url}" />

                                              <property name="Entity" value="GSS" />

                                              <property name="exceptionMethod" value="exceptionHandler" />

                                              <property name="LogName" value="GSSLog" />

                                              <property name="ErrorLogName" value="GSSErrorLog" />

                                          </action>

                                          <action class="org.jboss.soa.esb.actions.SystemPrintln" name="print-after">

                                              <property name="message"

                                                  value="&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp; --------------------- Global Webservice invoked ----------------------- &amp;&amp;&amp;&amp;&amp;&amp;&amp;" />

                                          </action>

                                      </actions>

                                  </service>

                                  <service category="Utility" name="ServeErrorService"

                                      description="" invmScope="GLOBAL">

                                      <actions mep="RequestResponse">

                                          <action name="myAction"

                                              class="com.sg.esb.gss.action.sharedservices.ErrorHandlingAction"

                                              process="processErrors" />

                                      </actions>

                                  </service>

                              </services>

                          </jbossesb>

                           

                          i want to handle the exception thrown by org.jboss.soa.esb.actions.soap.SOAPClient.

                          • 10. Re: Sending Custom Response back to the client
                            joe_boy12 Novice

                            thanks - can you post source for ErrorHandlingAction as well?

                             

                            • 11. Re: Sending Custom Response back to the client
                              Kishor Pawar Newbie

                              Joe,

                               

                              I am using the same code which you have posted in https://community.jboss.org/message/622789#622789.

                               

                              public class ErrorHandlingAction extends AbstractActionLifecycleRequest_base{

                               

                                  @Process

                                  public Message process(Message message) throws Exception

                                  {

                                      getEsbLog().log("--- In process of ErrorHandlingAction ---");

                                      getEsbLog().log("Message :"+message.toString());

                                      return message;

                               

                                  }

                               

                                  public ErrorHandlingAction(ConfigTree config) {

                                      super(config);

                                      // TODO Auto-generated constructor stub

                                  }

                               

                                  @Process

                                  public Message processErrors(Message message) throws Exception

                                  {

                                      System.out.println("--- In processErrors of ErrorHandlingAction ---");

                                      StringBuffer buffer = new StringBuffer();

                                      buffer.append("<Errors><Error code=\"9999\">");

                                      buffer.append(message.getBody().get("exceptionTrace").toString());

                                      buffer.append("</Error></Errors>");

                                      message.getBody().add(buffer.toString());

                                      System.out.println("Message:"+message.toString());

                                      return message;

                                  }

                               

                                  @OnSuccess

                                  public void processSuccess(Message message)

                                  {

                                      System.out.println("--- In success of ErrorHandlingAction ---");

                                  }

                               

                               

                                  @OnException

                                  public void processException(Message message, Throwable t) throws ActionProcessingException, FaultMessageException, RegistryException

                                  {

                                      System.out.println("--- In processException of ErrorHandlingAction ---");

                                      if( message != null )

                                      {

                                          message.getBody().add("exceptionTrace",message.getFault().getReason().toString());

                                          try {

                                              Service errorService = new Service("Utility", "ServeErrorService");

                                              ServiceInvoker si = new ServiceInvoker(errorService);

                                              si.deliverSync(message, 10000);

                                          } catch (MessageDeliverException e) {

                                              e.printStackTrace();

                                              throw new ActionProcessingException(e.getMessage(), e);

                                          }

                                      }

                                  }

                               

                              }

                              • 12. Re: Sending Custom Response back to the client
                                joe_boy12 Novice

                                sorry for late reply - do u see System.out.println("--- In success of ErrorHandlingAction ---"); executing at all?

                                 

                                also what is extends AbstractActionLifecycleRequest_base?

                                • 13. Re: Sending Custom Response back to the client
                                  Kishor Pawar Newbie

                                  Sorry for replying late.

                                  I dont see "--- In success of ErrorHandlingAction ---" statement.

                                   

                                  It extends a AbstractActionLifecycleRequest_base class which extends AbstractActionLifecycle.

                                   

                                   

                                  public class AbstractActionLifecycleRequest_base extends AbstractActionLifecycle  {

                                   

                                      protected ConfigTree _config;  

                                       .

                                       .

                                       .

                                  • 14. Re: Sending Custom Response back to the client
                                    joe_boy12 Novice

                                    So its not even hitting for the first pass. dont extend anything - let annotations play their role.

                                    1 2 Previous Next