Name

HTTP — provides endpoints for consuming external HTTP resources

Overview

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.

URI format

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.

Dependencies

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>

Options

Table 21, “HTTP endpoint options” lists the options for an HTTP endpoint.

Table 21. HTTP endpoint options

NameDefault ValueDescription
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 org.apache.camel.component.http.HttpBinding in the registry.
httpClientConfigurernullSpecifies a reference to a org.apache.camel.component.http.HttpClientConfigurer in the registry.
httpClient.XXX Specifies options to set on the HttpClientParams. For instance httpClient.soTimeout=5000 will set the SO_TIMEOUT to 5 seconds.
clientConnectionManagernullSpecifies a reference to a custom org.apache.http.conn.ClientConnectionManager.

Authentication options

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

Table 22. HTTP authentication options

NameDescription
authMethod

Specifies the authentication method to use. Supported methods are:

  • Basic

  • Digest

  • NTLM

authMethodPrioritySpecifies the priority of the authentication methods using a comma seperated list.
authUsernameSpecifies the username for authentication.
authPasswordSpecifies the password for authentication.
authDomainSpecifies the domain for NTML authentication.
authHostSpecifies an optional host for NTML authentication.
proxyHostSpecifies the proxy host name.
proxyPortSpecifies the proxy port number.
proxyAuthMethod

Specifies the authentication method to use for connecting to the proxy. Supported methods are:

  • Basic

  • Digest

  • NTLM

proxyAuthUsernameSpecifies the username for proxy authentication.
proxyAuthPasswordSpecifies the password for proxy authentication.
proxyAuthDomainSpecifies the domain for proxy NTML authentication.
proxyAuthHostSpecifies the optional host for proxy NTML authentication.

When using authentication you must provide a value for either the authMethod or authProxyMethod options.

Message headers

The following Exchange properties are recognized by HTTP endpoints:

Table 23. 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.
Content-EncodingStringSpecifies the HTTP content encoding. This header is populated on both the IN and OUT message to provide a content encoding.
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. 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

HTTP4
Jetty
HttpClientParams