当前位置: 首页 > 知识库问答 >
问题:

Camel处理器未设置标头

居飞扬
2023-03-14
    <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&amp;period=60000" />
        <process ref="refProcessor" />
        <to uri="http://dummyhost" />
        <to uri="log:DEBUG?showBody=true&amp;showHeaders=true" />
    </route>
</routeContext>
<bean id="refProcessor"
    class="com.abc.de.RefProcessor" />
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");
 }
}

日志-消息历史记录路由ID处理器ID处理器运行(ms)[sdPoll][sdPoll][Timer://sdPoll?FixedRate=true&period=60000][21176][null][onCompletion1][onCompletion][106][sdPoll][process7][Ref:RefProcessor][21067][null][process3][Ref:GenericErrorHandle][21016]

Exchange[Id ID-ABC-63143-1516034486954-0-2 ExchangePattern InOnly头{breadcrumbid=ID-ABC-63143-1516034486954-0-1,camelredelivered=false,camelredeliverycounter=0,Firedtime=mon 1月15日11:41:31 EST 2018}BodyType null Body[Body is null]]

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处理器运行(ms)[route1][route1][timer://timer1?period=60000][86][route1][process1][refprocessorcamel$3$1@258e2e41][6][route1][to1][http://dummyhost][76]

Exchange[Id ID-ABC-63940-1516036107063-0-2 ExchangePattern InOnly 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=mon 1月15日12:10:21 EST 2018}

共有1个答案

曾泳
2023-03-14

你的处理器看起来没问题。

只是胡乱猜测,但您是否有意在XML配置中使用routeContext?如果没有,可以尝试切换到CamelContext吗?

有关RouteContextCamelContext之间的区别,请参见http://people.apache.org/~dkulp/camel/configuring-camel.html

 类似资料:
  • 请查看下面位于扩展类内部的代码: null

  • 问题内容: 现在看起来像这样 有没有办法一次将缓存标头设置给所有处理程序? 问题答案: 包裹多路复用器 而不是单个处理程序。 请注意,使用的处理程序时的处理程序参数是。另外,将和处理程序添加到。

  • 我们有一个服务调用,它返回一个id列表,我们用它调用另一个服务,该服务一次只接受一个id,因此我们使用的是驼峰分割器,并行处理转换为。现在,我们通过seda调用该服务,因此可以设置超时。这将导致并行处理不再是并行的问题,因为seda默认只有1个并发使用者在处理它。 选项: < li >放一个?seda上的concurrent consumers = x < li >使用direct而不是seda。

  • 该链接包含在错误404s中(https://developer.android.com/r/tools/annotation-processor-error-message.html),因此没有帮助。 我已经在android studio设置中启用了注释处理,并将添加到我的注释处理器选项中。我还尝试将、和添加到处理器FQ名称中,但这也没有帮助。 这些是我添加到dependecies下的默认buil

  • 正确使用CSS预处理器(如Sass),以及JS预处理器和转换器可以大大提升你的开发效率。本文讲解如何设置设置CSS和JS预处理器。 TL;DR 预处理器允许您使用浏览器原生不支持的CSS和JavaScript中的特性,例如,CSS变量。 如果你使用预处理器,使用Source Maps(源映射)将原始源文件映射到渲染输出文件。 确保您的网络服务器支持Source Maps(源映射)。使用支持的预处理

  • 我的logback.xml如下: 当我查看wireshark的输出时,我只看到记录的JSON(没有给出PRI头字段) 如果切换到标准logback Syslog appender(非JSON输出)