带有recipientList的动态HTTP URI在第二次调用时返回404

时间:2016-09-07 16:02:34

标签: apache-camel

我有两步驼峰路线工作流程 - 两个步骤都对同一主机进行POST调用,但URL和正文不同。第一个调用返回第二个调用的URL的一部分。

以下是代码:

// I register converter for different request types
getContext().getTypeConverterRegistry().addTypeConverters(new RequestConverter());

from("direct:two-step-flow")
  .setHeader("paramId", body().method("getParamId")
  .setHeader("url", "http://localhost:8080/api/${header.paramId}
  .convertBodyTo(Step1Request.class)
  .to("direct:call-remote-service")
  .convertBodyTo(Step2Request.class) // converter sets newParamFromResponse
  .setHeader("url", "http://localhost:8080/api/${header.paramId}/${body.newParamFromResponse}
  .to("direct:call-remote-service")
.end();

from("direct:call-remote-service")
  .marshal().json(JsonLibrary.Jackson)
  .recipientList(header("url"))
  .unmarshal().json(JsonLibrary.Jackson, GenericResponse.class)
.end();

第一步工作正常,HTTP流程就像

httpclient.wire.header - >> "POST /api/p1 HTTP/1.1[\r][\n]" 
httpclient.wire.content - >> "{"amount":1.22,"reason":"some reason","relation-id":"12345"}"
httpclient.wire.header - << "HTTP/1.1 200 OK[\r][\n]"
httpclient.wire.header - << "HTTP/1.1 200 OK[\r][\n]"
httpclient.wire.header - << "Content-Type: application/json[\r][\n]"
httpclient.wire.header - << "Transfer-Encoding: chunked[\r][\n]"
httpclient.wire.header - << "Server: Jetty(9.3.11.v20160721)[\r][\n]"
httpclient.wire.header - << "[\r][\n]"
org.apache.camel.component.http.HttpProducer - Http responseCode: 200

第二步失败,HTTP 404

httpclient.wire.header - >> "POST /api/p1/Id1 HTTP/1.1[\r][\n]"
httpclient.wire.content - >> "{"action":"CONFIRM","reason":"reason to confirm","relation-id":"12345"}"

org.apache.camel.component.http.HttpProducer - Http responseCode: 404
httpclient.wire.content - << "<html>[\n]"
httpclient.wire.content - << "<head>[\n]"
httpclient.wire.content - << "<meta http-equiv="Content-Type"
content="text/html;charset=ISO-8859-1"/>[\n]"
httpclient.wire.content - << "<title>Error 404 </title>[\n]"
httpclient.wire.content - << "</head>[\n]"
httpclient.wire.content - << "<body>[\n]"
httpclient.wire.content - << "<h2>HTTP ERROR: 404</h2>[\n]"
httpclient.wire.content - << "<p>Problem accessing /api/p1/Id1. Reason:[\n]"
httpclient.wire.content - << "<pre>    Not Found</pre></p>[\n]"
httpclient.wire.content - << "<hr /><a href="http://eclipse.org   /jetty">Powered by Jetty:// 9.3.11.v20160721</a><hr/>[\n]"
httpclient.wire.content - << "</body>[\n]"
httpclient.wire.content - << "</html>[\n]"

相同的POST适用于curl:

curl 'http://localhost:8080/api/p1/Id1' -i -X POST -H
'Accept:application/json' -H 'Content-Type: application/json' -d
'{                                 
    "action" : "CONFIRM",
    "relation-id" : "12345",
    "reason" : "reason to confirm"
 }'
 HTTP/1.1 200 OK
 Content-Type: application/json
 Transfer-Encoding: chunked
 Server: Jetty(9.3.11.v20160721)

我可能会误用.recipentList,感谢任何帮助。

由于

1 个答案:

答案 0 :(得分:0)

可能它的某些HTTP响应标头被拾取并用于第二次调用。因此,请尝试删除2个调用之间的HTTP标头:http://camel.apache.org/how-to-remove-the-http-protocol-headers-in-the-camel-message.html

添加

.removeHeaders("CamelHttp*")

在使用收件人列表调用路线之前

.to("direct:call-remote-service")