apache camel - Dynamic HTTP URI with recipientList returns 404 on the second call -


i have 2 step camel route workflow - both steps make post call same host, url , body different. first call returns part of url second call.

here code:

// register converter 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(); 

first step works fine, http flow

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 

second step fails http 404

httpclient.wire.header - >> "post /api/p1/id1 http/1.1[\r][\n]" httpclient.wire.content - >> "{"action":"confirm","reason":"reason 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 jetty:// 9.3.11.v20160721</a><hr/>[\n]" httpclient.wire.content - << "</body>[\n]" httpclient.wire.content - << "</html>[\n]" 

the same post works 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 confirm"  }'  http/1.1 200 ok  content-type: application/json  transfer-encoding: chunked  server: jetty(9.3.11.v20160721) 

i might misusing .recipentlist, appreciated.

thanks

maybe http response headers picked , used 2nd call. therefore try removing http headers between 2 calls: http://camel.apache.org/how-to-remove-the-http-protocol-headers-in-the-camel-message.html

add

.removeheaders("camelhttp*") 

before call route recipient list

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

Comments

Popular posts from this blog

java - Jasper subreport showing only one entry from the JSON data source when embedded in the Title band -

mapreduce - Resource manager does not transit to active state from standby -

serialization - Convert Any type in scala to Array[Byte] and back -