8 Replies Latest reply on Sep 10, 2012 8:29 PM by joe_boy12

    Catching exceptions in the actions pipeline.

    mlog

      Hi.

      I have an ESB service that looks like this one:

       

          <service category="serviceCategory" name="serviceName" description="" invmScope="GLOBAL">
             <actions mep="RequestResponse" inXsd="request.xsd" outXsd="response.xsd">
                <action name="transform-request" class="org.jboss.soa.esb.smooks.SmooksAction">
                   <property name="smooksConfig" value="transform-request.xml"/>
                   <property name="resultType" value="JAVA"/>
                </action>
                <action name="call-business-method" class="business.method.caller"/>
                <action name="transform-responce" class="org.jboss.soa.esb.smooks.SmooksAction">
                   <property name="smooksConfig" value="transform-response.xml"/>
                </action>
             </actions>
          </service>
      

       

      This service is exposed as web service, receives soap message, transforms it into java class instance, calls EJB method with this instance as parameter, transforms java class response into soap message and returns it.

      It works fine until soap requests are correct. If not smooks throws the exception, pipeline execution stops and soap client receives an incorrect response.

      I spend a lot of time to find the way to catch the smooks' exception and transform it to my response scheme, but found nothing. So, my first question is if there is any way to do it?

      While I was looking for the answer I found a few similar questions but no one was answered. If there is no way to catch action's exception is the design of service that needs it wrong? If so could anyone point me to the right one? How to handle errors in the actions pipeline? I am not experienced in SOA, any article, example or advice will be helpful for me.

       

      Thanks in advance and sorry for my wrong English.

        • 1. Re: Catching exceptions in the actions pipeline.
          joe_boy12

          I have a proof of concept of doing that.... here are the steps.. add jms-provider in jboss-esb.xml (technicall you dont need it - but my server goes in infinite loop if I use InVm transport). Add a starting action in your service. Add another service which is responsible to send the customized response back to client. Add the Action class which does that. Reproduce the error and see if you get the <Error>..... response.

           

          <providers>
            <jms-provider name="JBossMessaging" connection-factory="XAConnectionFactory">
             <jms-bus busid="ErrorBus">
              <jms-message-filter dest-type="QUEUE" dest-name="queue/ErrorQueue" transacted="true"/>
             </jms-bus>
            </jms-provider>
          </providers>

           

           

              <service category="serviceCategory" name="serviceName" description="" invmScope="GLOBAL">
                 <actions mep="RequestResponse" inXsd="request.xsd" outXsd="response.xsd">
                    <!-- new addition starts here -->
                    <action name="startAction" class="my.action.ErrorHandlingAction" process="process"/>
                    <!-- new addition ends here -->
                             
                    <action name="transform-request" class="org.jboss.soa.esb.smooks.SmooksAction">
                       <property name="smooksConfig" value="transform-request.xml"/>
                       <property name="resultType" value="JAVA"/>
                    </action>
                    <action name="call-business-method" class="business.method.caller"/>
                    <action name="transform-responce" class="org.jboss.soa.esb.smooks.SmooksAction">
                       <property name="smooksConfig" value="transform-response.xml"/>
                    </action>
                 </actions>
              </service>

           

            <service category="Utility" name="ServeErrorService" description="">
             <listeners>
              <jms-listener name="error-channel" busidref="ErrorBus"/>
             </listeners>
             
             <actions mep="RequestResponse">
              <action name="myAction" class="my.action.ErrorHandlingAction" process="processErrors"/>
             </actions>
            </service>

           

          add this action to your source code.

           

          package my.action;


          public class ErrorHandlingAction {

          @Process
          public Message process(Message message) throws Exception
          {
            return message;
          }

          @Process
          public Message processErrors(Message message) throws Exception
          {
            StringBuffer buffer = new StringBuffer();
            buffer.append("<Errors><Error code=\"9999\">");
            buffer.append(((Throwable)message.getBody().get("exceptionTrace")).getMessage());
            buffer.append("</Error></Errors>");
            message.getBody().add(buffer.toString());
           
            return message;
          }

          @OnSuccess
          public void processSuccess(Message message)
          {
          }


          @OnException
          public void processException(Message message, Throwable t) throws ActionProcessingException
          {
            if( message != null )
            {
             message.getBody().add("exceptionTrace",t);
                      try {
                 Service errorService = new Service("Utility", "ServeErrorService");
                          ServiceInvoker si = new ServiceInvoker(errorService);
                          si.deliverSync(message, 1000);
             } catch (Exception e) {
              e.printStackTrace();
              throw new ActionProcessingException(e.getMessage(), e);
             }
            }
          }

          }

           

          • 2. Re: Catching exceptions in the actions pipeline.
            h.wolffenbuttel

            Hi Joe,

             

            Does JBossESB do anything with the 'Error code="9999" ' ? Or is this your own preferred implementation of the returned answer?

             

            Regards,

             

            Hans

            • 3. Re: Catching exceptions in the actions pipeline.
              mlog

              Hi, Joe.

               

              Thank you very much for your reply. It works, and it is exactly what I need!

              By the way, in my environment (JBossESB 4.9 on JBossAS 5.1.0.GA) it works fine with InVM transport too.

               

              Thank you again.

              • 4. Re: Catching exceptions in the actions pipeline.
                joe_boy12

                mlog - I have the same set up but the moment I use

                  <service category="Utility" name="ServeErrorService" description="" invmScope="GLOBAL"> and remove JMS queue - I still get the correct response but my server goes in infinite loop.

                 

                @Hans - No this is just a PoC I tried to send my customized reply in case of Synch calls over HttpGateways - there is still lot to do. The 9999 is just static error code I am using for PoC - nothing to do with JBoss specifications.

                 

                Please share if you guys have better idea to implement this stuff - I would really appreciate that.

                 

                Joe

                 

                • 5. Re: Catching exceptions in the actions pipeline.
                  dulee

                  Hi All,

                   

                  I'm using jboss esb 4.10.

                  When an action threw exception, I see that the method processException does not work. ESB does not call this method.

                   

                  Who has met this problem before, please help me.

                   

                  Thanks,

                  • 6. Re: Catching exceptions in the actions pipeline.
                    joe_boy12

                    can you post your Action code and jboss-esb.xml snippet?

                    • 7. Re: Catching exceptions in the actions pipeline.
                      dulee

                      Dear joe_boy,

                       

                      Here is my action class:

                      public class MyAction extends AbstractActionLifecycle {

                           public MyAction(Config config) {

                              ///set config

                            }

                       

                           public Message process(Message msg) {

                               throw new Exception("aaaaaa");

                            }

                       

                           @OnException

                           public void handleError(Message msg, Throwable t) {

                                /handle exception

                            }

                      }

                       

                      Jboss-esb.xml is similar to your file. But it has only 1 action.

                       

                        <service category="cat" name="testErrorHandler" description="" invmScope="GLOBAL">

                             <listeners>

                                                              <jms-listener name="mychannel" busidref="testErrorBus"/>

                             </listeners>

                             <actions mep="RequestResponse">

                                <action name="startAction" class="my.Myaction" process="process"/>

                             </actions>

                        </service>

                       

                      But the method handleError is not called

                      • 8. Re: Catching exceptions in the actions pipeline.
                        joe_boy12

                        try extending to AbstractActionPipelineProcessor and override

                        processException, or dont extend anything and just use annotations.