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

Compare with Current View Page History

« Previous Version 9 Next »

Jetty Component

The jetty: component provides HTTP based endpoints for consuming HTTP requests that arrive at an http endpoint.

URI format

jetty:http:hostname[:port][/resourceUri][?options]

Options

Name

Description

Example

Required?

default value

sessionSupport

The option for enable the session manager in the server side of Jetty.

sessionSupport=true

No

false

Message Headers

Camel will add the following headers to the input message on the exchange

header

description

http.requestMethod

The request method: POST, GET, PUT, etc.

org.apache.camel.component.http.query

The HTTP query string (request.getQueryString)

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. This feature is introduced in Camel 1.5.

Usage

You can only consume from endpoints generated by the Jetty 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/myapp/myservice:

Error formatting macro: snippet: java.lang.NullPointerException

Our business logic is implemented in our MyBookService class where we can access the http request stuff and return a response.
Note: The assert is because the code is part of an unit test.

Error formatting macro: snippet: java.lang.NullPointerException

In the sample below we have a content based route that routes all requests that contain the URI parameter one to mock:one and all others to mock:other.

Error formatting macro: snippet: java.lang.NullPointerException

So if a client sends the http request: http://serverUri?one=hello then camel-jetty will copy the http request parameter one to the exchange.in.header. Then we can use the simple language to route exchanges that contain this header to a specific endpoint and all others to another. If we used a more powerful language than Simple such as El or OGNL would could also test for the parameter value and do routing based on the header value as well.

  • No labels