48.3. ghttp

ghttp Component

The ghttp component contributes to the Camel Components for Google App Engine (GAE). It provides connectivity to the GAE URL fetch service but can also be used to receive messages from servlets (the only way to receive HTTP requests on GAE). This is achieved by extending the Servlet component. As a consequence, ghttp URI formats and options sets differ on the consumer-side (from) and producer-side (to).

Options

If set to true the Exchange.HTTP_URI header will be ignored. To override the default endpoint URI with the Exchange.HTTP_URI header set this option to false.

throwExceptionOnFailure

true

Producer

Throw a org.apache.camel.component.gae.http if the response code is >= 400. To disable throwing an exception set this option to false.

inboundBindingRef

reference to GHttpBinding

Consumer

Reference to an InboundBinding<GHttpEndpoint, HttpServletRequest, HttpServletResponse> in the Registry for customizing the binding of an Exchange to the Servlet API. The referenced binding is used as post-processor to org.apache.camel.component.http.HttpBinding.

outboundBindingRef

reference to GHttpBinding

Producer

Reference to an OutboundBinding<GHttpEndpoint, HTTPRequest, HTTPResponse> in the Registry for customizing the binding of an Exchange to the URLFetchService.

Message body

On the producer side the in message body is converted to a byte[]. The out message body is made available as InputStream. If the reponse size exceeds 1 megabyte a ResponseTooLargeException is thrown by the URL fetch service (see quotas and limits).

Receiving messages

For receiving messages via the ghttp component, a CamelHttpTransportServlet must be configured and mapped in the application's web.xml (see the section called “The web.xml”). For example, to handle requests targeted at http://<appname>.appspot.com/camel/* or http://localhost/camel/* (when using a local development server) the following servlet mapping must be defined:

Endpoint URI path definitions are relative to this servlet mapping e.g. the route

from("ghttp:///greeting").transform().constant("Hello")

processes requests targeted at http://<appname>.appspot.com/camel/greeting. In this example, the request body is ignored and the response body is set to Hello. Requests targeted at http://<appname>.appspot.com/camel/greeting/* are not processed by default. This requires setting the option matchOnUriPrefix to true.

Sending messages

For sending resquests to external HTTP services the ghttp component uses the URL fetch service. For example, the Apache Camel homepage can the retrieved with the following endpoint definition on the producer-side.

from(...)
...
.to("ghttp://camel.apache.org")
...

The HTTP method used depends on the Exchange.HTTP_METHOD message header or on the presence of an in-message body (GET if null, POST otherwise). Retrieving the Camel homepage via a GAE application is as simple as