Kris Swat
Kris Swat

Reputation: 1006

Spring Integration gateway with multiple parameters to construct url

In current model, we have a REST endpoint, which gets requestbody, based on which a jms text message is created and sent to JMS queue,

TextMessage outMessage = session.createTextMessage(messagePayloadText);
           ..          
outMessage.setStringProperty("clientType", clientType);
outMessage.setStringProperty("DYNAMIC", dynaHeader);

In above code DYNAMIC is required to help me in creating our url

<int:chain input-channel="gCStatusInChannel" output-channel="headerFilterChannel">
    <int:header-enricher>           
        <int:header name="Api-Key" value="B8872853E8B"></int:header>
        <int:header name="Accept" value="application/json" /> 
        <int:header name="Content-Type" value="application/json" />         
    </int:header-enricher>      
    <int-http:outbound-gateway  
           url="https://i-zaie.sr13.tst.bst/ia-zaaie/rest/search/v2/cReference/{cref}"
           http-method="PUT"               
           header-mapper="headerMapper" 
           expected-response-type="java.lang.String"
           encode-uri="false"
           request-factory="sslFactory">               
     <int-http:uri-variable name="cref" expression="headers['DYNAMIC']" />                 
    </int-http:outbound-gateway>
    <int:object-to-string-transformer></int:object-to-string-transformer>
</int:chain>

Everything works in this model. Now I want to use gateway instead of JMS

New code:

<int:gateway id="gService"
    service-interface="n.d.lr.eai.gw.GGateway"
    default-reply-channel="dest-channel"
    default-request-timeout="5000" default-reply-timeout="5000">
    <int:method name="vCreateSignal" request-channel="vCreateSignalInChannel"/> ...

Question: can i have method in gateway as below?

public String vCreateSignal(String caseDat, String dynamic);

what should I do to enable

<int:chain input-channel="gCStatusInChannel"...
..>

to get headers['DYNAMIC'] value and continue.

Upvotes: 0

Views: 557

Answers (1)

Artem Bilan
Artem Bilan

Reputation: 121272

Yes, you can do that. What you just need is to add a @Header("DYNAMIC") into that dynamic parameter:

public String vCreateSignal(String caseDat, @Header("DYNAMIC") String dynamic);

And when you call this gateway's method you just specify an argument and it will be mapped to an appropriate header and that all: https://docs.spring.io/spring-integration/docs/current/reference/html/messaging-endpoints-chapter.html#gateway-mapping

Upvotes: 1

Related Questions