如何从 Camel servlet 组件路由到 http 组件? [英] How to route from Camel servlet component to http component?

查看:29
本文介绍了如何从 Camel servlet 组件路由到 http 组件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm trying to configure a multicast route that receives an HTTP POST and POSTs it to multiple instances of a service.

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

From reading the documentation, and playing with the camel-example-servlet-tomcat, it looks like it should be simple, but i'm stuck. This question was helpful, but i'm still stuck.

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

Here's my web.xml for configuring the Camel Servlet:

<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>

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

Here's my camel context and route:

<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 的海报"插件)成功地直接发布到两个端点 URI.

The service expects data in request parameters. i can post directly to both endpoint URIs with an http tool ("Poster" plugin for Firefox) successfully.

但是,当我发布到这个 web 应用程序(在 Jetty 中运行)时,在 URI "http://localhost:8080/send/license" 我收到 404 错误.在 Jetty 调试日志中,我看到DEBUG [CamelHttpTransportServlet.service]: No consumer服务请求 [POST/send/license]"

However, when i post to this webapp (running in Jetty), at the URI "http://localhost:8080/send/license" i get a 404 error. In the Jetty debug log, i see "DEBUG [CamelHttpTransportServlet.service]: No consumer to service request [POST /send/license]"

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

I tried simplifying the route to look like this:

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

To simplify the route, i dropped the multicast component, so it looks like this:

<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"/>,我得到了同样的错误.

but i get the same error. Using <from uri="servlet:///0.0.0.0:8080/send/license"/>, i get the same error.

我是否在为 Camel servlet 配置 URI 时遗漏了一些明显的内容?

Am i missing something obvious in configuring the URI for the Camel servlet?

推荐答案

如果您的 servlet 没有使用默认名称 CamelServlet,那么您需要在端点 uri 中引用该名称,

If you do not use the default name for your servlet as CamelServlet, then you need to refer to that name in the endpoint uri,

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

应该是

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

这篇关于如何从 Camel servlet 组件路由到 http 组件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆