我将camel-example-servlet-tomcat-no-spring示例部署到了tomcat。效果很好。我更改了camel-config.xml,但出现以下错误。
java.lang.IllegalArgumentException: Invalid uri: /camel-example/camel/hello. If you are forwarding/bridging http endpoints, then enable the bridgeEndpoint option on the endpoint: Endpoint[https://www.google.com]
at org.apache.camel.component.http.HttpProducer.createMethod(HttpProducer.java:376)
at org.apache.camel.component.http.HttpProducer.process(HttpProducer.java:91)
at org.apache.camel.util.AsyncProcessorConverterHelper$ProcessorToAsyncProcessorBridge.process(AsyncProcessorConverterHelper.java:61)
at org.apache.camel.processor.SendProcessor.process(SendProcessor.java:110)
at org.apache.camel.management.InstrumentationProcessor.process(InstrumentationProcessor.java:72)
at org.apache.camel.processor.RedeliveryErrorHandler.process(RedeliveryErrorHandler.java:398)
at org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:191)
at org.apache.camel.processor.loadbalancer.QueueLoadBalancer.process(QueueLoadBalancer.java:43)
at org.apache.camel.management.InstrumentationProcessor.process(InstrumentationProcessor.java:72)
at org.apache.camel.processor.RedeliveryErrorHandler.process(RedeliveryErrorHandler.java:398)
at org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:191)
at org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:191)
at org.apache.camel.util.AsyncProcessorHelper.process(AsyncProcessorHelper.java:105)
at org.apache.camel.processor.DelegateAsyncProcessor.process(DelegateAsyncProcessor.java:87)
at org.apache.camel.component.http.CamelServlet.service(CamelServlet.java:127)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:723)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)
at org.apache.coyote.http11.Http11AprProcessor.process(Http11AprProcessor.java:879)
at org.apache.coyote.http11.Http11AprProtocol$Http11ConnectionHandler.process(Http11AprProtocol.java:617)
at org.apache.tomcat.util.net.AprEndpoint$Worker.run(AprEndpoint.java:1760)
at java.lang.Thread.run(Thread.java:662)
实际的camel-config.xml:
<routes xmlns="http://camel.apache.org/schema/spring">
<route>
<from uri="servlet:///hello"/>
<choice>
<when>
<header>name</header>
<transform>
<simple>Hello ${header.name} how are you?</simple>
</transform>
</when>
<otherwise>
<transform>
<constant>Add a name parameter to uri, eg ?name=foo</constant>
</transform>
</otherwise>
</choice>
</route>
</routes>
更改了camel-config.xml:
<routes xmlns="http://camel.apache.org/schema/spring">
<route>
<from uri="servlet:///hello"/>
<loadBalance>
<weighted roundRobin="false" distributionRatio="1"/>
<to uri="https://www.google.com"/>
</loadBalance>
</route>
</routes>
我的网址:
http://localhost:8080/camel-example/camel/hello?bridgeEndpoint=true
我添加了bridgeEndpoint=true并也删除了,我尝试了两种方法。我遇到了同样的错误。
请帮帮我
how do I configure http urls in <to> tag.
最佳答案
啊,servlet 组件使用 HTTP 端点拾取和使用的一些 HTTP 相关 header 来丰富消息。
因此,您需要做的是在路由到 http uri 之前删除这些 header 。
<from uri="servlet:///hello"/>
<removeHeaders pattern="CamelHttp*"/>
...
Camel 网站上有一个关于此问题的常见问题解答:http://camel.apache.org/how-to-remove-the-http-protocol-headers-in-the-camel-message.html
关于java - Camel servlet 没有带 http uri 的 spring 示例 <to> 标记?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20325337/