0

I am calling int-http:outbound-gateway for external service call which looks like this, http://workflow-test-svc-stg.com/workflow?testId=1234&userId=ABC

But I don't have int-http:inbound-gateway to set request param as

<int-http:header name="testId" expression="#requestParams[testId]"/>
<int-http:header name="userId" expression="#requestParams[userId]"/>

I am using request channel send method to send url(http://workflow-test-svc-stg.com/workflow) and headers(testId and userId) to call above external service but I am not sure how to tell outbound gateway that testId and userId need to be request params.

I tried using

<int:gateway id="requestGateway"
                 default-request-channel="request.channel">
        <int:default-header name="testId" expression="headers.testId" />
        <int:default-header name="userId" expression="headers.userId" />
</int:gateway>

<int-http:outbound-gateway id="driverWorkloadGateway"
                                   request-channel="request.channel"
                                   url-expression="headers.bstUrl"
                                   http-method="GET"
                                   expected-response-type="java.lang.String"
                                   charset="UTF-8"
                                   request-factory="httpComponentClientRequestFactory"
                                   mapped-request-headers="*" >
            <int-http:uri-variable name="testId" expression="#requestParams[testId]"/>
            <int-http:uri-variable name="userId" expression="#requestParams[userId]"/>
</int-http:outbound-gateway>

can you please help?

1 Answers1

0

We have that explained in the docs: https://docs.spring.io/spring-integration/docs/current/reference/html/http.html#mapping-uri-variables

If your URL contains URI variables, you can map them by using the uri-variable element.

And the sample demonstrates how that supposed to be:

<int-http:outbound-gateway id="trafficGateway"
    url="https://local.yahooapis.com/trafficData?appid=YdnDemo&amp;zip={zipCode}"
    request-channel="trafficChannel"
    http-method="GET"
    expected-response-type="java.lang.String">
    <int-http:uri-variable name="zipCode" expression="payload.getZip()"/>
</int-http:outbound-gateway>

Pay attention to that {zipCode} placeholder.

So, for your use-case that headers.bstUrl must have those testId and userId placeholders. You also need to change a #requestParams SpEL variable to the headers property reference.

That <int:default-header name="testId" expression="headers.testId" /> definition also looks suspicious. Why would one overrides the header with its own value?

Artem Bilan
  • 113,505
  • 11
  • 91
  • 118