Servlet Component
The servlet: component provides HTTP based endpoints for consuming HTTP requests that arrive at a http endpoint and this endpoint is bind with a published Servlet.
NOTE: This component is new to Camel 2.0.
URI format
jetty://RELATIVE_PATH[?options]
Options
Name |
Default Value |
Description |
---|---|---|
httpBindingRef |
null |
Reference to a |
matchOnUriPrefix |
false |
Whether or not the CamelServlet should try to find a target consumer by matching URI prefix if no exact match is found. |
servletName |
null |
Specifies the Servlet name which 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 form the HTTP component.
Camel will also populate all request.parameter and request.headers. For instance of a client request with http://myserver/myserver?orderid=123
then 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 you can use the HTTP Component
Sample
In this sample we define a route where we expose 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.
Using the Web.xml to publish the CamelHttpTransportServlet
Using the Activator to publish the CamelHttpTransportServlet in the OSGi platform
Then you can define you router like this
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, camel-servlet endpoint is using the relative path to specify the endpoint's URL. Client can access the camel-servlet endpoint through the Servlet publish address("http://localhost:8080/camel/services") + RELATIVE_PATH("/hello").