-
Nov 15th, 2011, 09:46 PM
#1
Exception handling in http outbound gateway
Hi
How can I handle exceptions in an http outbound gateway? If I send a request to another party and I receive an exception because the connection is reset for example how can I get access to the original request message? In my example I send on an id and if the other party is not responding I need to deal with it, so I need the context of the request, the error-handler attribute does not offer that, except I am missing something.
Thanks
Tarik
-
Nov 16th, 2011, 06:23 AM
#2
Spring Integration provides support for defining an error-channel on any component that is considered an entry point to a Messaging System. For example: <int:gateway error-channel.../> <int-http:inbound-gateway error-channel.../> <int
oller error-channel.../>
Outbound gateways are no different than any other MessageHandler, and as such the exception will be propagated back to the beginning of the Message flow where most likely you do have some type of an inbound gateway. Just as a background, we do not believe that MessageHandler should define their own error-handling logic or facilities aside from those available within java code (e.g., try/catch). This makes error-handling very sporadic since it would than exist in many different levels.
Now, one of the most common concerns is that you may not want the error to be propagated all the way to the beginning of the flow especially if such flow is rather long.To accomplish that we've introduce this hybrid pattern that we call service-activator/gateway which allows you to introduce check-points (segments) within the flow. So for you case is service-activator/gateway is the one that initiates a call to HTTP Outbound Gateway any error resulting from such gateway invocation will be cought and dealt with by the most close service-activator/gateway. We also call it flow segmentation.
Anyway, recently at SpringOne i've presented many different advanced Spring Integration samples which are available here: https://github.com/olegz/s12gx.2011
You can look through all of them but the one that describes what I just said is here: https://github.com/olegz/s12gx.2011/...n/segmentation
-
Nov 18th, 2011, 01:19 AM
#3
Hello Oleg
Thanks for this but I am not getting how I could make use of segmentation in my case. I thougt about using a service activator as well but it seems not to be working for me, the exception is not caught at the service activator:
My setup is like this:
int-jms:inbound-gateway-->int:service-activator(1)-->int:header-enricher-->int:router-->int:service-activator(2)-->int:filter-->int:header-enricher-->int:router-->int-http:outbound-gateway
So actually between the last route and the http outbound gateway I need to have a service-activator that updates a db record in case of a failure in the outbound-gateway, the example you gave I cannot make sense of how I would then be able to catch and deal with the exception.
I changed it to this:
int-jms:inbound-gateway-->int:service-activator(1)-->int:header-enricher-->int:router-->int:service-activator(new ref int:gateway(new))-->int:gateway(new)-->int:service-activator(2)-->int:filter-->int:header-enricher-->int:router-->int-http:outbound-gateway
After changing I still cannot handle the exception in service-activator(2). Trying to have service-activator(2) before the gateway(new).
Finally tried:
int-jms:inbound-gateway-->int:service-activator(1)-->int:header-enricher-->int:router-->int:service-activator(2)-->int:service-activator(new ref int:gateway(new))-->int:gateway(new)-->int:filter-->int:header-enricher-->int:router-->int-http:outbound-gateway
No success though.
Thank you for your input.
Last edited by TarikS; Nov 18th, 2011 at 02:37 AM.
-
Nov 18th, 2011, 03:37 AM
#4
Hello Oleg
I got it now, instead of catching it in the service-activator I handle the error by the error-channel of the segment gateway and by having access to the failedMessage of the request to the outbound gateway.
Thank you very much for this and for your efforts in general, we built a quite big system for realtime services hooking up to all kind of other systems with all kinds of adapters, I think spring integration gave us a big leverage for this.
Thanks a lot!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules