Spring集成:如何使用http出站网关发布请求参数

时间:2015-10-06 15:39:10

标签: spring-integration

我试图通过Spring Integration调用REST Web服务,即Spring Integration将充当REST Web服务的客户端。但是,我应该将params添加到ws url并添加json对象作为参数。 为此,我尝试了以下配置:

<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不是作为参数传递的,你可以给我一个解决方案,通过url和json对象传递param作为字符串。

1 个答案:

答案 0 :(得分:1)

你是什么意思&#34; tel_number不作为参数传递#34; ?

我刚刚修改了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标头设置为&#39; application / json&#39; (使用标题扩充器)并将杰克逊罐子放在类路径上,它会起作用。

相关问题