[英]Translating Apache Camel example from Spring DSL to Java DSL
I am trying to convert a Camel route in Spring DSL to its equivalent in Java DSL. 我正在尝试将Spring DSL中的骆驼路线转换为Java DSL中的等效路线。 I nailed most of the translations, but there is something I simply don't know how to do: to change the headers.
我钉了大部分翻译,但有些事情我根本不知道该怎么做:更改标题。
Here are the examples: 以下是示例:
Spring DSL: Spring DSL:
<bean id="service" class="org.apache.camel.example.service.Reporting" />
<camelContext xmlns="http://camel.apache.org/schema/spring">
<route id="mina1">
<from uri="mina:tcp://localhost:9991" />
<setHeader headerName="minaServer">
<constant>localhost:9991</constant>
</setHeader>
<bean ref="service" method="updateReport" />
<to uri="direct:messageSender1" />
</route>
</camelContext>
Java DSL: Java DSL:
public void configure() throws Exception {
from("mina:tcp://localhost:9991")
.setHeader(Exchange.HTTP_METHOD, constant("localhost:9991"))
.beanRef("camel_examples.loadbalancer_failover_javadsl.service.Reporting", "updateReport")
.to("direct:messageSender1");
}
And finally, the bean method that uses the Header: 最后,使用Header的bean方法:
public Report updateReport(@Body Report report, @Header("minaServer") String name) {
report.setReply("Report passed by MINA servers running on: " + name);
return report;
}
Now, on the example using Spring DSL, everything works fine. 现在,在使用Spring DSL的示例中,一切正常。 But in the example using Java DSL, I am simply unable to set the headers correctly.
但是在使用Java DSL的示例中,我根本无法正确设置标头。 it just does not happen.
只是没有发生。 I know the reason for this is the line
.setHeader(Exchange.HTTP_METHOD, constant("localhost:9991"))
, probably the Exchange.HTTP_METHOD
part, but I do not know what to put there either to be honest. 我知道这是因为行
.setHeader(Exchange.HTTP_METHOD, constant("localhost:9991"))
,可能是Exchange.HTTP_METHOD
部分,但是老实说,我不知道在那放什么。 I also tried with Exchange.HTTP_URI
and the result was the same. 我也尝试使用
Exchange.HTTP_URI
,结果是相同的。
What is wrong in my translation? 我的翻译有什么问题?
尝试这个
.exchange.getIn().setHeader("minaServer", constant("localhost:9991"))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.