JBoss 使用 camel-netty4-http 融合 camel dsl - 我如何获取 REST return 代码以记录它?

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

问题:

我正在使用 JBoss Fuse 和 camel-netty4-http 到 post 到 REST 服务。
- 我将如何获得 REST return 代码 - 又名 "status 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!!!    
}           

您的响应代码应该在您的 Exchange header 中。您可以使用一个简单的表达式来提取它。像这样:

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