Results 1 to 4 of 4

Thread: Handling Errors Represented as JSON

Hybrid View

  1. #1
    Join Date
    Aug 2007
    Posts
    138

    Default Handling Errors Represented as JSON

    I am using Spring Integration as an abstraction to a target REST service that returns JSON in all cases--a "document" object when things go well and an "error" object when things go awry. The tricky thing implied here is that the response is always HTTP 200; the only difference is the JSON returned.

    Here is the configuration of the outbound call:

    Code:
    <http:outbound-gateway                 
                               id ="documentByIdAdapter"
                               url="http://localhost:8080/myapp/documents/{id}"
                               http-method="GET"
                               request-channel="documentByIdRequestChannel"
                               reply-channel="myappDocumentByIdReplyChannel"
                               expected-response-type="com.myapp.Document"
                               charset="UTF-8"/>
    Since the JSON could either be a document or an error, I believe I need to get rid of expected-response-type. The problem is that when I do that, SI considers the payload to be just the status rather than the JSON that comes back. As a result, the following doesn't work for me:

    Code:
    <payload-type-router input-channel="routingChannel">
            <mapping type="com.myapp.Document" channel="documentResponseChannel"/>
            <mapping type="com.myapp.ErrorResponse" channel="errorResponseChannel"/>
        </payload-type-router>
    ...because SI just sees the payload as an HttpStatus object.

    Is it possible to do what I am trying to do? If so, how?

    Thanks.

  2. #2
    Join Date
    Jan 2008
    Location
    Mohnton, PA USA (that's near Philadelphia)
    Posts
    2,148

    Default

    Just to clarify, are you registering custom HttpMessageConverters to get com.myapp.Document?

  3. #3
    Join Date
    Aug 2007
    Posts
    138

    Default

    No...only because SI seems to know magically to apply the MappingJacksonHttpMessageConverter, which is precisely what I want.

    So I guess the answer is that it is applied implicitly.

    Thanks.

  4. #4
    Join Date
    Jan 2008
    Location
    Mohnton, PA USA (that's near Philadelphia)
    Posts
    2,148

    Default

    Ok

    Can you try to set expected-response-type to String and then add transformer downstream

Posting Permissions

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