Announcement Announcement Module
Collapse
No announcement yet.
Error handling Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Error handling

    Hello,

    I am new to Spring Integration and trying to play with the error handling piece of the framework. For a background I have a big flow consisting splitters, aggregators, transformers, routers etc.. and all happy paths are working fine and now I want to add the error handling capabilities like explained in one of the recent seminar. I added an error channel followed by transformer to my starting gateway. So when any runtime exception happens in my flow I get a Messaging Exception back with a cause set to an actual exception in my transformer. But the strange thing is if I remove that error channel and by that the error flow, my actual run time exception gets propagated to the caller and not the MessagingException. And what I read was Framework always wraps all the exceptions to a MessagingException.
    Please correct me if I am wrong and provide some insight in error handling. And what should be a best practice to handle runtime exceptions with Spring Integration?

  • #2
    It depends on the signature of your gateway method.

    If you declare a method that, say, throws FooException; the gateway will try to unwrap it for you. If not, you'll get the MessagingException.

    Comment


    • #3
      Thank you so much for the quick response.

      So following is a code for my gateway which is called from one java class:
      Code:
      public interface IntegrationGateway {
          Object  execute(Message m);	
      }
      and code for java class:
      Code:
      try {
      	// invoke the gateway
      	response = gateway.execute(message);
           } catch (MessagingException exception) {
      	logger.debug("Messaging Exception..",exception);
           }catch(NullPointerException ne){
      	logger.debug("Yeah I received Null..",ne);
           }catch (Exception e){
      	logger.debug("Exception is...:"+e);
           }
      So I am expecting following exceptions:
      1) SOAP Fault
      2) Any runtime like NullPointer Exception

      Now if I have error channel and my transformer, it goes to a catch block of Messaging Exception. And when I remove them, it goes to catch block of NullPointerException in case of NullPointer exception and to catch block of Exception in case of SOAP Fault exception.

      For the reference following is the method signature of my transformer after error channel:
      Code:
      public void transform(MessagingException exception){
      // Logic to work with exception
      }
      Am I doing something wrong in my code?

      Comment


      • #4
        I should have explained further; the above discussion was about checked exceptions (exceptions that are not subclasses of RuntimeException).

        The gateway also unwraps most RuntimeExceptions (and subclasses). Any RuntimeExceptions (that are not MessagingException, UndeclaredThrowableException or IllegalStateException who's message is 'Unexpected Exception Thrown') are also unwrapped.

        NullpointerException is a RuntimeException, so it is unwrapped.

        With an error channel; no unwrapping is performed and the full context of the exception is forwarded in the ErrorMessage.

        The main reason for this behavior is to minimize the exposure of Spring Integration to your application. Where possible, you get the native exception thrown by endpoints in the downstream flow (checked or otherwise); you only get MessagingException if something in the framework or configuration failed, and you can catch those in a generic RuntimeException catch block, rather than exposing your application to the messaging infrastructure.

        Comment

        Working...
        X