Announcement Announcement Module
Collapse
No announcement yet.
Handling Errors Represented as JSON Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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
    Just to clarify, are you registering custom HttpMessageConverters to get com.myapp.Document?

    Comment


    • #3
      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.

      Comment


      • #4
        Ok

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

        Comment

        Working...
        X