这是我的路线:
<route>
<from uri="timer:timerName?period=2000"/>
<to uri="ahc:http://www.google.com/search?q=Camel"/>
<log message="${property.CamelHttpResponseCode}"/>
</route>
我想获得响应代码状态,但我收到此错误
Exchange[Message: [Body is null]]
我该如何解决这个问题?
答案 0 :(得分:0)
我想阅读&#34;获取响应代码&#34; documentation中的段落会有所帮助:
Exchange exchange = template.send("ahc:http://www.google.com/search", new Processor() {
public void process(Exchange exchange) throws Exception {
exchange.getIn().setHeader(Exchange.HTTP_QUERY, constant("hl=en&q=activemq"));
}
});
Message out = exchange.getOut();
int responseCode = out.getHeader(Exchange.HTTP_RESPONSE_CODE, Integer.class);
答案 1 :(得分:0)
对于这个简单的情况,你可以使用camel-jetty。否则,还有其他组件,如Camel-Restlet,用于调用和公开HTTP服务。 http://camel.apache.org/jetty.html
<route>
<from uri="direct:start"/>
<to uri="http://www.google.com/search?q=Camel"/>
<route>
编辑:
出于测试目的,您可以这样做:
<route>
<from uri="jetty://localhost:5050/test"/>
<to uri="jetty://http://www.google.com?q=Camel"/>
<route>
然后在chrome或fiddler中使用postman等工具并调用localhost服务。