Name

HTTP4 — provides endpoints for consuming external HTTP resources using Apache HttpClient 4.x

Overview

The HTTP4 component provides HTTP based endpoints for consuming external HTTP resources as a client to call external servers using HTTP.

The HTTP4 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.

[Important]Important

HTTP4 uses HttpClient 4.x while HTTP uses HttpClient 3.x.

URI format

The URI format for an HTTP4 endpoint is:

http(s)4:hostname[:port][/resourceUri][?options]

By default the port is set to 80 for HTTP and to 443 for HTTPS.

Dependencies

Maven users will need to add a dependency on camel-http4 to their pom.xml for this component:

<dependency>
    <groupId>org.apache.camel</groupId>
    <artifactId>camel-http4</artifactId>
    <version>x.x.x</version>
    <!-- use the same version as your Camel core version -->
</dependency>

HttpEndpoint options

Table 24, “HTTP4 endpoint options” lists the options for an HTTP4 endpoint.

Table 24. HTTP4 endpoint options

NameDefaultDescription
x509HostnameVerifierBrowserCompatHostnameVerifier [a] Specifies an X509HostnameVerifier[a] instance in the registry.
throwExceptionOnFailuretrueSpecifies 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.
bridgeEndpointfalseSpecifies 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.
disableStreamCachefalseSpecifies 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.
httpBindingnullSpecifies a reference to a HttpBinding[b] in the registry.
httpClientConfigurernullSpecifies a reference to a HttpClientConfigurer [b] in the registry.
httpClient.XXX Specifies options to set on the BasicHttpParams. For instance, httpClient.soTimeout=5000 will set the SO_TIMEOUT to 5 seconds.
clientConnectionManagernullSpecifies a custom ClientConnectionManager [c].
transferExceptionfalseSpecifies if a producer will throw the received exception if the received exception was serialized in the response as a application/x-java-serialized-object content type.
maxTotalConnections200Specifies the maximum number of connections.
connectionsPerRoute20Specifies the maximum number of connections per route.

[a] In the package org.apache.http.conn.ssl.

[b] In the org.apache.camel.component.http package.

[c] In the org.apache.http.conn package.


Authentication and proxy options

The following authentication options can also be set on the HTTP4 endpoint:

NameDefaultDescription
username null Username for authentication.
password null Password for authentication.
domain null The domain name for authentication.
host null The host name authentication.
proxyHost null The proxy host name
proxyPort null The proxy port number
proxyUsername null Username for proxy authentication
proxyPassword null Password for proxy authentication
proxyDomain null The proxy domain name
proxyNtHost null The proxy Nt host name

HttpComponent options

The following options can be set on the HttpComponent:

NameDefaultDescription
httpBinding null To use a custom org.apache.camel.component.http.HttpBinding.
httpClientConfigurer null To use a custom org.apache.camel.component.http.HttpClientConfigurer.
httpConnectionManager null To use a custom org.apache.commons.httpclient.HttpConnectionManager.
x509HostnameVerifier null To use a custom org.apache.http.conn.ssl.X509HostnameVerifier

Message headers

The following Exchange properties are recognized by HTTP4 endpoints:

Table 25. HTTP Exchange properties

NameTypeDescription
CamelHttpUriStringSpecifies the URI to call. The value if this header will override the URI set directly on the endpoint.
CamelHttpPathStringSpecifies 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.
CamelHttpQueryStringSpecifies the URI parameters. The value of this header overrides the URI parameters set directly on the endpoint.
CamelHttpResponseCodeintSpecifies the HTTP response code from the external server.
CamelHttpCharacterEncodingStringSpecifies the character encoding.
Content-TypeStringSpecifies the HTTP content type. This header is populated on both the IN and OUT message to provide a content type, such as text/html.
Content-EncodingStringSpecifies the HTTP content encoding. This header is populated on both the IN and OUT message to provide a content encoding, such as gzip.
CamelHttpServletRequestStringSpecifies the HttpServletRequest object.
CamelHttpServletResponseStringSpecifies the HttpServletResponse object.
CamelHttpProtocolVersionStringSpecifies the HTTP protocol version. If you do not specify the header, HttpProducer will use the default value HTTP/1.1.

Message Body

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.

Response code

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.

    [Note]Note

    The option, 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.

Related topics

HTTP
Jetty
BasicHttpParams