You are viewing an old version of this page. View the current version.

Compare with Current View Page History

Version 1 Next »

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 org.apache.camel.component.http.HttpBinding in the Registry. HttpBinding can be used to customize how response should be written.

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 Servlet through the normal Web Container, or OSGi Service.
Using the Web.xml to publish the Servlet

Error formatting macro: snippet: java.lang.NullPointerException

Using the Activator to publish the Servlet in the OSGi platform

Error formatting macro: snippet: java.lang.NullPointerException

Then you can define you router like this

Error formatting macro: snippet: java.lang.NullPointerException

Specify the relative path

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").

  • No labels