3 Replies Latest reply on Nov 21, 2012 8:39 AM by splatch

    Auditing an exception response

    objectiser

      Hi,

       

      I've created a simple auditor but I'm having trouble observing an exception being returned instead of a message response. The auditor is:

       

       

      package org.test;
      
      import org.switchyard.bus.camel.processors.Processors;
      import org.apache.camel.Exchange;
      import org.switchyard.bus.camel.audit.Audit;
      import org.switchyard.bus.camel.audit.Auditor;
      import javax.inject.Named;
      
      @Audit //({Processors.CONSUMER_CALLBACK})
      @Named("Error handler")
      public class ErrorHandler implements Auditor {
      
          @Override
          public void beforeCall(Processors processor, Exchange exchange) {
              System.out.println("Before " + processor.name()+ " exchange="+exchange);
      
              if (exchange.isFailed()) {
                  System.out.println("EXCHANGE FAILED");
              }
      
              System.out.println("Exception: "+exchange.getException());
              System.out.println("Out: "+exchange.getOut());
          }
      
          @Override
          public void afterCall(Processors processor, Exchange exchange) {
              System.out.println("After " + processor.name()+ " exchange="+exchange);
      
              if (exchange.isFailed()) {
                  System.out.println("EXCHANGE FAILED");
              }
      
              System.out.println("Exception: "+exchange.getException());
              System.out.println("Out: "+exchange.getOut());
          }
      
      }
      

       

      I've attached the full log, but basically I get the following information from all of the callbacks:

       

      10:18:16,112 INFO  [stdout] (ODEServer-1) After PROVIDER_CALLBACK exchange=Exchange[Message: [Body is null]]

      10:18:16,113 INFO  [stdout] (ODEServer-1) Exception: null

      10:18:16,113 INFO  [stdout] (ODEServer-1) Out: Message: [Body is null]

       

      Although the javadoc for the 'isFailed' method on the exchange indicates that it will be true if a fault or exception is returned, this is returning false - and the exception and out message appear to be empty. Not sure how to determine and access the exception?

       

      Another question is, what occurs in the DOMAIN_HANDLERS to change the camel exchange's toString from initially reporting the request contents, to showing it as "Body is null"?

       

      10:18:15,260 INFO  [stdout] (http--127.0.0.1-8080-1) Before DOMAIN_HANDLERS exchange=Exchange[Message: <loan:request xmlns:loan="http://example.com/loan-approval/loanService/">

      10:18:15,261 INFO  [stdout] (http--127.0.0.1-8080-1)          <loan:firstName>Fred</loan:firstName>

      10:18:15,261 INFO  [stdout] (http--127.0.0.1-8080-1)          <loan:name>Bloggs</loan:name>

      10:18:15,262 INFO  [stdout] (http--127.0.0.1-8080-1)          <loan:amount>1000</loan:amount>

      10:18:15,262 INFO  [stdout] (http--127.0.0.1-8080-1)       </loan:request>]

      10:18:15,262 INFO  [stdout] (http--127.0.0.1-8080-1) Exception: null

      10:18:15,262 INFO  [stdout] (http--127.0.0.1-8080-1) Out: Message: [Body is null]

      10:18:15,266 INFO  [stdout] (http--127.0.0.1-8080-1) After DOMAIN_HANDLERS exchange=Exchange[Message: [Body is null]]

      10:18:15,266 INFO  [stdout] (http--127.0.0.1-8080-1) Exception: null

      10:18:15,266 INFO  [stdout] (http--127.0.0.1-8080-1) Out: Message: [Body is null]

       

       

      Thanks in advance.

       

      Regards

      Gary

        • 1. Re: Auditing an exception response
          splatch

          Hey Gray,

          The afterCall is not called in case of failures - it's not reflected in javadoc but in docs: https://docs.jboss.org/author/display/SWITCHYARD/Auditing+Exchanges.

           

          For now camel exchange do not contain 1:1 copy of data. It's kinda tricky - to get actual payload you need following code:

           

          org.switchyard.Exchange syEx = camelExchange.getProperty(org.switchyard.bus.camel.ExchangeDispatcher.SY_EXCHANGE, org.switchyard.Exchange.class);
          Object contents = syEx.getMessage().getContent();
          

           

          Because components we have still depends on SwitchYard API before camel exchange bus was introduced there was no simple transition..

           

          I hope that will help.

          • 2. Re: Auditing an exception response
            objectiser

            Hi Lukasz

             

            The afterCall is not called in case of failures - it's not reflected in javadoc but in docs: https://docs.jboss.org/author/display/SWITCHYARD/Auditing+Exchanges.

             

             

            Yes had seen that in the docs - but from the server log you can see that the afterCall methods are being called.

             

            I'll have a try retrieving the exchange as you have described and let you know. I think this needs to be added to the auditing exchange docs, as otherwise users will not know how to access the message.

             

            Regards

            Gary

            • 3. Re: Auditing an exception response
              splatch

              Hey Gary,

              Your observation is again correct. Fault response returned by service is not an exception in terms of SwitchYard bus mediation. To skip call of auditor an exception must be thrown from SwitchYard component.