简体   繁体   中英

JBoss Fuse camel dsl using camel-netty4-http - how to I obtain the REST return code in order to log it?

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+"]}");

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM