以下代码段运行良好:
public class HttpQueryTest
{
public static void main( String[] args ) throws Exception {
CamelContext camelContext = new DefaultCamelContext();
camelContext.addRoutes(new RouteBuilder() {
@Override
public void configure() throws Exception {
from("direct:start")
.setHeader(Exchange.HTTP_URI, simple("http://google.com?q=Name~ABC"))
.to("http://localhost/noSuchUrl").to("log:OUT");
}
});
camelContext.start();
camelContext.createProducerTemplate().sendBody("direct:start","start");
TimeUnit.SECONDS.sleep(5);
}
}
正如我在日志中看到的:
12:59:11.230 [main] DEBUG o.a.c.component.http.HttpProducer - Executing http GET method: http://google.com?q=Name~ABC
12:59:11.650 [main] DEBUG o.a.c.component.http.HttpProducer - Http responseCode: 200
如您所见,它使用 Exchange.HTTP_URI 标头值设置目标 URL。然后它使用与您的参数相似的参数创建 Google 查询。
您能否提供演示您的问题的片段,以便我可以重现它?