我正在尝试创建一个流,发送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时,它不会修复contentType是text/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
?