Since we're on a major migration process of this website, some component documents here are out of sync right now. In the meantime you may want to look at the early version of the new website
https://camel.apache.org/staging/
We would very much like to receive any feedback on the new site, please join the discussion on the Camel user mailing list.
|
Format | Context | Comment |
---|---|---|
ghttp:///path[?options] | Consumer | See also Servlet component |
ghttp://hostname[:port][/path][?options] ghttps://hostname[:port][/path][?options] | Producer | See also Http component |
Options
Name | Default Value | Context | Description |
---|---|---|---|
| | Producer | If set to |
| | Producer | Throw a |
| reference to | Consumer | Reference to an |
| reference to | Producer | Reference to an |
On the consumer-side, all options of the Servlet component are supported.
Message headers
On the producer-side the following headers of the Http component are supported.
Name | Type | Description |
---|---|---|
| | The HTTP content type. Is set on both the |
| | The HTTP content encoding. Is set on both the |
| | The HTTP method to execute. One of |
| | Overrides the query part of the endpoint URI or the the query part of |
| | Overrides the default endpoint URI if the |
| | The HTTP response code from URL fetch service responses. |
On the consumer-side all headers of the Servlet component component are supported.
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).
Usage
Receiving messages
For receiving messages via the ghttp
component, a CamelHttpTransportServlet
must be configured and mapped in the application's 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:
... <servlet> <servlet-name>CamelServlet</servlet-name> <servlet-class>org.apache.camel.component.servlet.CamelHttpTransportServlet</servlet-class> ... </servlet> ... <servlet-mapping> <servlet-name>CamelServlet</servlet-name> <url-pattern>/camel/*</url-pattern> </servlet-mapping> ...
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
.
from("ghttp:///greeting?matchOnUriPrefix=true").transform().constant("Hello")
Sending messages
For sending resquests to external HTTP services the ghttp
component uses the URL fetch service. For example, the 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
from("ghttp:///home") .to("ghttp://camel.apache.org")
Sending a GET
request to http://<appname>.appspot.com/camel/home
returns the Camel homepage. HTTPS-based communication with external services can be enabled with the ghttps
scheme.
from(...) ... .to("ghttps://svn.apache.org/repos/asf/camel/trunk/") ...
Dependencies
Maven users will need to add the following dependency to their pom.xml
.
<dependency> <groupId>org.apache.camel</groupId> <artifactId>camel-gae</artifactId> <version>x.x.x</version> </dependency>