The servlet: component provides HTTP based endpoints for consuming HTTP requests that arrive at a HTTP endpoint that is bound to a published Servlet.
Maven users will need to add the following dependency to their
Servlet is stream based, which means the input it receives is submitted to Camel as a stream. That means you will only be able to read the content of the stream once. If you find a situation where the message body appears to be empty or you need to access the data multiple times (eg: doing multicasting, or redelivery error handling) you should use Stream caching or convert the message body to a
You can append query options to the URI in the following format,
Camel will apply the same Message Headers as the HTTP component.
Camel will also populate all
You can consume only from endpoints generated by the Servlet component. Therefore, it should be used only as input into your Camel routes. To issue HTTP requests against other HTTP endpoints, use the HTTP Component
Using Servlet 3.0 Async Mode
Available as of Camel 2.18
You can configure the servlet with an init-param to turn on async mode when using a Servlet 3.x container. There is a sample XML configuration below:
Putting Camel JARs in the app server boot classpath
If you put the Camel JARs such as
Mind that putting Camel JARs in the boot classpath of the application server is generally not best practice!
So in those situations you must define a custom and unique servlet name in each of your Camel application, eg in the
And in your Camel endpoints then include the servlet name as well
From Camel 2.11 onwards Camel will detect this duplicate and fail to start the application. You can control to ignore this duplicate by setting the servlet init-parameter ignoreDuplicateServletName to true as follows:
But its strongly advised to use unique servlet-name for each Camel application to avoid this duplication clash, as well any unforeseen side-effects.
In this sample, we define a route that exposes a HTTP service at
Specify the relative path for camel-servlet endpoint
Since we are binding the Http transport with a published servlet, and we don't know the servlet's application context path, the
Sample when using Spring 3.x
Sample when using Spring 2.x
When using the Servlet component in a Camel/Spring application it's often required to load the Spring ApplicationContext after the Servlet component has started. This can be accomplished by using Spring's
Sample when using OSGi
From Camel 2.6.0, you can publish the CamelHttpTransportServlet as an OSGi service with help of SpringDM like this.
Error formatting macro: snippet: java.lang.IndexOutOfBoundsException: Index: 20, Size: 20Then use this service in your camel route like this:
Error formatting macro: snippet: java.lang.IndexOutOfBoundsException: Index: 20, Size: 20For versions prior to Camel 2.6 you can use an
Error formatting macro: snippet: java.lang.IndexOutOfBoundsException: Index: 20, Size: 20