22.14. 如何将 http 方法(GET/PATCH/POST/PUT/DELETE/HEAD/OPTIONS/TRACE)设置为 HTTP producer
HTTP 组件提供了一种通过设置消息标头来设置 HTTP 请求方法的方法。下面是一个示例:
from("direct:start") .setHeader(Exchange.HTTP_METHOD, constant(org.apache.camel.component.http.HttpMethods.POST)) .to("http://www.google.com") .to("mock:results");
使用字符串常量可以比较短的写入方法:
.setHeader("CamelHttpMethod", constant("POST"))
等同于 Spring 示例:
<camelContext xmlns="http://activemq.apache.org/camel/schema/spring"> <route> <from uri="direct:start"/> <setHeader name="CamelHttpMethod"> <constant>POST</constant> </setHeader> <to uri="http://www.google.com"/> <to uri="mock:results"/> </route> </camelContext>