LibraryToggle FramesPrintFeedback

Available as of Camel 2.3

The http4: component provides HTTP based endpoints for consuming external HTTP resources (as a client to call external servers using HTTP).

Maven users will need to add the following dependency 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>
[Important]camel-http4 vs camel-http

Camel-http4 uses HttpClient 4.x while camel-http uses HttpClient 3.x.

http4:hostname[:port][/resourceUri][?options]

Will by default use port 80 for HTTP and 443 for HTTPS.

You can append query options to the URI in the following format, ?option=value&option=value&...

[Important]camel-http4 vs camel-jetty

You can only produce to endpoints generated by the HTTP4 component. Therefore it should never be used as input into your camel Routes. To bind/expose an HTTP endpoint via a HTTP server as input to a camel route, you can use the Jetty Component

Name Default Value Description
x509HostnameVerifier BrowserCompatHostnameVerifier Camel 2.7: You can refer to a different org.apache.http.conn.ssl.X509HostnameVerifier instance in the Registry such as org.apache.http.conn.ssl.StrictHostnameVerifier or org.apache.http.conn.ssl.AllowAllHostnameVerifier.
throwExceptionOnFailure true Option 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 If the option is true , HttpProducer will ignore the Exchange.HTTP_URI header, and use the endpoint's URI for request. You may also set the throwExcpetionOnFailure to be false to let the HttpProducer send all the fault response back. If the option is true, HttpProducer and CamelServlet will skip the gzip processing if the content-encoding is "gzip".
disableStreamCache false DefaultHttpBinding will copy the request input stream into a stream cache and put it into message body if this option is false to support read it twice, otherwise DefaultHttpBinding will set the request input stream direct into the message body.
httpBindingRef null Reference to a org.apache.camel.component.http.HttpBinding in the Registry. Prefer to use the httpBinding option.
httpBinding null Reference to a org.apache.camel.component.http.HttpBinding in the Registry.
httpClientConfigurerRef null Reference to a org.apache.camel.component.http.HttpClientConfigurer in the Registry. Prefer to use the httpClientConfigurer option.
httpClientConfigurer null Reference to a org.apache.camel.component.http.HttpClientConfigurer in the Registry.
httpClient.XXX null Setting options on the BasicHttpParams. For instance httpClient.soTimeout=5000 will set the SO_TIMEOUT to 5 seconds. Look on the setter methods of the following parameter beans for a complete reference: AuthParamBean, ClientParamBean, ConnConnectionParamBean, ConnRouteParamBean, CookieSpecParamBean, HttpConnectionParamBean and HttpProtocolParamBean
clientConnectionManager null To use a custom org.apache.http.conn.ClientConnectionManager.
transferException false If enabled and an Exchange failed processing on the consumer side, and if the caused Exception was send back serialized in the response as a application/x-java-serialized-object content type (for example using Jetty or Servlet Camel components). On the producer side the exception will be deserialized and thrown as is, instead of the HttpOperationFailedException. The caused exception is required to be serialized.
maxTotalConnections 200 The maximum number of connections.
connectionsPerRoute 20 The maximum number of connections per route.
sslContextParametersRef null Camel 2.8: Reference to a org.apache.camel.util.jsse.SSLContextParameters in the Registry. This reference overrides any configured SSLContextParameters at the component level. See Using the JSSE Configuration Utility.

The following authentication options can also be set on the HttpEndpoint:

Since Fuse Mediation Router 2.8.0, the basic authentication and proxy options are as follows:

Name Default Value Description
authUsername null Username for authentication.
authPassword null Password for authentication.
authDomain null The domain name for authentication.
authHost null The host name authentication.
proxyAuthHost null The proxy host name.
proxyAuthPort null The proxy port number.
proxyAuthScheme null The proxy scheme, will fallback and use the scheme from the endpoint if not configured.
proxyAuthUsername null Username for proxy authentication.
proxyAuthPassword null Password for proxy authentication.
proxyAuthDomain null The proxy domain name.
proxyAuthNtHost null The proxy Nt host name.
Name Default Value Description
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 Camel 2.7: To use a custom org.apache.http.conn.ssl.X509HostnameVerifier
sslContextParameters null Camel 2.8: To configure a custom SSL/TLS configuration options at the component level. See Using the JSSE Configuration Utility for more details.
Name Type Description
Exchange.HTTP_URI String URI to call. Will override existing URI set directly on the endpoint.
Exchange.HTTP_PATH String Request URI's path, the header will be used to build the request URI with the HTTP_URI.
Exchange.HTTP_QUERY String URI parameters. Will override existing URI parameters set directly on the endpoint.
Exchange.HTTP_RESPONSE_CODE int The HTTP response code from the external server. Is 200 for OK.
Exchange.HTTP_CHARACTER_ENCODING String Character encoding.
Exchange.CONTENT_TYPE String The HTTP content type. Is set on both the IN and OUT message to provide a content type, such as text/html.
Exchange.CONTENT_ENCODING String The HTTP content encoding. Is set on both the IN and OUT message to provide a content encoding, such as gzip.

As of Camel 2.8, the HTTP4 component supports SSL/TLS configuration through the Camel JSSE Configuration Utility. This utility greatly decreases the amount of component specific code you need to write and is configurable at the endpoint and component levels. The following examples demonstrate how to use the utility with the HTTP4 component.

Basically camel-http4 component is built on the top of Apache HTTP client. Please refer to SSL/TLS customization for details or have a look into the org.apache.camel.component.http4.HttpsServerTestSupport unit test base class. You can also implement a custom org.apache.camel.component.http4.HttpClientConfigurer to do some configuration on the http client if you need full control of it.

However if you just want to specify the keystore and truststore you can do this with Apache HTTP HttpClientConfigurer, for example:

KeyStore keystore = ...;
KeyStore truststore = ...;

SchemeRegistry registry = new SchemeRegistry();
registry.register(new Scheme("https", 443, new SSLSocketFactory(keystore, "mypassword", truststore)));

And then you need to create a class that implements HttpClientConfigurer, and registers https protocol providing a keystore or truststore per example above. Then, from your camel route builder class you can hook it up like so:

HttpComponent httpComponent = getContext().getComponent("http4", HttpComponent.class);
httpComponent.setHttpClientConfigurer(new MyHttpClientConfigurer());

If you are doing this using the Spring DSL, you can specify your HttpClientConfigurer using the URI. For example:

<bean id="myHttpClientConfigurer"
 class="my.https.HttpClientConfigurer">
</bean>

<to uri="https4://myhostname.com:443/myURL?httpClientConfigurer=myHttpClientConfigurer"/>

As long as you implement the HttpClientConfigurer and configure your keystore and truststore as described above, it will work fine.

Comments powered by Disqus