0

I hava xml that include this :

<channel id="myDataChannel"></channel>
<http:outbound-gateway 
    request-channel="myDataChannel"
    url="{url}/myApi/getData/{id}"
    expected-response-type="com.api.dto.Data"
    http-method="GET" 
    rest-template="myRestTemplate">
    <http:uri-variable name="url" expression="headers.url" />
</http:outbound-gateway>

and in java code like this :

    MessagingTemplate myTemplate = new MessagingTemplate();
    Message<?> getDataReply = null;
    Data dataDto = null;

    Message<?> requestMsg = MessageBuilder.withPayload(requestDto)
            .build();

    getDataReply = template.sendAndReceive(myDataChannel, requestMsg);
    return dataDto = (Data) getDataReply.getPayload();

here is my question how to path id in URL with payload in java code and there is an additional tag should I add to XML in out-bound-gateway ?

Stu Dev
  • 13
  • 1
  • 7

1 Answers1

0

Your question is not clear but you need something like

Message<?> requestMsg = MessageBuilder.withPayload(requestDto)
        .setHeader("url", ...)
        .setHeader("id", ...)
        .build();

and

<http:uri-variable name="id" expression="headers.id" />

Or, if the id is a property of the payload

Message<?> requestMsg = MessageBuilder.withPayload(requestDto)
        .setHeader("url", ...)
        .build();

and

<http:uri-variable name="id" expression="payload.id" />
Gary Russell
  • 166,535
  • 14
  • 146
  • 179
  • i mean when i call api for example I have id from request and want send its value like this URL : **HTTP//localhost:8080/myApi/getData/2** if I apply your solution will it create it like URL in my comment ? – Stu Dev Jun 02 '20 at 13:41
  • Yes it will you just have to tell the adapter where to find the `id`. – Gary Russell Jun 02 '20 at 13:47