首页 文章

如何从Camel servlet组件路由到http组件?

提问于
浏览
1

我正在尝试配置接收HTTP POST的组播路由,并将其POST到服务的多个实例 .

从阅读文档,并使用camel-example-servlet-tomcat,它看起来应该很简单,但我被卡住了 . 这个question很有帮助,但我仍然被卡住了 .

这是我用于配置Camel Servlet的web.xml:

<web-app...>
<!-- location of spring xml files -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/applicationContext.xml</param-value>
</context-param>
<!-- Camel servlet -->
<servlet>
<servlet-name>MulticastServlet</servlet-name>
<servlet-class>org.apache.camel.component.servlet.CamelHttpTransportServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<!-- Camel servlet mapping -->
<servlet-mapping>
<servlet-name>MulticastServlet</servlet-name>
<url-pattern>/send/*</url-pattern>
</servlet-mapping>
<!-- the listener that kick-starts Spring -->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<welcome-file-list>
<welcome-file>WEB-INF/index.xhtml</welcome-file>
</welcome-file-list>
</web-app>

这是我的骆驼背景和路线:

<camelContext trace="true" id="multicastCtx" 
xmlns="http://camel.apache.org/schema/spring">
<route id="multicastRoute">
<from uri="servlet:///license"/>
<multicast stopOnException="false">
<to uri="http://192.168.22.95:8135/transform-service/send/license"/>
<to uri="http://10.50.1.58:9080/send/license"/>
</multicast>
</route>
</camelContext>

该服务期望请求参数中的数据 . 我可以成功地使用http工具(Firefox的“Poster”插件)直接发布到两个 endpoints URI .

但是,当我发布到这个webapp(在Jetty中运行)时,在URI“http://localhost:8080/send/license " i get a 404 error. In the Jetty debug log, i see " DEBUG [CamelHttpTransportServlet.service]:没有消费者对服务请求[POST / send / license]”

我尝试将路由简化为如下所示:

为了简化路由,我删除了多播组件,所以它看起来像这样:

<route id="myRoute" streamCache="true">
<from uri="servlet:///license"/>
<to uri="http://192.168.22.95:8135/transform-service/send/license"/>
</route>

但我得到同样的错误 . 使用 <from uri="servlet:///0.0.0.0:8080/send/license"/> ,我得到相同的错误 .

在配置Camel servlet的URI时,我是否遗漏了一些明显的东西?

1 回答

  • 7

    如果不将servlet的默认名称用作CamelServlet,则需要在 endpoints uri中引用该名称,

    <from uri="servlet:///license"/>
    

    应该是

    <from uri="servlet:///license?servletName=MulticastServlet"/>
    

相关问题