joeniski
joeniski

Reputation: 156

How to route from Camel servlet component to http component?

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

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.

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>

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

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>

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

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

Upvotes: 1

Views: 7107

Answers (1)

Claus Ibsen
Claus Ibsen

Reputation: 55525

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

Should then be

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

Upvotes: 7

Related Questions