Spring XD http-client处理器发送text/plain而不是application/json



我正在尝试创建一个流,发送POST请求作为流的一部分。

stream create form-time --definition "<working source> | generate-form-transformer: transform --script=form-generation.groovy  --outputType=application/json | http-client --inputType=application/json ..." --deploy

它可以工作,但它将contentType设置为text/plain而不是application/json,这会引发400,因为我的服务器不支持。(内容是完美的JSON)。

转换器返回一个XD元组,因此据我所知,从元组到JSON的转换应该正确完成(事实上,正如前面指出的,有效负载是正确的)。

然而,当涉及到http-client时,它不会修复contentTypetext/plain;UTF-8而不是application/json

有什么建议吗?我错过什么了吗?谢谢你。

我不相信--inputType--outputType转换应该设置标题,他们只是执行转换;一种技术是在http-client

中添加标题富集器。
$ git diff
diff --git a/modules/processor/http-client/config/http-client.xml b/modules/processor/http-client/config/http-client.xml
index cf7d2e2..c2ecd00 100644
--- a/modules/processor/http-client/config/http-client.xml
+++ b/modules/processor/http-client/config/http-client.xml
@@ -10,7 +10,7 @@
                        http://www.springframework.org/schema/integration/http/spring-integration-http.xsd">
        <int-http:outbound-gateway id='http-client'
-               request-channel='input' url-expression="${url}" http-method="${httpMethod}"
+               request-channel='inputX' url-expression="${url}" http-method="${httpMethod}"
                expected-response-type='java.lang.String' charset='${charset}'
                reply-timeout='${replyTimeout}' reply-channel='output'
                mapped-request-headers="${mappedRequestHeaders}"
@@ -19,5 +19,9 @@
        <channel id="output" />
        <channel id="input" />
+       <channel id="inputX" />
+       <header-enricher input-channel="input" output-channel="inputX">
+               <header name="content-type" value="application/json" />
+       </header-enricher>

现在spring-xd-modules中有一个header- enrichment处理器模块

stream create form-time -definition " | generate-form-transformer: transform——script=form-generation。groovy——outputType=application/json | http-client——inputType=application/json…"——部署

您是否为http-client模块设置了--outputType=application/json ?此外,http-client中的--inputType是不必要的,因为前一个模块的输出类型已经是applicationjson。可能,您打算将其设置为--outputType ?

最新更新