QUESTION:
I'm using JBoss Fuse and camel-netty4-http to post to a REST service.
-How would I obtain the REST return code - aka, "status code" - (in order to log it)?
sample code:
@Override
public void configure() throws Exception {
...
from("wmq:queue:mylocalqueue")
.log("inMessage=" + (null==body()?"":body().toString()))
.to("seda:node1?concurrentConsumers=20");
from("seda:node1")
.streamCaching()
.threads(20)
.setHeader(Exchange.HTTP_METHOD, constant(org.apache.camel.component.http4.HttpMethods.POST))
.setHeader(Exchange.CONTENT_TYPE, constant("application/json"))
.toD("netty4-http:http://localhost:7001/MyService/myServiceThing?textline\\=true")
.log("the http return/status code is [what?]..."; <=== need response/http code!!!
}
Your response code should be in your Exchange
header. You could use a simple expression to extract it. Like this:
from("direct:start")
.setHeader(Exchange.HTTP_METHOD, constant(HttpMethods.POST))
.setHeader(Exchange.CONTENT_TYPE, constant("application/json"))
.to("netty4-http:http://localhost:8080")
.log("The response code is: ${header["+Exchange.HTTP_RESPONSE_CODE+"]}");