Servlet Tomcat Example

Since Camel 2.7

This example is located in the examples/camel-example-servlet-tomcat directory of the Camel Examples Repository. There is a README.adoc file with instructions how to run it.

If you use Maven then you can easily package the example from the command line:

mvn package


This example demonstrates how you can use Servlet to expose a http service in a Camel route.


In the web.xml file in the src/main/webapp/WEB-INF folder the CamelServlet is defined. This is mandatory to do when using the Servlet component.

<web-app version="2.4" xmlns=""

  <display-name>My Web Application</display-name>

  <!-- location of spring xml files -->

  <!-- the listener that kick-starts Spring -->

  <!-- Camel servlet -->

  <!-- Camel servlet mapping -->


The route is a simple Content Based Router defined in the DSL XML as shown:

<beans xmlns=""

  <camelContext xmlns="">

    <route id="helloRoute">
      <!-- incoming requests from the servlet is routed -->
      <from uri="servlet:hello"/>
          <!-- is there a header with the key name? -->
          <!-- yes so return back a message to the user -->
            <simple>Hi I am ${sysenv.HOSTNAME}. Hello ${} how are you today?</simple>
          <!-- if no name parameter then output a syntax to the user -->
            <constant>Add a name parameter to uri, eg ?name=foo</constant>



Running the example

This example runs in Apache Tomcat, so you will have to package the .war file and copy it to the webapp folder of Tomcat, which is the hot deploy folder.

There is a main page at http://localhost:8080/camel-example-servlet-tomcat which has more instructions. You can then use a web browser and send a request to the http://localhost:8080/camel-example-servlet-tomcat/camel/hello URL.