【发布时间】:2019-02-19 07:27:04
【问题描述】:
我需要使用查询字符串对 REST WS 进行 GET 调用,uri 必须是这样的:
http://somehost.com/someservice?parm1=value
我需要分配body的参数“parm1”的值(一个普通的带有getter和setter的pojo),所以这是骆驼路线:
<setHeader headerName = "Exchange.HTTP_QUERY" id = "queryStringSomeService">
<simple>parm1=${body.someField}</simple>
</setHeader>
<setHeader headerName = "CamelHttpMethod" id = "httpMethodSomeService">
<constant>GET</constant>
</setHeader>
<to id="SOME_SERVICE" uri="http4:/somehost.com/someservice?bridgeEndpoint=true" />
问题是查询字符串从未添加到uri,http方法最终使用了它的POST,虽然我添加了header来显式设置GET。
我使用的是 Spring DSL。
在文档的页面http://camel.apache.org/http4.html中,建立了选择HTTP方法的规则;在“使用 GET 或 POST 调用”部分中,但显然它们没有在这种情况下应用。
更新:
将正文设置为 null 解决了将 HTTP 方法更改为 GET 的问题,尽管在文档中说您使用 CamelHttpMethod 标头覆盖它。
但是对于查询字符串,我已经尝试了所有变体;使用 Exchange.HTTP_URI 和 Exchange.HTTP_QUERY,都没有工作
这是 WS 调用之前的交换标头:
Accept: application/json
CamelHttpCharacterEncoding: ISO-8859-1
CamelHttpMethod: GET
CamelHttpQuery: ?parm1=value
CamelHttpResponseCode: 200
CamelHttpResponseText: OK
CamelHttpUri: /someservice
CamelHttpUrl: http://somehost/someservice
CamelRedelivered: false
CamelRedeliveryCounter: 0
Connection: close
Content-Type: application/json;charset=UTF-8
Date: Fri, 14 Sep 2018 16:08:19 GMT
Last-Modified: Thu, 13 Sep 2018 13:33:30 GMT
Set-Cookie: JSESSIONID=YXQkEAUAjh0yWsu4UYwSG8vE.5aa71417-9e93-3be1-99ca-7b4ec1d6f2a0; Path=/ca_tar_tarjeta
Transfer-Encoding: chunked
breadcrumbId: ID-wildfly01-1536931422750-9-23
【问题讨论】:
-
我不确定
<a .../>在 Camel 中应该是什么,但我猜你的意思可能是<to .../>。对于动态 URI,Camel 提供 recipientList 或 toD。如HTTP4 component description 中所述,您可以设置.setHeader(Exchange.HTTP_URI, constant(...))以覆盖.to(...)中的实际URI,在这种情况下.to(...)定义仅用于确定要使用的组件。请注意,这不适用于桥 -
我尝试了您的示例并在日志中有“org.apache.http.client.CircularRedirectException: Circular redirect to 'somehost.com/someservice?parm1=value'”。似乎查询已添加到 url。
标签: java apache-camel