2015-10-06 164 views
0

我試圖通過Spring集成調用REST Web服務,即Spring集成將充當我的客戶端到REST Web服務。但是,我應該將參數添加到ws url並添加json對象作爲參數。 爲此,我嘗試了以下配置:春季集成:如何用http出站網關發佈請求參數

<int:enricher input-channel="inputChannel" request-channel="quakeinfotrigger.channel"> 
    <int:property name="info" expression="payload"/> 
</int:enricher> 

<int-http:outbound-gateway id="quakerHttpGateway" 
    request-channel="quakeinfotrigger.channel" 
    url="http://ffff.ff/gg/rest/put/{tel_number}" 
    http-method="PUT" 
    expected-response-type="java.lang.String" 
    charset="UTF-8" 
    reply-timeout="5000" 
    reply-channel="quakeinfo.channel"> 
    <int-http:uri-variable name="tel_number" expression="payload.getNumTelefono()"/> 
</int-http:outbound-gateway> 

tel_number不作爲PARAM過去了,能否請您給我一個解決方案來傳遞PARAM通過URL字符串和JSON對象。

回答

1

你是什麼意思「tel_number不作爲參數傳遞」?

我只是修改了http sample這樣的:

<int:gateway id="requestGateway" 
      service-interface="org.springframework.integration.samples.http.RequestGateway" 
      default-request-channel="requestChannel"> 
    <int:default-header name="content-type" value="application/json" /> 
</int:gateway> 

<int:channel id="requestChannel"/> 

<int-http:outbound-gateway request-channel="requestChannel" 
          url="http://localhost:8080/http/receiveGateway/{tel_num}" 
          http-method="POST" 
          expected-response-type="java.lang.String"> 
    <int-http:uri-variable name="tel_num" expression="'foo'" /> 
</int-http:outbound-gateway> 

和它的工作如預期 - 服務器端,我看到

No mapping found for HTTP request with URI [/http/receiveGateway/foo] 

目前還不清楚你問什麼JSON;如果您在有效負載中發送POJO並將content-type頭設置爲'application/json'(使用header-richher)並將Jackson Jars放在類路徑中,它將會正常工作。

+0

如何傳遞{tel_num}?這是一個動態變量。我應該以編程方式通過它。端點不是網關,而是入站通道適配器 – NAZEHA

+0

啓動流程的內容並不重要;正如我在asnwer中所說的,你可以使用''來設置'content-type'頭。你的表情應該工作(如果它是有效的),我只是用了一個文字表達式。我需要知道你的意思是「沒有通過」。 –

+0

它確實意味着:如何填充URI變量{tel_number},我將它發送到頭部? – NAZEHA

相關問題