Announcement Announcement Module
No announcement yet.
Is it possible to have my own exceptions sent to the global errorChannel? Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Is it possible to have my own exceptions sent to the global errorChannel?

    I have a couple application specific exceptions that I'd like to be able to send to the global errorChannel any time the exceptions are thrown. I've manually defined an errorChannel so that the exceptions are emailed to me when they occur. I can't seem to figure out how to achieve this. I have unit tests that will throw the exceptions I'm looking for, but I don't get an email.

    This is my errorChannel config.

    	<chain input-channel="errorChannel" output-channel="mailChannel">
    			<int-mail:subject value="${notification.subject}"/>
    			<int-mail:to value="${}"/>
    			<int-mail:from value="${notification.from}"/>
    	<channel id="mailChannel"/>
    	<int-mail:outbound-channel-adapter channel="mailChannel" host="${smtp.server}"/>

  • #2
    Sorry for short reply but I am typing it on the phone since I have all day poweoutage.
    Look at the ExceptionTypeRouter there is also a namespase support for it. I am sure it fits your case.
    I'll follow up with more details once back online


    • #3
      Hey Oleg,

      I'm reading the docs on implementing the exception-type-router. Now as far as I can tell, it still requires a message with an instance of Throwable as the payload. So does that mean, simply throwing an exception won't actually work? Would I have to implement the messaging logic within the exception type itself?



      • #4

        Just look at this configuration, hopefully it will clarify

        <int:gateway . . . . error-channel="myErrorChannel" . . ./>
        <int:channel id="myErrorChannel"/>
        <int:exception-type-router input-channel="myErrorChannel">
           <int:mapping exception-type="" channel="fooChannel"/>
           <int:mapping exception-type="" channel="barChannel"/>
        . . . .
        So let's say you are invoking a gateway method and somewhere downstream a component throws FooException. This exception will be re-thrown up the stack and back to the gateway. Since gateway defines an error-channel the exception will be converted to an ErrorMessage and sent to the specified error-channel (e.g., myErrorChannel). The 'myErrorChannel' is subscribed to by an exception-type-router which routes based on the exception.

        Does that explain?


        • #5
          Thanks Oleg,

          That explains it. In my config, I don't use a gateway anywhere, just chains where I define an input-channel, so SI creates the channels for me. Also there's nowhere to define an error-channel on those. So I'll start my config off with a gateway instead. Downstream I think I can stick with just defining the input-channel on my chains and not need a separate gateway for each.

          One thing I'm having trouble with is defining an <exception-type-router> element in my config. I'm using Spring Integration as the root namespace in this config file and the schema location is defined as "" but it doesn't seem to recognize <exception-type-router> as a valid element. Have you seen that before?


          • #6
            It might just be an STS goof. Every now and than someone reports something like that. But it should not be affecting you at runtime.


            • #7
              Ok, thanks.


              • #8
                Also, just realized. Since you are talking about global error channel (channel with the name 'errorChannel'), than you can just hook up ETR to it


                • #9
                  Ok, will try that.


                  • #10
                    Hey Oleg,

                    So turns out I didn't even need an <exception-type-router>. All I wanted to do was capture any exception I throw in my code and pass it off to the global errorChannel, which then sends an email with the exception. With a gateway properly defined, my code will attempt to login to a web service using a <ws:outbound-gateway>. I throw an exception if the response from the web service is a failed login. The content of the exception is whatever the web service returned as a fault.

                    Thanks for your help.


                    • #11
                      But aren't you glad you learned something new


                      • #12
                        Of course! ;-)