Results 1 to 10 of 10

Thread: Why no error-channel attribute for int-http:outbound-gateway?

  1. #1
    Join Date
    May 2008
    Posts
    16

    Default Why no error-channel attribute for int-http:outbound-gateway?

    My int-http:outbound-gateway calls out to a server that may return an error message with a HTTP 500 status code.

    If that's the case I want to do a small amount of error handling only, I don't want the message to go onto the reply-channel.

    I set the error-handler and it detects and processes this scenario, but for some reason the message still gets placed on the reply-channel.

    So, I'm wondering if there's a reason why there isn't support for a error-channel, or if there's some way of stopping certain (e.g. 500) messages going to the reply-channel?

    Thanks

  2. #2
    Join Date
    Mar 2010
    Location
    Gtr Philadelphia, PA
    Posts
    2,022

    Default

    The error-channel goes on the inbound endpoint; when a downstream component throws an exception, an ErrorMessage is sent to that error channel. The ErrorMessage payload has two properties cause (the exception) and failedMessage.

    You then handle the error on that channel.
    Gary P. Russell
    Spring Integration Team
    SpringSource, a division of VMware

  3. #3
    Join Date
    May 2008
    Posts
    16

    Default

    Thanks, I put the error-channel on the inbound endpoint and now pick up the ErrorMessage in a transformer on the error channel.

    When the external server returns a HTTP 500 message, some additional information about the failure is passed in a HTTP header field. I had hoped to pick up this header in my transformer, but it doesn't look like HTTP headers are mapped on to ErrorMessage. Is there any way to retrieve the HTTP headers from ErrorMessage / error channel?

  4. #4
    Join Date
    Oct 2005
    Location
    Boston, MA
    Posts
    2,840

    Default

    You can access the original Message via the ErrorMessage payload's "failedMessage" property.

  5. #5
    Join Date
    May 2008
    Posts
    16

    Default

    Thanks, but it's not the original message headers that I want.

    The original message is passed to an outbound http gateway. The gateway makes a HTTP request and gets a 500 response. It is the HTTP headers of this 500 response that I'd like to be able to access from the ErrorMessage.

  6. #6
    Join Date
    Oct 2005
    Location
    Boston, MA
    Posts
    2,840

    Default

    Have you considered adding a router after the HTTP outbound gateway instead? You could route based on the status code in the reply Message's header.

  7. #7
    Join Date
    May 2008
    Posts
    16

    Default

    I'd be happy to do that, but from what I've seen the 500 response causes a MessageHandlingException inside the gateway which results in an ErrorMessage that would bypass the router? Or should I also override the error-handler so a 500 response isn't treated as an error?

  8. #8
    Join Date
    Oct 2005
    Location
    Boston, MA
    Posts
    2,840

    Default

    Right, the DefaultResponseErrorHandler on the underlying RestTemplate will automatically throw an Exception for any error status. So, yes, you could provide one that subclasses the default and bypasses that logic for certain status codes. Then that HTTP response would be sent downstream (via the gateway's "reply-channel") as if it were a "normal" reply Message.

  9. #9
    Join Date
    May 2008
    Posts
    16

    Default

    Ah, I've run into a problem with that method: although i now get the http header ok, i also need the contents of the original message (previously, using ErrorMessage, I could retrieve these using getFailedMessage). Is there any way of retrieving the original message contents given the reply message?

  10. #10
    Join Date
    Oct 2005
    Location
    Boston, MA
    Posts
    2,840

    Default

    Well, you could add a header-enricher upstream from the gateway that stores the original payload (or relative part(s) of it that you need in the error flow case) in a header. However, at the risk of going back and forth again, if you do use the error-channel approach, the actual Exception thrown by the DefaultResponseErrorHandler on RestTemplate is an instance of HttpServerErrorException, and that does have a getStatusCode() method. You could even route on that using an expression to evaluate against the ErrorMessage payload like this: "payload.cause.statusCode".

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •