Announcement Announcement Module
Collapse
No announcement yet.
Transferring HTTP URL Variables Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Transferring HTTP URL Variables

    I am using Spring Integration to facilitate a simple REST GET over HTTP. Essentially, a client makes a GET request to SI with a single query parameter via an inbound gateway, and SI needs to make its own outbound GET request to an existing service passing the same parameter.

    Here is the my configuration:

    Code:
    <http:inbound-gateway id="documentByIdInboundGateway"
                              request-channel="documentByIdRequestChannel"
                              reply-channel="documentByIdReplyChannel"
                              name="/documents/{id}"
                              supported-methods="GET"/>
        <http:outbound-gateway id="documentByIdTargetAdapter"
                               url="http://localhost:8080/myapp/documents/{id}"
                               http-method="GET"
                               request-channel="documentByIdRequestChannel"
                               reply-channel="targetDocumentByIdReplyChannel"
                               expected-response-type="com.myapp.Document"
                               charset="UTF-8"
                               header-mapper="jsonHeaderMapper">
        </http:outbound-gateway>
    Things look good early on as you see here:
    Code:
    18:56:16,609 DEBUG [BeanNameUrlHandlerMapping.lookupHandler] Matching patterns for request [/documents/1232332] are [/documents/{id}]
    18:56:16,609 DEBUG [BeanNameUrlHandlerMapping.lookupHandler] URI Template variables for request [/documents/1232332] are {id=1232332}
    But then I get the following exception:

    Code:
    org.springframework.integration.MessageHandlingException: HTTP request execution failed for URI [http://localhost:8080/myapp/documents/{id}]
    	at org.springframework.integration.http.outbound.HttpRequestExecutingMessageHandler.handleRequestMessage(HttpRequestExecutingMessageHandler.java:243)
    	at org.springframework.integration.handler.AbstractReplyProducingMessageHandler.handleMessageInternal(AbstractReplyProducingMessageHandler.java:98)
    	at org.springframework.integration.handler.AbstractMessageHandler.handleMessage(AbstractMessageHandler.java:78)
    	at org.springframework.integration.dispatcher.UnicastingDispatcher.doDispatch(UnicastingDispatcher.java:110)
    .
    .
    .
    .
    I have tried to do some things with <http:uri-variable>, but that hasn't worked for me either.

    I would love to know how to extract the id parameter from the inbound request and tack it on to the outbound request. Any insight is appreciated.

    Thanks.

  • #2
    You should be able to do exactly that with a <uri-variable> sub-element. There you can provide any SpEL expression that can be evaluated against the request Message. Where is the value that you want to replace {id} (payload, header, ...?)

    Comment


    • #3
      Sorry - I see what you're doing on the inbound side, so forget that last question. The inbound request URL should be available in a header whose key is defined by HttpHeaders.REQUEST_URL. So, you could create a SpEL expression that evaluates against that in the outbound adapter's 'uri-variable' sub-element. Does that help?

      Comment


      • #4
        Thanks for the hint, Mark. I got it working with some String manipulation fun:

        Code:
        <int-http:uri-variable name="id" expression="headers[http_requestUrl].substring(headers[http_requestUrl].lastIndexOf('/') + 1)"/>
        Still, given that the right parsing is done on the inbound call as indicated here:

        Code:
        17:08:51,015 DEBUG [BeanNameUrlHandlerMapping.lookupHandler] URI Template variables for request [/documents/1232332] are {id=1232332}
        ...it might be nice to have those variables accessible for a subsequent call rather that have to resort to clunky string manipulation.

        Just a thought.

        Thanks.

        Comment


        • #5
          I agree that this would be a nice feature. Can you open a feature request in JIRA?

          Comment


          • #6
            Done: https://jira.springsource.org/browse/INT-1677

            Thanks.

            Comment

            Working...
            X