Servlet Component
The servlet: component provides HTTP based endpoints for consuming HTTP requests that arrive at a HTTP endpoint and this endpoint is bound to a published Servlet.
Note: This component is new to Camel 2.0.
URI format
servlet://relative_path[?options]
You can append query options to the URI in the following format, ?option=value&option=value&...
Options
Name |
Default Value |
Description |
---|---|---|
|
|
Reference to an |
|
|
Whether or not the |
|
|
Specifies the servlet name that the servlet endpoint will bind to. If there is no servlet name specified, the servlet endpoint will be bind to first published Servlet |
Message Headers
Camel will apply the same Message Headers as the HTTP component.
Camel will also populate all request.parameter
and request.headers
. For example, if a client request has the URL, http://myserver/myserver?orderid=123
, the exchange will contain a header named orderid
with the value 123.
Usage
You can only consume from endpoints generated by the Servlet component. Therefore, it should only be used as input into your camel routes. To issue HTTP requests against other HTTP endpoints, use the HTTP Component
Sample
In this sample, we define a route that exposes a HTTP service at http://localhost:8080/camel/services/hello
.
First, you need to publish the CamelHttpTransportServlet through the normal Web Container, or OSGi Service.
Use the Web.xml
file to publish the CamelHttpTransportServlet as follows:
Use an Activator
to publish the CamelHttpTransportServlet on the OSGi platform
Then you can define your route as follows:
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 camel-servlet
endpoint uses the relative path to specify the endpoint's URL. A client can access the camel-servlet
endpoint through the servlet publish address: ("http://localhost:8080/camel/services") + RELATIVE_PATH("/hello")
.