HTTP — provides endpoints for consuming external HTTP resources
The HTTP component provides HTTP based endpoints for consuming external HTTP resources as a client to call external servers using HTTP.
The HTTP component can only send messages to external resources. It should never be used as input into a route. To expose an HTTP endpoint via a HTTP server as input to a route, you can use the Jetty Component.
The URI format for an HTTP endpoint is:
http(s):hostname
[:port
][/resourceUri
][?options
]
By default the port is set to 80
for HTTP and to
443
for HTTPS.
Maven users will need to add a dependency on camel-http
to their
pom.xml
for this component:
<dependency> <groupId>org.apache.camel</groupId> <artifactId>camel-http</artifactId> <version>x.x.x</version> <!-- use the same version as your Camel core version --> </dependency>
Table 21, “HTTP endpoint options” lists the options for an HTTP endpoint.
Table 21. HTTP endpoint options
Name | Default Value | Description |
---|---|---|
throwExceptionOnFailure | true | Specifies if you want to disable throwing the
HttpOperationFailedException in case of failed
responses from the remote server. This allows you to get all responses regardless of
the HTTP status code. |
bridgeEndpoint | false | Specifies if the HttpProducer ignores the Exchange.HTTP_URI
header, and use the endpoint's URI for request. If the option is true ,
HttpProducer and CamelServlet will skip the gzip processing if the
content-encoding is gzip . |
disableStreamCache | false | Specifies if the DefaultHttpBinding copies the request input stream directly into the message body. The default setting is to copy the request input stream into a stream cache and into the message body to support reading the message twice. |
httpBinding | null | Specifies a reference to a
org.apache.camel.component.http.HttpBinding in the registry. |
httpClientConfigurer | null | Specifies a reference to a
org.apache.camel.component.http.HttpClientConfigurer in the registry. |
httpClient. | Specifies options to set on the HttpClientParams. For instance httpClient.soTimeout=5000 will set the
SO_TIMEOUT to 5 seconds. | |
clientConnectionManager | null | Specifies a reference to a custom
org.apache.http.conn.ClientConnectionManager . |
The following authentication options can also be set on the HTTP endpoint:
Table 22. HTTP authentication options
Name | Description |
---|---|
authMethod |
Specifies the authentication method to use. Supported methods are:
|
authMethodPriority | Specifies the priority of the authentication methods using a comma seperated list. |
authUsername | Specifies the username for authentication. |
authPassword | Specifies the password for authentication. |
authDomain | Specifies the domain for NTML authentication. |
authHost | Specifies an optional host for NTML authentication. |
proxyHost | Specifies the proxy host name. |
proxyPort | Specifies the proxy port number. |
proxyAuthMethod |
Specifies the authentication method to use for connecting to the proxy. Supported methods are:
|
proxyAuthUsername | Specifies the username for proxy authentication. |
proxyAuthPassword | Specifies the password for proxy authentication. |
proxyAuthDomain | Specifies the domain for proxy NTML authentication. |
proxyAuthHost | Specifies the optional host for proxy NTML authentication. |
When using authentication you must provide a value for
either the authMethod
or authProxyMethod
options.
The following Exchange
properties are recognized by HTTP endpoints:
Table 23. HTTP Exchange properties
Name | Type | Description |
---|---|---|
CamelHttpUri | String | Specifies the URI to call. The value if this header will override the URI set directly on the endpoint. |
CamelHttpPath | String | Specifies the Request URI's path. The header will be used to build the request
URI with the HTTP_URI. If the path is start with / , the HTTP producer
will try to find the relative path based on the HTTP_BASE_URI header or
the exchange.getFromEndpoint().getEndpointUri() method. |
CamelHttpQuery | String | Specifies the URI parameters. The value of this header overrides the URI parameters set directly on the endpoint. |
CamelHttpResponseCode | int | Specifies the HTTP response code from the external server. |
CamelHttpCharacterEncoding | String | Specifies the character encoding. |
Content-Type | String | Specifies the HTTP content type. This header is populated on both the IN and OUT message to provide a content type. |
Content-Encoding | String | Specifies the HTTP content encoding. This header is populated on both the IN and OUT message to provide a content encoding. |
CamelHttpServletRequest | String | Specifies the HttpServletRequest object. |
CamelHttpServletResponse | String | Specifies the HttpServletResponse object. |
CamelHttpProtocolVersion | String | Specifies the HTTP protocol version. If you do not specify the header,
HttpProducer will use the default value HTTP/1.1 . |
Apache Camel will store the HTTP response from the external server on the OUT body. All headers from the IN message will be copied to the OUT message, so headers are preserved during routing. Additionally, Apache Camel will add the HTTP response headers as well to the OUT message headers.
Apache Camel will handle according to the HTTP response code:
Response code is in the range 100..299, Apache Camel regards it as a success response.
Response code is in the range 300..399, Apache Camel regards it as a redirection
response and will throw a HttpOperationFailedException
with
the information.
Response code is 400+, Apache Camel regards it as an external server failure and will
throw a HttpOperationFailedException
with the
information. throwExceptionOnFailure
can be set to
false
to prevent the
HttpOperationFailedException
from being
thrown for failed response codes. This allows you to get any response from the
remote server.