22.12. 配置 URI 以调用
您可以直接设置 HTTP producer 的 URI 来直接组成端点 URI。在以下路由中,Camel 会使用 HTTP 调用到外部服务器 oldhost。
from("direct:start")
.to("http://oldhost");
等同于 Spring 示例:
<camelContext xmlns="http://activemq.apache.org/camel/schema/spring">
<route>
<from uri="direct:start"/>
<to uri="http://oldhost"/>
</route>
</camelContext>
您可以通过在消息中添加使用密钥 Exchange.HTTP_URI 的标头来覆盖 HTTP 端点 URI。
from("direct:start")
.setHeader(Exchange.HTTP_URI, constant("http://newhost"))
.to("http://oldhost");
在上例中,尽管端点配置了 http://newhost/,但 Camel 将调用 http://oldhost/。
如果 http 端点以网桥模式工作,它将忽略 Exchange.HTTP_URI 的消息标头。