Uploaded image for project: 'Spring Integration'
  1. Spring Integration
  2. INT-4169

Support for appending arbitrary query string parameters to outgoing requests in HTTP outbound gateway/adapter




      I need to invoke a REST service which is mapped on the remote side with Spring Web MVC to a method with a given number of parameters (an Integer, a String and a String[]).

      If this service is mapped against POST method, I can configure my <int-http:outbound-gateway> and send to it a message payload of type MultiValueMap so that it sends out my parameters with content type application/x-www-form-urlencoded or multipart/form-data (depending on the actual content). So far so good.

      But if this service is mapped against GET method, it's much harder to invoke it with Spring Integration. I would need to add all the URI variables to the URI and then use, for instance, the uri-variables-expression to get a Map of those variables values. However, unless URI variables are few and known in advance, this approach is not flexible. In my specific case, I think it's even useless, because to send a multi-value parameter I would need to repeat the query-string parameter in the URL n times, being n not known in advance.

      I mean, if I need to call:


      but I don't know how many values are in paramList, I can't write a proper URI template in my <int-http:outbound-gateway> definition and I hardly think that a Map containing an Iterable value for paramList parameter will be "expanded" to such an actual URL (honestly, I haven't tried).

      I think an elegant solution to this problem could be an attribute like append-query-string-parameters-expression which must evaluate to a MultiValueMap (or just Map for simple scenarios) containing all the key-value pairs (or key-multiple value pairs) to be dynamically appended to the URL before invocation. something like:

        id="myHttpGateway" request-channel="inputChannel"
        reply-channel="outputChannel" url="http://www.example.com/getSomething"
        http-method="GET" charset="UTF-8" append-query-string-parameters-expression="payload"
        expected-response-type="com.example.MyResponseBean" />

      In this example, if payload is a MultiValueMap, it will be used to compute all the query string parameters to be appended to the URL to make the actual service invocation.

      I know that passing parameters through arbitrary query string parameters may be risky (because you may have lose control con the final length of the URL), but if this is in some way controlled, I find it a reasonable alternative to a POST + application/x-www-form-urlencoded content type. After all, this is what a browser does when posting a FORM with GET method.




            abilan Artem Bilan
            mauromol Mauro Molinari
            0 Vote for this issue
            2 Start watching this issue