LibraryToggle FramesPrintFeedback

Available as of Camel 2.8

The ahc: component provides HTTP based endpoints for consuming external HTTP resources (as a client to call external servers using HTTP). The component uses the Async Http Client library.

Maven users will need to add the following dependency to their pom.xml for this component:

<dependency>
    <groupId>org.apache.camel</groupId>
    <artifactId>camel-ahc</artifactId>
    <version>x.x.x</version>
    <!-- use the same version as your Camel core version -->
</dependency>
Name Default Value Description
throwExceptionOnFailure true Option to disable throwing the AhcOperationFailedException 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, then the Exchange.HTTP_URI header is ignored, and use the endpoint's URI for request. You may also set the throwExcpetionOnFailure to be false to let the AhcProducer send all the fault response back.
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 AhcOperationFailedException. The caused exception is required to be serialized.
client null To use a custom com.ning.http.client.AsyncHttpClient.
clientConfig null To configure the AsyncHttpClients use a custom com.ning.http.client.AsyncHttpClientConfig.
binding null To use a custom org.apache.camel.component.ahc.AhcBinding.
sslContextParameters null Camel 2.9: Reference to a org.apache.camel.util.jsse.SSLContextParameters in the CAMEL:Registry. This reference overrides any configured SSLContextParameters at the component level. See Using the JSSE Configuration Utility. Note that configuring this option will override any SSL/TLS configuration options provided through the clientConfig option at the endpoint or component level.

Name Default Value Description
client null To use a custom com.ning.http.client.AsyncHttpClient.
clientConfig null To configure the AsyncHttpClients use a custom com.ning.http.client.AsyncHttpClientConfig.
binding null To use a custom org.apache.camel.component.ahc.AhcBinding.
sslContextParameters null Camel 2.9: To configure custom SSL/TLS configuration options at the component level. See Using the JSSE Configuration Utility for more details. Note that configuring this option will override any SSL/TLS configuration options provided through the clientConfig option at the endpoint or component level.

Notice that setting any of the options on the AhcComponent will propagate those options to AhcEndpoints being created. However the AhcEndpoint can also configure/override a custom option. Options set on endpoints will always take precedence over options from the AhcComponent.

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. If the path is start with "/", http producer will try to find the relative path based on the Exchange.HTTP_BASE_URI header or the exchange.getFromEndpoint().getEndpointUri();
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.

The AsyncHttpClient client uses a AsyncHttpClientConfig to configure the client. See the documentation at Async Http Client for more details.

The example below shows how to use a builder to create the AsyncHttpClientConfig which we configure on the AhcComponent.

// create a client config builder
AsyncHttpClientConfig.Builder builder = new AsyncHttpClientConfig.Builder();
// use the builder to set the options we want, in this case we want to follow redirects and try
// at most 3 retries to send a request to the host
AsyncHttpClientConfig config = builder.setFollowRedirects(true).setMaxRequestRetry(3).build();

// lookup AhcComponent
AhcComponent component = context.getComponent("ahc", AhcComponent.class);
// and set our custom client config to be used
component.setClientConfig(config);

The AsyncHttpClientConfig doesn't support getters/setters so its not easy to create/configure using a Spring bean style (eg the <bean> tag in the XML file).

As of Camel 2.9, the AHC 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 AHC component.

Comments powered by Disqus