Camel 处理器未设置 headers
Camel Processor not setting headers
我无法在使用以下 spring DSL 配置的处理器中 inject/modify headers。你能帮我弄清楚我做错了什么吗?
<routeContext xmlns="http://camel.apache.org/schema/spring"
id="routes1">
<route id="sdPoll" de:name="Polling"
de:systemName="Polling" streamCache="true">
<from uri="timer://sdPoll?fixedRate=true&period=60000" />
<process ref="refProcessor" />
<to uri="http://dummyhost" />
<to uri="log:DEBUG?showBody=true&showHeaders=true" />
</route>
</routeContext>
<bean id="refProcessor"
class="com.abc.de.RefProcessor" />
处理器class
public class RefProcessor implements Processor {
private final Logger log = Logger.getLogger(RefProcessor.class);
@SuppressWarnings("unchecked")
@Override
public void process(Exchange exchange) throws Exception {
exchange.getIn().setHeader("Authorization", "TODO");
exchange.getIn().setHeader("CamelHttpMethod", "POST");
exchange.getIn().setHeader("CamelHttpUri", "http://localhost:8280/api/check");
exchange.getIn().setHeader("Content-Type", "application/json");
exchange.getIn().setHeader("Accept", "application/json");
exchange.getIn().setBody("TODO");
//exchange.getOut().setHeaders(exchange.getIn().getHeaders());
//exchange.getOut().setHeader("Authorization", "TODO");
//exchange.getOut().setBody("TODO");
}
}
日志-
留言历史
RouteId ProcessorId 处理器经过(毫秒)
[sdPoll] [sdPoll] [timer://sdPoll?fixedRate=true&period=60000] [21176]
[null] [onCompletion1] [onCompletion] [106]
[sdPoll] [process7] [ref:refProcessor] [21067]
[null] [process3] [ref:GenericErrorHandle] [21016]
交换[
ID ID-ABC-63143-1516034486954-0-2
仅交换模式
Headers {breadcrumbId=ID-ABC-63143-1516034486954-0-1,CamelRedelivered=false,CamelRedeliveryCounter=0,firedTime=1 月 15 日星期一 11:41:31 EST 2018}
Body输入空
Body [Body 为空]
]
Java DSL 似乎可以工作!那么我的 Spring DSL 配置有什么问题
static RouteBuilder createRouteBuilder3() {
return new RouteBuilder() {
public void configure() {
from("timer://timer1?period=60000").process(new Processor() {
public void process(Exchange exchange) throws UnsupportedEncodingException {
exchange.getIn().setHeader("CamelHttpMethod", "POST");
exchange.getIn().setHeader("Content-Type", "application/json");
exchange.getIn().setHeader("Accept", "application/json");
exchange.getIn().setHeader("CamelHttpUri",
"http://localhost:8280/api/check");
exchange.getIn().setHeader("Authorization", "TODO");
exchange.getIn().setBody("TODO");
}
}).to("http://dummyhost").to("log:DEBUG?showBody=true&showHeaders=true");
}
};
}
消息历史记录
RouteId ProcessorId 处理器经过(毫秒)
[route1] [route1] [timer://timer1?period=60000] [86]
[route1] [process1] [RefProcessorCamel$3$1@258e2e41] [6]
[路线 1][到 1][http://dummyhost][76]
交换[
ID ID-ABC-63940-1516036107063-0-2
仅交换模式
Headers {Accept=application/json, Authorization=TODO, breadcrumbId=ID-ABC-63994-1516036220042-0-1, CamelHttpMethod=POST, CamelHttpUri=http://localhost:8280/api/check,CamelRedelivered=false,CamelRedeliveryCounter=0,Content-Type=application/json,firedTime=1 月 15 日星期一 12:10:21 EST 2018}
Body类型字符串
Body待办事项
]
您的处理器看起来没问题。
纯属胡乱猜测,但您是否有意在 XML 配置中使用 routeContext
?如果没有,你可以尝试切换到camelContext
吗?
routeContext
和camelContext
的区别见http://people.apache.org/~dkulp/camel/configuring-camel.html
我无法在使用以下 spring DSL 配置的处理器中 inject/modify headers。你能帮我弄清楚我做错了什么吗?
<routeContext xmlns="http://camel.apache.org/schema/spring"
id="routes1">
<route id="sdPoll" de:name="Polling"
de:systemName="Polling" streamCache="true">
<from uri="timer://sdPoll?fixedRate=true&period=60000" />
<process ref="refProcessor" />
<to uri="http://dummyhost" />
<to uri="log:DEBUG?showBody=true&showHeaders=true" />
</route>
</routeContext>
<bean id="refProcessor"
class="com.abc.de.RefProcessor" />
处理器class
public class RefProcessor implements Processor {
private final Logger log = Logger.getLogger(RefProcessor.class);
@SuppressWarnings("unchecked")
@Override
public void process(Exchange exchange) throws Exception {
exchange.getIn().setHeader("Authorization", "TODO");
exchange.getIn().setHeader("CamelHttpMethod", "POST");
exchange.getIn().setHeader("CamelHttpUri", "http://localhost:8280/api/check");
exchange.getIn().setHeader("Content-Type", "application/json");
exchange.getIn().setHeader("Accept", "application/json");
exchange.getIn().setBody("TODO");
//exchange.getOut().setHeaders(exchange.getIn().getHeaders());
//exchange.getOut().setHeader("Authorization", "TODO");
//exchange.getOut().setBody("TODO");
}
}
日志- 留言历史 RouteId ProcessorId 处理器经过(毫秒) [sdPoll] [sdPoll] [timer://sdPoll?fixedRate=true&period=60000] [21176] [null] [onCompletion1] [onCompletion] [106] [sdPoll] [process7] [ref:refProcessor] [21067] [null] [process3] [ref:GenericErrorHandle] [21016]
交换[ ID ID-ABC-63143-1516034486954-0-2 仅交换模式 Headers {breadcrumbId=ID-ABC-63143-1516034486954-0-1,CamelRedelivered=false,CamelRedeliveryCounter=0,firedTime=1 月 15 日星期一 11:41:31 EST 2018} Body输入空 Body [Body 为空] ]
Java DSL 似乎可以工作!那么我的 Spring DSL 配置有什么问题
static RouteBuilder createRouteBuilder3() {
return new RouteBuilder() {
public void configure() {
from("timer://timer1?period=60000").process(new Processor() {
public void process(Exchange exchange) throws UnsupportedEncodingException {
exchange.getIn().setHeader("CamelHttpMethod", "POST");
exchange.getIn().setHeader("Content-Type", "application/json");
exchange.getIn().setHeader("Accept", "application/json");
exchange.getIn().setHeader("CamelHttpUri",
"http://localhost:8280/api/check");
exchange.getIn().setHeader("Authorization", "TODO");
exchange.getIn().setBody("TODO");
}
}).to("http://dummyhost").to("log:DEBUG?showBody=true&showHeaders=true");
}
};
}
消息历史记录 RouteId ProcessorId 处理器经过(毫秒) [route1] [route1] [timer://timer1?period=60000] [86] [route1] [process1] [RefProcessorCamel$3$1@258e2e41] [6] [路线 1][到 1][http://dummyhost][76]
交换[ ID ID-ABC-63940-1516036107063-0-2 仅交换模式 Headers {Accept=application/json, Authorization=TODO, breadcrumbId=ID-ABC-63994-1516036220042-0-1, CamelHttpMethod=POST, CamelHttpUri=http://localhost:8280/api/check,CamelRedelivered=false,CamelRedeliveryCounter=0,Content-Type=application/json,firedTime=1 月 15 日星期一 12:10:21 EST 2018} Body类型字符串 Body待办事项 ]
您的处理器看起来没问题。
纯属胡乱猜测,但您是否有意在 XML 配置中使用 routeContext
?如果没有,你可以尝试切换到camelContext
吗?
routeContext
和camelContext