Author: buildbot
Date: Fri Aug 25 10:20:13 2017
New Revision: 1017269
Log:
Production update by buildbot for camel
Modified:
websites/production/camel/content/activemq.html
websites/production/camel/content/ahc.html
websites/production/camel/content/atom.html
websites/production/camel/content/bean.html
websites/production/camel/content/book-in-one-page.html
websites/production/camel/content/cache/main.pageCache
websites/production/camel/content/cxf-bean-component.html
websites/production/camel/content/dead-letter-channel.html
websites/production/camel/content/file2.html
websites/production/camel/content/freemarker.html
websites/production/camel/content/ibatis.html
websites/production/camel/content/jdbc.html
websites/production/camel/content/jetty.html
websites/production/camel/content/jms.html
websites/production/camel/content/jmx.html
websites/production/camel/content/jpa.html
websites/production/camel/content/mail.html
websites/production/camel/content/seda.html
websites/production/camel/content/spring.html
websites/production/camel/content/stream.html
Modified: websites/production/camel/content/activemq.html
==============================================================================
--- websites/production/camel/content/activemq.html (original)
+++ websites/production/camel/content/activemq.html Fri Aug 25 10:20:13 2017
@@ -36,16 +36,6 @@
<![endif]-->
- <link href='//camel.apache.org/styles/highlighter/styles/shCoreCamel.css'
rel='stylesheet' type='text/css' />
- <link href='//camel.apache.org/styles/highlighter/styles/shThemeCamel.css'
rel='stylesheet' type='text/css' />
- <script src='//camel.apache.org/styles/highlighter/scripts/shCore.js'
type='text/javascript'></script>
- <script src='//camel.apache.org/styles/highlighter/scripts/shBrushJava.js'
type='text/javascript'></script>
- <script src='//camel.apache.org/styles/highlighter/scripts/shBrushXml.js'
type='text/javascript'></script>
-
- <script type="text/javascript">
- SyntaxHighlighter.defaults['toolbar'] = false;
- SyntaxHighlighter.all();
- </script>
<title>
Apache Camel: ActiveMQ
@@ -85,95 +75,70 @@
<tbody>
<tr>
<td valign="top" width="100%">
-<div class="wiki-content maincontent"><h2
id="ActiveMQ-ActiveMQComponent">ActiveMQ Component</h2><p>The ActiveMQ
component allows messages to be sent to a <a shape="rect" class="external-link"
href="http://java.sun.com/products/jms/" rel="nofollow">JMS</a> Queue or Topic
or messages to be consumed from a JMS Queue or Topic using <a shape="rect"
class="external-link" href="http://activemq.apache.org/" title="The most
popular and powerful open source message broker">Apache ActiveMQ</a>. This
component is based on <a shape="rect" href="jms.html">JMS Component</a> and
uses Spring's JMS support for declarative transactions, using Spring's
<strong><code>JmsTemplate</code></strong> for sending and a
<strong><code>MessageListenerContainer</code></strong> for consuming. All the
options from the <a shape="rect" href="jms.html">JMS</a> component also applies
for this component.</p><p>To use this component make sure you have the
<strong><code>activemq.jar</code></strong> or <strong><code>active
mq-core.jar</code></strong> on your classpath along with any Camel
dependencies such as <strong><code>camel-core.jar</code></strong>,
<strong><code>camel-spring.jar</code></strong> and
<strong><code>camel-jms.jar</code></strong>.</p><div
class="confluence-information-macro confluence-information-macro-tip"><p
class="title">Transacted and caching</p><span class="aui-icon aui-icon-small
aui-iconfont-approve confluence-information-macro-icon"></span><div
class="confluence-information-macro-body"><p>See section <em>Transactions and
Cache Levels</em> below on <a shape="rect" href="jms.html">JMS</a> page if you
are using transactions with <a shape="rect" href="jms.html">JMS</a> as it can
impact performance.</p></div></div><h3 id="ActiveMQ-URIformat">URI
format</h3><div class="code panel pdl" style="border-width: 1px;"><div
class="codeContent panelContent pdl">
-<script class="brush: java; gutter: false; theme: Default"
type="syntaxhighlighter"><![CDATA[activemq:[queue:|topic:]destinationName
-]]></script>
-</div></div><p>Where <strong><code>destinationName</code></strong> is an
ActiveMQ queue or topic name. By default,
the <strong><code>destinationName</code></strong> is interpreted as a
queue name. For example, to connect to the queue,
<strong><code>FOO.BAR</code></strong>, use:</p><div class="code panel pdl"
style="border-width: 1px;"><div class="codeContent panelContent pdl">
-<script class="brush: java; gutter: false; theme: Default"
type="syntaxhighlighter"><![CDATA[activemq:FOO.BAR
-]]></script>
-</div></div><p>You can include the optional
<strong><code>queue:</code></strong> prefix, if you prefer:</p><div class="code
panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
-<script class="brush: java; gutter: false; theme: Default"
type="syntaxhighlighter"><![CDATA[activemq:queue:FOO.BAR
-]]></script>
-</div></div><p>To connect to a topic, you must include the
<strong><code>topic:</code></strong> prefix. For example, to connect to the
topic, <strong><code>Stocks.Prices</code></strong>, use:</p><div class="code
panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
-<script class="brush: java; gutter: false; theme: Default"
type="syntaxhighlighter"><![CDATA[activemq:topic:Stocks.Prices
-]]></script>
-</div></div><h3 id="ActiveMQ-Options">Options</h3><p>See Options on the <a
shape="rect" href="jms.html">JMS</a> component as all these options also apply
for this component.</p><h3
id="ActiveMQ-ConfiguringtheConnectionFactory">Configuring the Connection
Factory</h3><p>This <a shape="rect" class="external-link"
href="http://svn.apache.org/repos/asf/activemq/trunk/activemq-camel/src/test/java/org/apache/activemq/camel/component/ActiveMQRouteTest.java">test
case</a> shows how to add
an <strong><code>ActiveMQComponent</code></strong> to the <a shape="rect"
href="camelcontext.html">CamelContext</a> using the <a shape="rect"
class="external-link"
href="http://activemq.apache.org/maven/5.5.0/activemq-camel/apidocs/org/apache/activemq/camel/component/ActiveMQComponent.html#activeMQComponent%28java.lang.String%29"><code>activeMQComponent()</code>
method</a> while specifying the <a shape="rect" class="external-link"
href="http://activemq.apache.org/configuring-transports.html">brokerURL<
/a> used to connect to ActiveMQ.</p><div class="code panel pdl"
style="border-width: 1px;"><div class="codeContent panelContent pdl">
-<script class="brush: java; gutter: false; theme: Default"
type="syntaxhighlighter"><![CDATA[camelContext.addComponent("activemq",
activeMQComponent("vm://localhost?broker.persistent=false"));
-]]></script>
-</div></div><h3
id="ActiveMQ-ConfiguringtheConnectionFactoryusingSpringXML">Configuring the
Connection Factory using Spring XML</h3><p>You can configure the ActiveMQ
broker URL on the <strong><code>ActiveMQComponent</code></strong> as
follows</p><div class="code panel pdl" style="border-width: 1px;"><div
class="codeContent panelContent pdl">
-<script class="brush: xml; gutter: false; theme: Default"
type="syntaxhighlighter"><![CDATA[<beans
xmlns="http://www.springframework.org/schema/beans"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://www.springframework.org/schema/beans
+<div class="wiki-content maincontent"><h2
id="ActiveMQ-ActiveMQComponent">ActiveMQ Component</h2><p>The ActiveMQ
component allows messages to be sent to a <a shape="rect" class="external-link"
href="http://java.sun.com/products/jms/" rel="nofollow">JMS</a> Queue or Topic
or messages to be consumed from a JMS Queue or Topic using <a shape="rect"
class="external-link" href="http://activemq.apache.org/" title="The most
popular and powerful open source message broker">Apache ActiveMQ</a>. This
component is based on <a shape="rect" href="jms.html">JMS Component</a> and
uses Spring's JMS support for declarative transactions, using Spring's
<strong><code>JmsTemplate</code></strong> for sending and a
<strong><code>MessageListenerContainer</code></strong> for consuming. All the
options from the <a shape="rect" href="jms.html">JMS</a> component also applies
for this component.</p><p>To use this component make sure you have the
<strong><code>activemq.jar</code></strong> or <strong><code>active
mq-core.jar</code></strong> on your classpath along with any Camel
dependencies such as <strong><code>camel-core.jar</code></strong>,
<strong><code>camel-spring.jar</code></strong> and
<strong><code>camel-jms.jar</code></strong>.</p><parameter
ac:name="title">Transacted and caching</parameter><rich-text-body><p>See
section <em>Transactions and Cache Levels</em> below on <a shape="rect"
href="jms.html">JMS</a> page if you are using transactions with <a shape="rect"
href="jms.html">JMS</a> as it can impact performance.</p></rich-text-body><h3
id="ActiveMQ-URIformat">URI
format</h3><plain-text-body>activemq:[queue:|topic:]destinationName
+</plain-text-body><p>Where <strong><code>destinationName</code></strong>
is an ActiveMQ queue or topic name. By default,
the <strong><code>destinationName</code></strong> is interpreted as a
queue name. For example, to connect to the queue,
<strong><code>FOO.BAR</code></strong>, use:</p><plain-text-body>activemq:FOO.BAR
+</plain-text-body><p>You can include the optional
<strong><code>queue:</code></strong> prefix, if you
prefer:</p><plain-text-body>activemq:queue:FOO.BAR
+</plain-text-body><p>To connect to a topic, you must include the
<strong><code>topic:</code></strong> prefix. For example, to connect to the
topic, <strong><code>Stocks.Prices</code></strong>,
use:</p><plain-text-body>activemq:topic:Stocks.Prices
+</plain-text-body><h3 id="ActiveMQ-Options">Options</h3><p>See Options on the
<a shape="rect" href="jms.html">JMS</a> component as all these options also
apply for this component.</p><h3
id="ActiveMQ-ConfiguringtheConnectionFactory">Configuring the Connection
Factory</h3><p>This <a shape="rect" class="external-link"
href="http://svn.apache.org/repos/asf/activemq/trunk/activemq-camel/src/test/java/org/apache/activemq/camel/component/ActiveMQRouteTest.java">test
case</a> shows how to add
an <strong><code>ActiveMQComponent</code></strong> to the <a shape="rect"
href="camelcontext.html">CamelContext</a> using the <a shape="rect"
class="external-link"
href="http://activemq.apache.org/maven/5.5.0/activemq-camel/apidocs/org/apache/activemq/camel/component/ActiveMQComponent.html#activeMQComponent%28java.lang.String%29"><code>activeMQComponent()</code>
method</a> while specifying the <a shape="rect" class="external-link"
href="http://activemq.apache.org/configuring-transports.html">brok
erURL</a> used to connect to
ActiveMQ.</p><plain-text-body>camelContext.addComponent("activemq",
activeMQComponent("vm://localhost?broker.persistent=false"));
+</plain-text-body><h3
id="ActiveMQ-ConfiguringtheConnectionFactoryusingSpringXML">Configuring the
Connection Factory using Spring XML</h3><p>You can configure the ActiveMQ
broker URL on the <strong><code>ActiveMQComponent</code></strong> as
follows</p><parameter ac:name="">xml</parameter><plain-text-body><beans
xmlns="http://www.springframework.org/schema/beans"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
http://camel.apache.org/schema/spring
-
http://camel.apache.org/schema/spring/camel-spring.xsd">
+
http://camel.apache.org/schema/spring/camel-spring.xsd">
- <camelContext xmlns="http://camel.apache.org/schema/spring">
+ <camelContext xmlns="http://camel.apache.org/schema/spring">
</camelContext>
- <bean id="activemq"
class="org.apache.activemq.camel.component.ActiveMQComponent">
- <property name="brokerURL"
value="tcp://somehost:61616"/>
+ <bean id="activemq"
class="org.apache.activemq.camel.component.ActiveMQComponent">
+ <property name="brokerURL" value="tcp://somehost:61616"/>
</bean>
</beans>
-]]></script>
-</div></div><h3 id="ActiveMQ-UsingConnectionPooling">Using Connection
Pooling</h3><p>When sending to an ActiveMQ broker using Camel it's recommended
to use a pooled connection factory to efficiently handle pooling of JMS
connections, sessions and producers. This is documented on the <a shape="rect"
class="external-link"
href="http://activemq.apache.org/spring-support.html">ActiveMQ Spring Support
</a> page.</p><p>You can grab ActiveMQ's
<strong><code>org.apache.activemq.pool.PooledConnectionFactory</code></strong>
with Maven:</p><div class="code panel pdl" style="border-width: 1px;"><div
class="codeContent panelContent pdl">
-<script class="brush: xml; gutter: false; theme: Default"
type="syntaxhighlighter"><![CDATA[<dependency>
+</plain-text-body><h3 id="ActiveMQ-UsingConnectionPooling">Using Connection
Pooling</h3><p>When sending to an ActiveMQ broker using Camel it's recommended
to use a pooled connection factory to efficiently handle pooling of JMS
connections, sessions and producers. This is documented on the <a shape="rect"
class="external-link"
href="http://activemq.apache.org/spring-support.html">ActiveMQ Spring Support
</a> page.</p><p>You can grab ActiveMQ's
<strong><code>org.apache.activemq.pool.PooledConnectionFactory</code></strong>
with Maven:</p><parameter
ac:name="">xml</parameter><plain-text-body><dependency>
<groupId>org.apache.activemq</groupId>
<artifactId>activemq-pool</artifactId>
<version>5.6.0</version>
</dependency>
-]]></script>
-</div></div><p>And then setup the <strong><code>activemq</code></strong>
Camel component as follows:</p><div class="code panel pdl" style="border-width:
1px;"><div class="codeContent panelContent pdl">
-<script class="brush: xml; gutter: false; theme: Default"
type="syntaxhighlighter"><![CDATA[<bean id="jmsConnectionFactory"
class="org.apache.activemq.ActiveMQConnectionFactory">
- <property name="brokerURL"
value="tcp://localhost:61616"/>
+</plain-text-body><p>And then setup
the <strong><code>activemq</code></strong> Camel component as
follows:</p><parameter ac:name="">xml</parameter><plain-text-body><bean
id="jmsConnectionFactory"
class="org.apache.activemq.ActiveMQConnectionFactory">
+ <property name="brokerURL" value="tcp://localhost:61616"/>
</bean>
-<bean id="pooledConnectionFactory"
class="org.apache.activemq.pool.PooledConnectionFactory"
init-method="start" destroy-method="stop">
- <property name="maxConnections" value="8"/>
- <property name="connectionFactory"
ref="jmsConnectionFactory"/>
+<bean id="pooledConnectionFactory"
class="org.apache.activemq.pool.PooledConnectionFactory" init-method="start"
destroy-method="stop">
+ <property name="maxConnections" value="8"/>
+ <property name="connectionFactory" ref="jmsConnectionFactory"/>
</bean>
-<bean id="jmsConfig"
class="org.apache.camel.component.jms.JmsConfiguration">
- <property name="connectionFactory"
ref="pooledConnectionFactory"/>
- <property name="concurrentConsumers" value="10"/>
+<bean id="jmsConfig"
class="org.apache.camel.component.jms.JmsConfiguration">
+ <property name="connectionFactory" ref="pooledConnectionFactory"/>
+ <property name="concurrentConsumers" value="10"/>
</bean>
-<bean id="activemq"
class="org.apache.activemq.camel.component.ActiveMQComponent">
- <property name="configuration" ref="jmsConfig"/>
+<bean id="activemq"
class="org.apache.activemq.camel.component.ActiveMQComponent">
+ <property name="configuration" ref="jmsConfig"/>
<!-- If transacted=true then enable CACHE_CONSUMER (if not using XA) to
run faster.
See more details at: http://camel.apache.org/jms -->
<!--
- Â <property name="transacted" value="true"/>
- <property name="cacheLevelName"
value="CACHE_CONSUMER"/>
+  <property name="transacted" value="true"/>
+ <property name="cacheLevelName" value="CACHE_CONSUMER"/>
-->
</bean>
-]]></script>
-</div></div><div class="confluence-information-macro
confluence-information-macro-note"><span class="aui-icon aui-icon-small
aui-iconfont-warning confluence-information-macro-icon"></span><div
class="confluence-information-macro-body"><p>Notice
the <strong><code>init</code></strong>
and <strong><code>destroy</code></strong> methods on the pooled connection
factory. This is important to ensure the connection pool is properly started
and shutdown.</p></div></div><div class="confluence-information-macro
confluence-information-macro-information"><p class="title">Important
information about when using transactions</p><span class="aui-icon
aui-icon-small aui-iconfont-info confluence-information-macro-icon"></span><div
class="confluence-information-macro-body"><p>If you are using transactions then
see more details at <a shape="rect" href="jms.html">JMS</a>. And remember to
set <strong><code>cacheLevelName</code></strong> to
<strong><code>CACHE_CONSUMER</code></strong> if you are
not using XA transactions. This can dramatically improve
performance.</p></div></div><p>The
<strong><code>PooledConnectionFactory</code></strong> will then create a
connection pool with up to 8 connections in use at the same time. Each
connection can be shared by many sessions. There is an option named
<strong><code>maximumActive</code></strong> you can use to configure the
maximum number of sessions per connection; the default value is
<strong><code>500</code></strong>. From <strong>ActiveMQ 5.7</strong>: the
option has been renamed to better reflect its purpose, being named as
<strong><code>maximumActiveSessionPerConnection</code></strong>. Notice the
<strong><code>concurrentConsumers</code></strong> is set to a higher value than
<strong><code>maxConnections</code></strong> is. This is okay, as each consumer
is using a session, and as a session can share the same connection, we are in
the safe. In this example we can have <strong><code>8 * 500 =
4000</code></strong> active se
ssions at the same time.</p><h3
id="ActiveMQ-InvokingMessageListenerPOJOsinaCamelroute">Invoking
MessageListener POJOs in a Camel route</h3><p>The ActiveMQ component also
provides a helper <a shape="rect" href="type-converter.html">Type Converter</a>
from a JMS <strong><code>MessageListener</code></strong> to a <a
shape="rect" href="processor.html">Processor</a>. This means that the <a
shape="rect" href="bean.html">Bean</a> component is capable of invoking any
JMS <strong><code>MessageListener</code></strong> bean directly inside any
route.</p><p>So for example you can create
a <strong><code>MessageListener</code></strong> in JMS like this:</p><div
class="code panel pdl" style="border-width: 1px;"><div class="codeContent
panelContent pdl">
-<script class="brush: java; gutter: false; theme: Default"
type="syntaxhighlighter"><![CDATA[public class MyListener implements
MessageListener {
+</plain-text-body><rich-text-body><p>Notice
the <strong><code>init</code></strong>
and <strong><code>destroy</code></strong> methods on the pooled connection
factory. This is important to ensure the connection pool is properly started
and shutdown.</p></rich-text-body><parameter ac:name="title">Important
information about when using transactions</parameter><rich-text-body><p>If you
are using transactions then see more details at <a shape="rect"
href="jms.html">JMS</a>. And remember to set
<strong><code>cacheLevelName</code></strong> to
<strong><code>CACHE_CONSUMER</code></strong> if you are not using XA
transactions. This can dramatically improve
performance.</p></rich-text-body><p>The
<strong><code>PooledConnectionFactory</code></strong> will then create a
connection pool with up to 8 connections in use at the same time. Each
connection can be shared by many sessions. There is an option named
<strong><code>maximumActive</code></strong> you can use to configure the maximum
number of sessions per connection; the default value is
<strong><code>500</code></strong>. From <strong>ActiveMQ 5.7</strong>: the
option has been renamed to better reflect its purpose, being named as
<strong><code>maximumActiveSessionPerConnection</code></strong>. Notice the
<strong><code>concurrentConsumers</code></strong> is set to a higher value than
<strong><code>maxConnections</code></strong> is. This is okay, as each consumer
is using a session, and as a session can share the same connection, we are in
the safe. In this example we can have <strong><code>8 * 500 =
4000</code></strong> active sessions at the same time.</p><h3
id="ActiveMQ-InvokingMessageListenerPOJOsinaCamelroute">Invoking
MessageListener POJOs in a Camel route</h3><p>The ActiveMQ component also
provides a helper <a shape="rect" href="type-converter.html">Type Converter</a>
from a JMS <strong><code>MessageListener</code></strong> to a <a
shape="rect" href="processor.html">Processor</a>. This means th
at the <a shape="rect" href="bean.html">Bean</a> component is capable of
invoking any JMS <strong><code>MessageListener</code></strong> bean
directly inside any route.</p><p>So for example you can create
a <strong><code>MessageListener</code></strong> in JMS like
this:</p><plain-text-body>public class MyListener implements MessageListener {
public void onMessage(Message jmsMessage) {
// ...
}
}
-]]></script>
-</div></div><p>Then use it in your Camel route as follows</p><div class="code
panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
-<script class="brush: java; gutter: false; theme: Default"
type="syntaxhighlighter"><![CDATA[from("file://foo/bar")
+</plain-text-body><p>Then use it in your Camel route as
follows</p><plain-text-body>from("file://foo/bar")
.bean(MyListener.class);
-]]></script>
-</div></div><p>That is, you can reuse any of the Camel <a shape="rect"
href="components.html">Components</a> and easily integrate them into your
JMS <strong><code>MessageListener</code></strong> POJO!</p><h3
id="ActiveMQ-UsingActiveMQDestinationOptions">Using ActiveMQ Destination
Options</h3><p><strong>Available as of ActiveMQ 5.6</strong></p><p>You can
configure the <a shape="rect" class="external-link"
href="http://activemq.apache.org/destination-options.html">Destination
Options</a> in the endpoint URI, using
the <strong><code>destination.</code></strong> prefix. For example to mark
a consumer as exclusive, and set its prefetch size to
<strong><code>50</code></strong>, you can do as follows:</p><p> </p><div
class="code panel pdl" style="border-width: 1px;"><div class="codeContent
panelContent pdl">
-<script class="brush: java; gutter: false; theme: Default"
type="syntaxhighlighter"><![CDATA[<from
uri="activemq:foo?destination.consumer.exclusive=true&amp;destination.consumer.prefetchSize=50"/>]]></script>
-</div></div><h3 id="ActiveMQ-ConsumingAdvisoryMessages">Consuming Advisory
Messages</h3><p>ActiveMQ can generate <a shape="rect" class="external-link"
href="http://activemq.apache.org/advisory-message.html">Advisory messages </a>
which are put in topics that you can consume. Such messages can help you send
alerts in case you detect slow consumers or to build statistics (number of
messages/produced per day, etc.) The following Spring DSL example shows you how
to read messages from a topic.</p><p>The below route starts by reading the
topic <em>ActiveMQ.Advisory.Connection</em>. To watch another topic, simply
change the name according to the name provided in ActiveMQ Advisory Messages
documentation. The
parameter <strong><code>mapJmsMessage=false</code></strong> allows for
converting
the <strong><code>org.apache.activemq.command.ActiveMqMessage</code></strong>
object from the JMS queue. Next, the body received is converted into a String
for the purposes of this example and a
carriage return is added. Finally, the string is added to a file</p><div
class="code panel pdl" style="border-width: 1px;"><div class="codeContent
panelContent pdl">
-<script class="brush: java; gutter: false; theme: Default"
type="syntaxhighlighter"><![CDATA[<route>
- <from
uri="activemq:topic:ActiveMQ.Advisory.Connection?mapJmsMessage=false"/>
- <convertBodyTo type="java.lang.String"/>
+</plain-text-body><p>That is, you can reuse any of the Camel <a shape="rect"
href="components.html">Components</a> and easily integrate them into your
JMS <strong><code>MessageListener</code></strong> POJO!</p><h3
id="ActiveMQ-UsingActiveMQDestinationOptions">Using ActiveMQ Destination
Options</h3><p><strong>Available as of ActiveMQ 5.6</strong></p><p>You can
configure the <a shape="rect" class="external-link"
href="http://activemq.apache.org/destination-options.html">Destination
Options</a> in the endpoint URI, using
the <strong><code>destination.</code></strong> prefix. For example to mark
a consumer as exclusive, and set its prefetch size to
<strong><code>50</code></strong>, you can do as
follows:</p><p> </p><plain-text-body><from
uri="activemq:foo?destination.consumer.exclusive=true&amp;destination.consumer.prefetchSize=50"/></plain-text-body><h3
id="ActiveMQ-ConsumingAdvisoryMessages">Consuming Advisory
Messages</h3><p>ActiveMQ can generate <a shape="re
ct" class="external-link"
href="http://activemq.apache.org/advisory-message.html">Advisory messages </a>
which are put in topics that you can consume. Such messages can help you send
alerts in case you detect slow consumers or to build statistics (number of
messages/produced per day, etc.) The following Spring DSL example shows you how
to read messages from a topic.</p><p>The below route starts by reading the
topic <em>ActiveMQ.Advisory.Connection</em>. To watch another topic, simply
change the name according to the name provided in ActiveMQ Advisory Messages
documentation. The
parameter <strong><code>mapJmsMessage=false</code></strong> allows for
converting
the <strong><code>org.apache.activemq.command.ActiveMqMessage</code></strong>
object from the JMS queue. Next, the body received is converted into a String
for the purposes of this example and a carriage return is added. Finally, the
string is added to a file</p><plain-text-body><route>
+ <from
uri="activemq:topic:ActiveMQ.Advisory.Connection?mapJmsMessage=false"/>
+ <convertBodyTo type="java.lang.String"/>
<transform>
<simple>${in.body}&#13;</simple>
</transform>
- <to
uri="file://data/activemq/?fileExist=Append&amp;fileName=advisoryConnection-${date:now:yyyyMMdd}.txt"/>
+ <to
uri="file://data/activemq/?fileExist=Append&amp;fileName=advisoryConnection-${date:now:yyyyMMdd}.txt"/>
</route>
-]]></script>
-</div></div><p>If you consume a message on a queue, you should see the
following files under the <strong><code>data/activemq</code></strong>
folder :</p><p><strong><code>advisoryConnection-20100312.txt</code></strong><br
clear="none"><strong><code>advisoryProducer-20100312.txt</code></strong></p><p>containing
the following string:</p><div class="code panel pdl" style="border-width:
1px;"><div class="codeContent panelContent pdl">
-<script class="brush: java; gutter: false; theme: Default"
type="syntaxhighlighter"><![CDATA[ActiveMQMessage {
+</plain-text-body><p>If you consume a message on a queue, you should see the
following files under the <strong><code>data/activemq</code></strong>
folder :</p><p><strong><code>advisoryConnection-20100312.txt</code></strong><br
clear="none"><strong><code>advisoryProducer-20100312.txt</code></strong></p><p>containing
the following string:</p><plain-text-body>ActiveMQMessage {
commandId = 0,
responseRequired = false,
messageId = ID:dell-charles-3258-1268399815140-1:0:0:0:221,
@@ -218,16 +183,12 @@ readOnlyProperties = true,
readOnlyBody = true,
droppable = false
}
-]]></script>
-</div></div><h3 id="ActiveMQ-GettingComponentJAR">Getting Component
JAR</h3><p>You will need this dependency</p><ul
class="alternate"><li><strong><code>activemq-camel</code></strong></li></ul><p><a
shape="rect" href="activemq.html">ActiveMQ</a> is an extension of the <a
shape="rect" href="jms.html">JMS</a> component released with the <a
shape="rect" class="external-link" href="http://activemq.apache.org">ActiveMQ
project</a>.</p><div class="code panel pdl" style="border-width: 1px;"><div
class="codeContent panelContent pdl">
-<script class="brush: java; gutter: false; theme: Default"
type="syntaxhighlighter"><![CDATA[<dependency>
+</plain-text-body><h3 id="ActiveMQ-GettingComponentJAR">Getting Component
JAR</h3><p>You will need this dependency</p><ul
class="alternate"><li><strong><code>activemq-camel</code></strong></li></ul><p><a
shape="rect" href="activemq.html">ActiveMQ</a> is an extension of the <a
shape="rect" href="jms.html">JMS</a> component released with the <a
shape="rect" class="external-link" href="http://activemq.apache.org">ActiveMQ
project</a>.</p><plain-text-body><dependency>
<groupId>org.apache.activemq</groupId>
<artifactId>activemq-camel</artifactId>
<version>5.6.0</version>
</dependency>
-]]></script>
-</div></div><p></p><h3 id="ActiveMQ-SeeAlso">See Also</h3>
-<ul><li><a shape="rect" href="configuring-camel.html">Configuring
Camel</a></li><li><a shape="rect"
href="component.html">Component</a></li><li><a shape="rect"
href="endpoint.html">Endpoint</a></li><li><a shape="rect"
href="getting-started.html">Getting Started</a></li></ul></div>
+</plain-text-body><p><parameter ac:name=""><a shape="rect"
href="endpoint-see-also.html">Endpoint See Also</a></parameter></p></div>
</td>
<td valign="top">
<div class="navigation">
Modified: websites/production/camel/content/ahc.html
==============================================================================
--- websites/production/camel/content/ahc.html (original)
+++ websites/production/camel/content/ahc.html Fri Aug 25 10:20:13 2017
@@ -36,16 +36,6 @@
<![endif]-->
- <link href='//camel.apache.org/styles/highlighter/styles/shCoreCamel.css'
rel='stylesheet' type='text/css' />
- <link href='//camel.apache.org/styles/highlighter/styles/shThemeCamel.css'
rel='stylesheet' type='text/css' />
- <script src='//camel.apache.org/styles/highlighter/scripts/shCore.js'
type='text/javascript'></script>
- <script src='//camel.apache.org/styles/highlighter/scripts/shBrushJava.js'
type='text/javascript'></script>
- <script src='//camel.apache.org/styles/highlighter/scripts/shBrushXml.js'
type='text/javascript'></script>
-
- <script type="text/javascript">
- SyntaxHighlighter.defaults['toolbar'] = false;
- SyntaxHighlighter.all();
- </script>
<title>
Apache Camel: AHC
@@ -85,137 +75,93 @@
<tbody>
<tr>
<td valign="top" width="100%">
-<div class="wiki-content maincontent"><h2
id="AHC-AsyncHttpClient(AHC)Component">Async Http Client (AHC)
Component</h2><p><strong>Available from Camel
2.8</strong></p><p>The <strong><code>ahc</code></strong> component
provides HTTP based <a shape="rect" href="endpoint.html">endpoints</a> for
consuming external HTTP resources (as a client to call external servers using
HTTP). The component uses the <a shape="rect" class="external-link"
href="https://github.com/AsyncHttpClient/async-http-client"
rel="nofollow">Async Http Client</a> library.</p><p>Maven users will need to
add the following dependency to their <strong><code>pom.xml</code></strong> for
this component:</p><div class="code panel pdl" style="border-width: 1px;"><div
class="codeContent panelContent pdl">
-<script class="brush: xml; gutter: false; theme: Default"
type="syntaxhighlighter"><![CDATA[<dependency>
+<div class="wiki-content maincontent"><h2
id="AHC-AsyncHttpClient(AHC)Component">Async Http Client (AHC)
Component</h2><p><strong>Available from Camel
2.8</strong></p><p>The <strong><code>ahc</code></strong> component
provides HTTP based <a shape="rect" href="endpoint.html">endpoints</a> for
consuming external HTTP resources (as a client to call external servers using
HTTP). The component uses the <a shape="rect" class="external-link"
href="https://github.com/AsyncHttpClient/async-http-client"
rel="nofollow">Async Http Client</a> library.</p><p>Maven users will need to
add the following dependency to their <strong><code>pom.xml</code></strong> for
this component:</p><parameter
ac:name="">xml</parameter><plain-text-body><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>
-]]></script>
-</div></div><h3 id="AHC-URIformat">URI format</h3><div class="code panel pdl"
style="border-width: 1px;"><div class="codeContent panelContent pdl">
-<script class="brush: java; gutter: false; theme: Default"
type="syntaxhighlighter"><![CDATA[ahc:http://hostname[:port][/resourceUri][?options]
+</plain-text-body><h3 id="AHC-URIformat">URI
format</h3><plain-text-body>ahc:http://hostname[:port][/resourceUri][?options]
ahc:https://hostname[:port][/resourceUri][?options]
-]]></script>
-</div></div><p>The default ports are <strong><code>80</code></strong> for
HTTP and <strong><code>443</code></strong> for HTTPS.</p><p>Query options
can be specified on the URI using the following format:
<strong><code>?option=value&option=value&...</code></strong></p><h3
id="AHC-AhcEndpointOptions">AhcEndpoint Options</h3><div
class="confluenceTableSmall"><div class="table-wrap"><table
class="confluenceTable"><tbody><tr><th colspan="1" rowspan="1"
class="confluenceTh"><p>Name</p></th><th colspan="1" rowspan="1"
class="confluenceTh"><p>Default Value</p></th><th colspan="1" rowspan="1"
class="confluenceTh"><p>Description</p></th></tr><tr><td colspan="1"
rowspan="1" class="confluenceTd"><p><code>binding</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p><code>null</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p>To use a custom
<strong><code>org.apache.camel.component.ahc.AhcBinding</code></strong>.</p></td></tr><tr><td
colspan="1" ro
wspan="1" class="confluenceTd"><p><code>bridgeEndpoint</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p><code>false</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p>If the option is
<strong><code>true</code></strong>, then
the <strong><code>Exchange.HTTP_URI</code></strong> header is ignored, and
use the endpoint's URI for request. You may also set the
<strong><code>throwExcpetionOnFailure</code></strong> to be false to let
the <strong><code>AhcProducer</code></strong> send all the fault response
back.</p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>bufferSize</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p><code>4096</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p><strong>Camel 2.10.3:</strong> The initial
in-memory buffer size used when transferring data between Camel and
the <strong><code>ahc</code></strong> Client.</p></td></tr><tr><td
colspan="1" rowspan="1" class
="confluenceTd"><p><code>client</code></p></td><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>null</code></p></td><td colspan="1" rowspan="1"
class="confluenceTd"><p>To use a custom
<strong><code>com.ning.http.client.AsyncHttpClient</code></strong>.</p></td></tr><tr><td
colspan="1" rowspan="1"
class="confluenceTd"><p><code>clientConfig</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p><code>null</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p>To configure the
<strong><code>AsyncHttpClient</code></strong> to use a custom
<strong><code>com.ning.http.client.AsyncHttpClientConfig</code></strong>
instance. This instance replaces any instance configured at the component
level.</p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>clientConfig.x</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p><code>null</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p>To configure additional properties
of the
<strong><code>com.ning.http.client.AsyncHttpClientConfig</code></strong>
instance used by the endpoint.</p><p><strong>Note</strong>: that configuration
options set using this parameter will be merged with those set using the
<strong><code>clientConfig</code></strong> parameter or the instance set at the
component level with properties set using this parameter taking
priority.</p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>clientConfig.realm.x</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p><code>null</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p><strong>Camel 2.11:</strong> To
configure realm properties of the
<strong><code>com.ning.http.client.AsyncHttpClientConfig</code></strong> The
options which can be used are the options from
<strong><code>com.ning.http.client.Realm.RealmBuilder</code></strong>. e.g., to
set the scheme, you should configure
<strong><code>clientConfig.realm.scheme=DIGEST</code></strong><
/p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>connectionClose</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p><code>false</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p><strong><strong>Camel
2.18: </strong></strong>If this option is
<strong><code>true</code></strong>, the producer will add a Connection Close
header to HTTP Request</p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>cookieHandler</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p><code>null</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p><strong>Camel 2.19:</strong> Configure a
cookie handler to maintain a HTTP session</p></td></tr><tr><td colspan="1"
rowspan="1"
class="confluenceTd"><p><code>sslContextParameters</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p><code>null</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p><strong>Camel 2.9:</strong>
Refer
ence to a
<strong><code>org.apache.camel.util.jsse.SSLContextParameters</code></strong>
in the <a shape="rect" href="registry.html">Registry</a>.  This reference
overrides any
configured <strong><code>SSLContextParameters</code></strong> at the
component level. </p><p>See <a shape="rect"
href="#AHC-UsingtheJSSEConfigurationUtility">Using the JSSE Configuration
Utility</a>. </p><p><strong>Note</strong>: configuring this option will
override any SSL/TLS configuration options provided through
the <strong><code>clientConfig</code></strong> option at the endpoint or
component level.</p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>throwExceptionOnFailure</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p><code>true</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p>Option to disable throwing the
<strong><code>AhcOperationFailedException</code></strong> in case of failed
responses from the remote server. Th
is allows you to get all responses regardless of the HTTP status
code.</p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>transferException</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p><code>false</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p>If enabled and an <a shape="rect"
href="exchange.html">Exchange</a> failed processing on the consumer side, and
if the caused <strong><code>Exception</code></strong> was send back serialized
in the response as a
<strong><code>application/x-java-serialized-object</code></strong> content type
(for example using <a shape="rect" href="jetty.html">Jetty</a> or <a
shape="rect" href="servlet.html">SERVLET</a> Camel components). On the producer
side the exception will be deserialized and thrown as is, instead of the
<strong><code>AhcOperationFailedException</code></strong>. The caused exception
is required to be serialized.</p></td></tr></tbody></table></div></div>
-
-
-<h3 id="AHC-AhcComponentOptions">AhcComponent Options</h3><div
class="confluenceTableSmall"><div class="table-wrap"><table
class="confluenceTable"><tbody><tr><th colspan="1" rowspan="1"
class="confluenceTh"><p>Name</p></th><th colspan="1" rowspan="1"
class="confluenceTh"><p>Default Value</p></th><th colspan="1" rowspan="1"
class="confluenceTh"><p>Description</p></th></tr><tr><td colspan="1"
rowspan="1" class="confluenceTd"><p><code>binding</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p><code>null</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p>To use a custom
<strong><code>org.apache.camel.component.ahc.AhcBinding</code></strong>.</p></td></tr><tr><td
colspan="1" rowspan="1"
class="confluenceTd"><p><code>client</code></p></td><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>null</code></p></td><td colspan="1" rowspan="1"
class="confluenceTd"><p>To use a custom
<strong><code>com.ning.http.client.AsyncHttpClient</code>.</strong></p></td>
</tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>clientConfig</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p><code>null</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p>To configure the
<strong><code>AsyncHttpClient</code></strong> to use a custom
<strong><code>com.ning.http.client.AsyncHttpClientConfig</code></strong>.</p></td></tr><tr><td
colspan="1" rowspan="1"
class="confluenceTd"><p><code>sslContextParameters</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p><code>null</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p><strong>Camel 2.9:</strong> To
configure custom SSL/TLS configuration options at the component
level. </p><p>See  <a shape="rect"
href="#AHC-UsingtheJSSEConfigurationUtility">Using the JSSE Configuration
Utility</a> for more details. </p><p><strong>Note</strong>: configuring
this option will override any SSL/TLS configuration options provided through
the <
strong><code>clientConfig</code></strong> option at the endpoint or component
level.</p></td></tr></tbody></table></div></div>
-
-
-<p><strong>Note</strong>: setting any of the options on
the <strong><code>AhcComponent</code></strong> will propagate those
options to the <strong><code>AhcEndpoint</code></strong>(s) being created.
However, the <strong><code>AhcEndpoint</code></strong> can also
configure/override a custom option. Options set on endpoints will always take
precedence over options from the
<strong><code>AhcComponent</code>.</strong></p><h3
id="AHC-MessageHeaders">Message Headers</h3><div
class="confluenceTableSmall"><div class="table-wrap"><table
class="confluenceTable"><tbody><tr><th colspan="1" rowspan="1"
class="confluenceTh"><p>Name</p></th><th colspan="1" rowspan="1"
class="confluenceTh"><p>Type</p></th><th colspan="1" rowspan="1"
class="confluenceTh"><p>Description</p></th></tr><tr><td colspan="1"
rowspan="1"
class="confluenceTd"><p><code>Exchange.CONTENT_ENCODING</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p><code>String</code></p></td><td
colspan="1" rowspan
="1" class="confluenceTd"><p>The HTTP content encoding. Is set on both
the <strong><code>IN</code></strong>
and <strong><code>OUT</code></strong> message to provide a content
encoding, such as <strong><code>gzip</code></strong>.</p></td></tr><tr><td
colspan="1" rowspan="1"
class="confluenceTd"><p><code>Exchange.CONTENT_TYPE</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p><code>String</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p>The HTTP content type. Is set
on both the <strong><code>IN</code></strong>
and <strong><code>OUT</code></strong> message to provide a content type,
such as <strong><code>text/html</code></strong>.</p></td></tr><tr><td
colspan="1" rowspan="1"
class="confluenceTd"><p><code>Exchange.HTTP_CHARACTER_ENCODING</code></p></td><td
colspan="1" rowspan="1"
class="confluenceTd"><p><code>String</code></p></td><td colspan="1" rowspan="1"
class="confluenceTd"><p>Character encoding.</p></td></tr><tr><td colspan="1"
rowspan="1"
class="confluenceTd"><p><code>Exchange.HTTP_PATH</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p><code>String</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p>Request URI's path, the header will be used
to build the request URI with the
<strong><code>HTTP_URI</code></strong>.</p><p>However, if the path is start
with <strong><code>"/"</code></strong>, the HTTP producer will try to find the
relative path based on
the <strong><code>Exchange.HTTP_BASE_URI</code></strong> header or the
<code><strong>exchange.getFromEndpoint().getEndpointUri()</strong>;</code></p></td></tr><tr><td
colspan="1" rowspan="1"
class="confluenceTd"><p><code>Exchange.HTTP_QUERY</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p><code>String</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p><strong>Camel 2.11</strong>:
URI parameters. Will override existing URI parameters set directly on the
endpoint.</p></td></tr><tr><td colsp
an="1" rowspan="1"
class="confluenceTd"><p><code>Exchange.HTTP_RESPONSE_CODE</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p><code>int</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p>The HTTP response code from the
external server. Is <strong><code>200</code></strong> for
<strong><code>OK</code></strong>.</p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>Exchange.HTTP_URI</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p><code>String</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p>URI to call. Will override existing URI set
directly on the endpoint.</p></td></tr></tbody></table></div></div>
-
-
-<h3 id="AHC-MessageBody">Message Body</h3><p>Camel will store the HTTP
response from the external server on the <strong><code>OUT</code></strong>
body. All headers from the <strong><code>IN</code></strong> message will
be copied to the <strong><code>OUT</code></strong> message, so headers are
preserved during routing. Additionally Camel will add the HTTP response headers
as well to the <strong><code>OUT</code></strong> message headers.</p><h3
id="AHC-ResponseCodes">Response Codes</h3><p>The value of the HTTP response
code governs how Camel behaves:</p><ul class="alternate"><li><p>If in the range
<strong><code>100..299</code></strong> Camel will regard it as a successful
response.</p></li><li><p>If in the range <strong><code>300..399</code></strong>
Camel will regard it as a redirection response and throw an
<strong><code>AhcOperationFailedException</code></strong> containing the
relevant information.</p></li><li><p>If greater than
<strong><code>400</code></strong
> Camel regards it as an external server failure and throw an
> <strong><code>AhcOperationFailedException</code></strong> containing the
> relevant information.</p><div class="confluence-information-macro
> confluence-information-macro-tip"><p
> class="title">throwExceptionOnFailure</p><span class="aui-icon
> aui-icon-small aui-iconfont-approve
> confluence-information-macro-icon"></span><div
> class="confluence-information-macro-body"><p>The option,
> <strong><code>throwExceptionOnFailure</code></strong>, can be set to
> <strong><code>false</code></strong> to prevent the
> <strong><code>AhcOperationFailedException</code></strong> from being thrown
> for failed response codes. This allows you to get any response from the
> remote server.</p></div></div></li></ul><h3
> id="AHC-AhcOperationFailedExceptionDetails"><code>AhcOperationFailedException</code>
> Details</h3><p>This exception contains the following information:</p><ul
> class="alternate"><li><p>The HTTP status code.</p></li><li><p>The HTTP
> status line (te
xt of the status code).</p></li><li><p>Redirect location, if server returned a
redirect.</p></li><li><p>Response body as a
<strong><code>java.lang.String</code></strong>, if the server provides a
response body.</p></li></ul><h3 id="AHC-CallingusingGETorPOST">Calling
using <code>GET</code> or <code>POST</code></h3><p>The following
algorithm is used to determine if either <strong><code>GET</code></strong> or
<strong><code>POST</code></strong> HTTP method should be
used:</p><ol><li><p>  Use method provided in header.</p></li><li><p> 
<strong><code>GET</code></strong> if query string is provided in
header.</p></li><li><p>  <strong><code>GET</code></strong> if endpoint is
configured with a query string.</p></li><li><p> 
<strong><code>POST</code></strong> if there is data to send (body is
not <strong><code>null</code></strong>).</p></li><li><p><strong> 
<code>GET</code> </strong>otherwise<strong>.</strong></p></li></ol><h3
id="AHC-ConfiguringtheURIt
oCall">Configuring the URI to Call</h3><p>You can set the HTTP producer's URI
directly form the endpoint URI. In the route below, Camel will call out to the
external server, <strong><code>oldhost</code></strong>, using
HTTP.</p><p><strong>Java DSL</strong>:</p><div class="code panel pdl"
style="border-width: 1px;"><div class="codeContent panelContent pdl">
-<script class="brush: java; gutter: false; theme: Default"
type="syntaxhighlighter"><![CDATA[from("direct:start")
- .to("ahc:http://oldhost");
-]]></script>
-</div></div><p><strong> Spring XML DSL</strong>:</p><div class="code panel
pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
-<script class="brush: xml; gutter: false; theme: Default"
type="syntaxhighlighter"><![CDATA[<camelContext
xmlns="http://activemq.apache.org/camel/schema/spring">
+</plain-text-body><p>The default ports
are <strong><code>80</code></strong> for HTTP
and <strong><code>443</code></strong> for HTTPS.</p><p>Query options can
be specified on the URI using the following format:
<strong><code>?option=value&option=value&...</code></strong></p><h3
id="AHC-AhcEndpointOptions">AhcEndpoint Options</h3><parameter
ac:name="class">confluenceTableSmall</parameter><rich-text-body><div
class="table-wrap"><table class="confluenceTable"><tbody><tr><th colspan="1"
rowspan="1" class="confluenceTh"><p>Name</p></th><th colspan="1" rowspan="1"
class="confluenceTh"><p>Default Value</p></th><th colspan="1" rowspan="1"
class="confluenceTh"><p>Description</p></th></tr><tr><td colspan="1"
rowspan="1" class="confluenceTd"><p><code>binding</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p><code>null</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p>To use a custom
<strong><code>org.apache.camel.component.ahc.AhcBinding</code
></strong>.</p></td></tr><tr><td colspan="1" rowspan="1"
>class="confluenceTd"><p><code>bridgeEndpoint</code></p></td><td colspan="1"
>rowspan="1" class="confluenceTd"><p><code>false</code></p></td><td
>colspan="1" rowspan="1" class="confluenceTd"><p>If the option is
><strong><code>true</code></strong>, then
>the <strong><code>Exchange.HTTP_URI</code></strong> header is ignored,
>and use the endpoint's URI for request. You may also set the
><strong><code>throwExcpetionOnFailure</code></strong> to be false to let
>the <strong><code>AhcProducer</code></strong> send all the fault
>response back.</p></td></tr><tr><td colspan="1" rowspan="1"
>class="confluenceTd"><p><code>bufferSize</code></p></td><td colspan="1"
>rowspan="1" class="confluenceTd"><p><code>4096</code></p></td><td colspan="1"
>rowspan="1" class="confluenceTd"><p><strong>Camel 2.10.3:</strong> The
>initial in-memory buffer size used when transferring data between Camel and
>the <strong><code>ahc</code></strong> Client.</p>
</td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>client</code></p></td><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>null</code></p></td><td colspan="1" rowspan="1"
class="confluenceTd"><p>To use a custom
<strong><code>com.ning.http.client.AsyncHttpClient</code></strong>.</p></td></tr><tr><td
colspan="1" rowspan="1"
class="confluenceTd"><p><code>clientConfig</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p><code>null</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p>To configure the
<strong><code>AsyncHttpClient</code></strong> to use a custom
<strong><code>com.ning.http.client.AsyncHttpClientConfig</code></strong>
instance. This instance replaces any instance configured at the component
level.</p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>clientConfig.x</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p><code>null</code></p></td><td colspan="1"
rowspan="1" class="confl
uenceTd"><p>To configure additional properties of the
<strong><code>com.ning.http.client.AsyncHttpClientConfig</code></strong>
instance used by the endpoint.</p><p><strong>Note</strong>: that configuration
options set using this parameter will be merged with those set using the
<strong><code>clientConfig</code></strong> parameter or the instance set at the
component level with properties set using this parameter taking
priority.</p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>clientConfig.realm.x</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p><code>null</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p><strong>Camel 2.11:</strong> To
configure realm properties of the
<strong><code>com.ning.http.client.AsyncHttpClientConfig</code></strong> The
options which can be used are the options from
<strong><code>com.ning.http.client.Realm.RealmBuilder</code></strong>. e.g., to
set the scheme, you should configure <strong><code>cl
ientConfig.realm.scheme=DIGEST</code></strong></p></td></tr><tr><td
colspan="1" rowspan="1"
class="confluenceTd"><p><code>connectionClose</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p><code>false</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p><strong><strong>Camel
2.18: </strong></strong>If this option is
<strong><code>true</code></strong>, the producer will add a Connection Close
header to HTTP Request</p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>cookieHandler</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p><code>null</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p><strong>Camel 2.19:</strong> Configure a
cookie handler to maintain a HTTP session</p></td></tr><tr><td colspan="1"
rowspan="1"
class="confluenceTd"><p><code>sslContextParameters</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p><code>null</code></p></td><td
colspan="1" rowspan="1" class="con
fluenceTd"><p><strong>Camel 2.9:</strong> Reference to a
<strong><code>org.apache.camel.util.jsse.SSLContextParameters</code></strong>
in the <a shape="rect" href="registry.html">Registry</a>.  This reference
overrides any
configured <strong><code>SSLContextParameters</code></strong> at the
component level. </p><p>See <a shape="rect"
href="#AHC-UsingtheJSSEConfigurationUtility">Using the JSSE Configuration
Utility</a>. </p><p><strong>Note</strong>: configuring this option will
override any SSL/TLS configuration options provided through
the <strong><code>clientConfig</code></strong> option at the endpoint or
component level.</p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>throwExceptionOnFailure</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p><code>true</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p>Option to disable throwing the
<strong><code>AhcOperationFailedException</code></strong> in case
of failed responses from the remote server. This allows you to get all
responses regardless of the HTTP status code.</p></td></tr><tr><td colspan="1"
rowspan="1" class="confluenceTd"><p><code>transferException</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p><code>false</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p>If enabled and an <a
shape="rect" href="exchange.html">Exchange</a> failed processing on the
consumer side, and if the caused <strong><code>Exception</code></strong> was
send back serialized in the response as a
<strong><code>application/x-java-serialized-object</code></strong> content type
(for example using <a shape="rect" href="jetty.html">Jetty</a> or <a
shape="rect" href="servlet.html">SERVLET</a> Camel components). On the producer
side the exception will be deserialized and thrown as is, instead of the
<strong><code>AhcOperationFailedException</code></strong>. The caused exception
is required to be serialized.</p></td></tr></t
body></table></div></rich-text-body><h3
id="AHC-AhcComponentOptions">AhcComponent Options</h3><parameter
ac:name="class">confluenceTableSmall</parameter><rich-text-body><div
class="table-wrap"><table class="confluenceTable"><tbody><tr><th colspan="1"
rowspan="1" class="confluenceTh"><p>Name</p></th><th colspan="1" rowspan="1"
class="confluenceTh"><p>Default Value</p></th><th colspan="1" rowspan="1"
class="confluenceTh"><p>Description</p></th></tr><tr><td colspan="1"
rowspan="1" class="confluenceTd"><p><code>binding</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p><code>null</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p>To use a custom
<strong><code>org.apache.camel.component.ahc.AhcBinding</code></strong>.</p></td></tr><tr><td
colspan="1" rowspan="1"
class="confluenceTd"><p><code>client</code></p></td><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>null</code></p></td><td colspan="1" rowspan="1"
class="confluenceTd"><p>To use a custom
<strong><code>com.ning.http.client.AsyncHttpClient</code>.</strong></p></td></tr><tr><td
colspan="1" rowspan="1"
class="confluenceTd"><p><code>clientConfig</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p><code>null</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p>To configure the
<strong><code>AsyncHttpClient</code></strong> to use a custom
<strong><code>com.ning.http.client.AsyncHttpClientConfig</code></strong>.</p></td></tr><tr><td
colspan="1" rowspan="1"
class="confluenceTd"><p><code>sslContextParameters</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p><code>null</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p><strong>Camel 2.9:</strong> To
configure custom SSL/TLS configuration options at the component
level. </p><p>See  <a shape="rect"
href="#AHC-UsingtheJSSEConfigurationUtility">Using the JSSE Configuration
Utility</a> for more details. </p><p><strong>Note</strong>: configuring
this optio
n will override any SSL/TLS configuration options provided through
the <strong><code>clientConfig</code></strong> option at the endpoint or
component
level.</p></td></tr></tbody></table></div></rich-text-body><p><strong>Note</strong>:
setting any of the options on
the <strong><code>AhcComponent</code></strong> will propagate those
options to the <strong><code>AhcEndpoint</code></strong>(s) being created.
However, the <strong><code>AhcEndpoint</code></strong> can also
configure/override a custom option. Options set on endpoints will always take
precedence over options from the
<strong><code>AhcComponent</code>.</strong></p><h3
id="AHC-MessageHeaders">Message Headers</h3><parameter
ac:name="class">confluenceTableSmall</parameter><rich-text-body><div
class="table-wrap"><table class="confluenceTable"><tbody><tr><th colspan="1"
rowspan="1" class="confluenceTh"><p>Name</p></th><th colspan="1" rowspan="1"
class="confluenceTh"><p>Type</p></th><th colspan="1" rowspan="1"
class="confluenceTh"><p>Description</p></th></tr><tr><td colspan="1"
rowspan="1"
class="confluenceTd"><p><code>Exchange.CONTENT_ENCODING</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p><code>String</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p>The HTTP content encoding. Is
set on both the <strong><code>IN</code></strong>
and <strong><code>OUT</code></strong> message to provide a content
encoding, such as <strong><code>gzip</code></strong>.</p></td></tr><tr><td
colspan="1" rowspan="1"
class="confluenceTd"><p><code>Exchange.CONTENT_TYPE</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p><code>String</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p>The HTTP content type. Is set
on both the <strong><code>IN</code></strong>
and <strong><code>OUT</code></strong> message to provide a content type,
such as <strong><code>text/html</code></strong>.</p></td></tr><tr><td
colspan="1" rowspan="1" class="
confluenceTd"><p><code>Exchange.HTTP_CHARACTER_ENCODING</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p><code>String</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p>Character
encoding.</p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>Exchange.HTTP_PATH</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p><code>String</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p>Request URI's path, the header will be used
to build the request URI with the
<strong><code>HTTP_URI</code></strong>.</p><p>However, if the path is start
with <strong><code>"/"</code></strong>, the HTTP producer will try to find the
relative path based on
the <strong><code>Exchange.HTTP_BASE_URI</code></strong> header or the
<code><strong>exchange.getFromEndpoint().getEndpointUri()</strong>;</code></p></td></tr><tr><td
colspan="1" rowspan="1"
class="confluenceTd"><p><code>Exchange.HTTP_QUERY</code></p></td><td
colspan="1"
rowspan="1" class="confluenceTd"><p><code>String</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p><strong>Camel 2.11</strong>:
URI parameters. Will override existing URI parameters set directly on the
endpoint.</p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>Exchange.HTTP_RESPONSE_CODE</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p><code>int</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p>The HTTP response code from the
external server. Is <strong><code>200</code></strong> for
<strong><code>OK</code></strong>.</p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>Exchange.HTTP_URI</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p><code>String</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p>URI to call. Will override existing URI set
directly on the
endpoint.</p></td></tr></tbody></table></div></rich-text-body><h3
id="AHC-MessageBody">Messa
ge Body</h3><p>Camel will store the HTTP response from the external server on
the <strong><code>OUT</code></strong> body. All headers from
the <strong><code>IN</code></strong> message will be copied to
the <strong><code>OUT</code></strong> message, so headers are preserved
during routing. Additionally Camel will add the HTTP response headers as well
to the <strong><code>OUT</code></strong> message headers.</p><h3
id="AHC-ResponseCodes">Response Codes</h3><p>The value of the HTTP response
code governs how Camel behaves:</p><ul class="alternate"><li><p>If in the range
<strong><code>100..299</code></strong> Camel will regard it as a successful
response.</p></li><li><p>If in the range <strong><code>300..399</code></strong>
Camel will regard it as a redirection response and throw an
<strong><code>AhcOperationFailedException</code></strong> containing the
relevant information.</p></li><li><p>If greater than
<strong><code>400</code></strong> Camel regards it as an exter
nal server failure and throw an
<strong><code>AhcOperationFailedException</code></strong> containing the
relevant information.</p><parameter
ac:name="title">throwExceptionOnFailure</parameter><rich-text-body><p>The
option, <strong><code>throwExceptionOnFailure</code></strong>, can be set to
<strong><code>false</code></strong> to prevent the
<strong><code>AhcOperationFailedException</code></strong> from being thrown for
failed response codes. This allows you to get any response from the remote
server.</p></rich-text-body></li></ul><h3
id="AHC-AhcOperationFailedExceptionDetails"><code>AhcOperationFailedException</code>
Details</h3><p>This exception contains the following information:</p><ul
class="alternate"><li><p>The HTTP status code.</p></li><li><p>The HTTP status
line (text of the status code).</p></li><li><p>Redirect location, if server
returned a redirect.</p></li><li><p>Response body as a
<strong><code>java.lang.String</code></strong>, if the server provides a
response body.</p
></li></ul><h3 id="AHC-CallingusingGETorPOST">Calling
>using <code>GET</code> or <code>POST</code></h3><p>The following
>algorithm is used to determine if either <strong><code>GET</code></strong> or
><strong><code>POST</code></strong> HTTP method should be
>used:</p><ol><li><p>  Use method provided in
>header.</p></li><li><p>  <strong><code>GET</code></strong> if query
>string is provided in header.</p></li><li><p> 
><strong><code>GET</code></strong> if endpoint is configured with a query
>string.</p></li><li><p>  <strong><code>POST</code></strong> if there is
>data to send (body is
>not <strong><code>null</code></strong>).</p></li><li><p><strong> 
><code>GET</code> </strong>otherwise<strong>.</strong></p></li></ol><h3
>id="AHC-ConfiguringtheURItoCall">Configuring the URI to Call</h3><p>You can
>set the HTTP producer's URI directly form the endpoint URI. In the route
>below, Camel will call out to the external server,
><strong><code>oldhost</code></strong>,
using HTTP.</p><p><strong>Java DSL</strong>:</p><parameter
ac:name="language">java</parameter><plain-text-body>from("direct:start")
+ .to("ahc:http://oldhost");
+</plain-text-body><p><strong> Spring XML DSL</strong>:</p><parameter
ac:name="language">xml</parameter><plain-text-body><camelContext
xmlns="http://activemq.apache.org/camel/schema/spring">
<route>
- <from uri="direct:start"/>
- <to uri="ahc:http://oldhost"/>
+ <from uri="direct:start"/>
+ <to uri="ahc:http://oldhost"/>
</route>
</camelContext>
-]]></script>
-</div></div><p>You can override the HTTP endpoint URI by adding a header with
the key <strong><code>Exchange.HTTP_URI</code></strong> on the message.</p><div
class="code panel pdl" style="border-width: 1px;"><div class="codeContent
panelContent pdl">
-<script class="brush: java; gutter: false; theme: Default"
type="syntaxhighlighter"><![CDATA[from("direct:start")
- .setHeader(Exchange.HTTP_URI, constant("http://newhost"))
- .to("ahc:http://oldhost");
-]]></script>
-</div></div><h3 id="AHC-ConfiguringURIParameters">Configuring URI
Parameters</h3><p>The <strong><code>ahc</code></strong> producer supports
URI parameters to be sent to the HTTP server. The URI parameters can either be
set directly on the endpoint URI or as a header with the key
<strong><code>Exchange.HTTP_QUERY</code></strong> on the message.</p><div
class="code panel pdl" style="border-width: 1px;"><div class="codeContent
panelContent pdl">
-<script class="brush: java; gutter: false; theme: Default"
type="syntaxhighlighter"><![CDATA[from("direct:start")
- .to("ahc:http://oldhost?order=123&detail=short");
-]]></script>
-</div></div><p>Or options provided via a header:</p><div class="code panel
pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
-<script class="brush: java; gutter: false; theme: Default"
type="syntaxhighlighter"><![CDATA[from("direct:start")
- .setHeader(Exchange.HTTP_QUERY,
constant("order=123&detail=short"))
- .to("ahc:http://oldhost");
-]]></script>
-</div></div><h3
id="AHC-HowtoSettheHTTPMethod(GET/POST/PUT/DELETE/HEAD/OPTIONS/TRACE)totheHTTPProducer">How
to Set the HTTP Method
(<code>GET</code>/<code>POST</code>/<code>PUT</code>/<code>DELETE</code>/<code>HEAD</code>/<code>OPTIONS</code>/<code>TRACE</code>)
to the HTTP Producer</h3><p>The HTTP component provides a way to set the HTTP
request method by setting the message
header.</p><p><strong>Example</strong></p><p><strong>Java DSL</strong>:</p><div
class="code panel pdl" style="border-width: 1px;"><div class="codeContent
panelContent pdl">
-<script class="brush: java; gutter: false; theme: Default"
type="syntaxhighlighter"><![CDATA[from("direct:start")
- .setHeader(Exchange.HTTP_METHOD, constant("POST"))
- .to("ahc:http://www.google.com")
- .to("mock:results");
-]]></script>
-</div></div><p><strong> Spring XML DSL</strong>:</p><div class="code panel
pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
-<script class="brush: xml; gutter: false; theme: Default"
type="syntaxhighlighter"><![CDATA[<camelContext
xmlns="http://activemq.apache.org/camel/schema/spring">
+</plain-text-body><p>You can override the HTTP endpoint URI by adding a header
with the key <strong><code>Exchange.HTTP_URI</code></strong> on the
message.</p><parameter
ac:name="language">java</parameter><plain-text-body>from("direct:start")
+ .setHeader(Exchange.HTTP_URI, constant("http://newhost"))
+ .to("ahc:http://oldhost");
+</plain-text-body><h3 id="AHC-ConfiguringURIParameters">Configuring URI
Parameters</h3><p>The <strong><code>ahc</code></strong> producer supports
URI parameters to be sent to the HTTP server. The URI parameters can either be
set directly on the endpoint URI or as a header with the key
<strong><code>Exchange.HTTP_QUERY</code></strong> on the message.</p><parameter
ac:name="language">java</parameter><plain-text-body>from("direct:start")
+ .to("ahc:http://oldhost?order=123&detail=short");
+</plain-text-body><p>Or options provided via a header:</p><parameter
ac:name="language">java</parameter><plain-text-body>from("direct:start")
+ .setHeader(Exchange.HTTP_QUERY, constant("order=123&detail=short"))
+ .to("ahc:http://oldhost");
+</plain-text-body><h3
id="AHC-HowtoSettheHTTPMethod(GET/POST/PUT/DELETE/HEAD/OPTIONS/TRACE)totheHTTPProducer">How
to Set the HTTP Method
(<code>GET</code>/<code>POST</code>/<code>PUT</code>/<code>DELETE</code>/<code>HEAD</code>/<code>OPTIONS</code>/<code>TRACE</code>)
to the HTTP Producer</h3><p>The HTTP component provides a way to set the HTTP
request method by setting the message
header.</p><p><strong>Example</strong></p><p><strong>Java
DSL</strong>:</p><parameter
ac:name="language">java</parameter><plain-text-body>from("direct:start")
+ .setHeader(Exchange.HTTP_METHOD, constant("POST"))
+ .to("ahc:http://www.google.com")
+ .to("mock:results");
+</plain-text-body><p><strong> Spring XML DSL</strong>:</p><parameter
ac:name="language">xml</parameter><plain-text-body><camelContext
xmlns="http://activemq.apache.org/camel/schema/spring">
<route>
- <from uri="direct:start"/>
- <setHeader headerName="CamelHttpMethod">
+ <from uri="direct:start"/>
+ <setHeader headerName="CamelHttpMethod">
<constant>POST</constant>
</setHeader>
- <to uri="ahc:http://www.google.com"/>
- <to uri="mock:results"/>
+ <to uri="ahc:http://www.google.com"/>
+ <to uri="mock:results"/>
</route>
</camelContext>
-]]></script>
-</div></div><h3
id="AHC-Configuringcharset">Configuring <code>charset</code></h3><p>If you
are using <strong><code>POST</code></strong> to send data you can configure the
<strong><code>charset</code></strong> using the
<strong><code>Exchange</code></strong> property:</p><div class="code panel pdl"
style="border-width: 1px;"><div class="codeContent panelContent pdl">
-<script class="brush: java; gutter: false; theme: Default"
type="syntaxhighlighter"><![CDATA[exchange.setProperty(Exchange.CHARSET_NAME,
"iso-8859-1");
-]]></script>
-</div></div><h4 id="AHC-URIParametersFromtheEndpointURI">URI Parameters From
the Endpoint URI</h4><p>In this example we have the complete URI endpoint that
is just what you would have typed in a web browser. Multiple URI parameters can
of course be set using the <strong><code>&</code></strong> character as
separator, just as you would in the web browser. Camel does no tricks
here.</p><div class="code panel pdl" style="border-width: 1px;"><div
class="codeContent panelContent pdl">
-<script class="brush: java; gutter: false; theme: Default"
type="syntaxhighlighter"><![CDATA[// we query for Camel at the Google page
-template.sendBody("ahc:http://www.google.com/search?q=Camel", null);
-]]></script>
-</div></div><h4 id="AHC-URIParametersFromtheMessage">URI Parameters From the
Message</h4><div class="code panel pdl" style="border-width: 1px;"><div
class="codeContent panelContent pdl">
-<script class="brush: java; gutter: false; theme: Default"
type="syntaxhighlighter"><![CDATA[Map headers = new HashMap();
-headers.put(Exchange.HTTP_QUERY, "q=Camel&lr=lang_en");
+</plain-text-body><h3
id="AHC-Configuringcharset">Configuring <code>charset</code></h3><p>If you
are using <strong><code>POST</code></strong> to send data you can configure the
<strong><code>charset</code></strong> using the
<strong><code>Exchange</code></strong> property:</p><parameter
ac:name="language">java</parameter><plain-text-body>exchange.setProperty(Exchange.CHARSET_NAME,
"iso-8859-1");
+</plain-text-body><h4 id="AHC-URIParametersFromtheEndpointURI">URI Parameters
From the Endpoint URI</h4><p>In this example we have the complete URI endpoint
that is just what you would have typed in a web browser. Multiple URI
parameters can of course be set using the <strong><code>&</code></strong>
character as separator, just as you would in the web browser. Camel does no
tricks here.</p><parameter
ac:name="language">java</parameter><plain-text-body>// we query for Camel at
the Google page
+template.sendBody("ahc:http://www.google.com/search?q=Camel", null);
+</plain-text-body><h4 id="AHC-URIParametersFromtheMessage">URI Parameters From
the Message</h4><parameter
ac:name="language">java</parameter><plain-text-body>Map headers = new HashMap();
+headers.put(Exchange.HTTP_QUERY, "q=Camel&lr=lang_en");
// We query for Camel and English language at Google
-template.sendBody("ahc:http://www.google.com/search", null, headers);
-]]></script>
-</div></div><p>In the header value above notice that it should
<strong>not</strong> be prefixed with <strong><code>?</code></strong> and you
can separate parameters as usual with the <strong><code>&</code></strong>
char.</p><h4 id="AHC-GettingtheResponseCode">Getting the Response
Code</h4><p>You can get the HTTP response code from
the <strong><code>ahc</code></strong> component by getting the value from
the <strong><code>OUT</code></strong> message header with
<strong><code>Exchange.HTTP_RESPONSE_CODE</code></strong>.</p><div class="code
panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
-<script class="brush: java; gutter: false; theme: Default"
type="syntaxhighlighter"><![CDATA[Exchange exchange =
template.send("ahc:http://www.google.com/search", new Processor() {
+template.sendBody("ahc:http://www.google.com/search", null, headers);
+</plain-text-body><p>In the header value above notice that it should
<strong>not</strong> be prefixed with <strong><code>?</code></strong> and you
can separate parameters as usual with the <strong><code>&</code></strong>
char.</p><h4 id="AHC-GettingtheResponseCode">Getting the Response
Code</h4><p>You can get the HTTP response code from
the <strong><code>ahc</code></strong> component by getting the value from
the <strong><code>OUT</code></strong> message header with
<strong><code>Exchange.HTTP_RESPONSE_CODE</code></strong>.</p><parameter
ac:name="language">java</parameter><plain-text-body>Exchange exchange =
template.send("ahc:http://www.google.com/search", new Processor() {
public void process(Exchange exchange) throws Exception {
- exchange.getIn().setHeader(Exchange.HTTP_QUERY,
constant("hl=en&q=activemq"));
+ exchange.getIn().setHeader(Exchange.HTTP_QUERY,
constant("hl=en&q=activemq"));
}
});
Message out = exchange.getOut();
int responseCode = out.getHeader(Exchange.HTTP_RESPONSE_CODE, Integer.class);
-]]></script>
-</div></div><h3 id="AHC-ConfiguringAsyncHttpClient">Configuring
AsyncHttpClient</h3><p>The <strong><code>AsyncHttpClient</code></strong> client
uses a <strong><code>AsyncHttpClientConfig</code></strong> to configure the
client. See the documentation at<a shape="rect" class="external-link"
href="http://github.com/sonatype/async-http-client" rel="nofollow"> Async Http
Client</a> for more details.</p><p>In Camel <strong>2.8</strong>, configuration
is limited to using the builder pattern provided by
<strong><code>AsyncHttpClientConfig.Builder</code></strong>. In Camel
<strong>2.8</strong>, the <strong><code>AsyncHttpClientConfig</code></strong>
doesn't support getters/setters so its not easy to create/configure using a
Spring bean style e.g., the <strong><code><bean></code></strong> tag
in the XML file.</p><p>The example below shows how to use a builder to create
the <strong><code>AsyncHttpClientConfig</code></strong> which we configure on
the <strong><code>AhcComponent</code
></strong>.</p><div class="code panel pdl" style="border-width: 1px;"><div
>class="codeContent panelContent pdl">
-<script class="brush: java; gutter: false; theme: Default"
type="syntaxhighlighter"><![CDATA[// Create a client config builder.
+</plain-text-body><h3 id="AHC-ConfiguringAsyncHttpClient">Configuring
AsyncHttpClient</h3><p>The <strong><code>AsyncHttpClient</code></strong> client
uses a <strong><code>AsyncHttpClientConfig</code></strong> to configure the
client. See the documentation at<a shape="rect" class="external-link"
href="http://github.com/sonatype/async-http-client" rel="nofollow"> Async Http
Client</a> for more details.</p><p>In Camel <strong>2.8</strong>, configuration
is limited to using the builder pattern provided by
<strong><code>AsyncHttpClientConfig.Builder</code></strong>. In Camel
<strong>2.8</strong>, the <strong><code>AsyncHttpClientConfig</code></strong>
doesn't support getters/setters so its not easy to create/configure using a
Spring bean style e.g., the <strong><code><bean></code></strong> tag
in the XML file.</p><p>The example below shows how to use a builder to create
the <strong><code>AsyncHttpClientConfig</code></strong> which we configure on
the <strong><code>AhcComponent
</code></strong>.<parameter ac:name="language">java</parameter><parameter
ac:name="atlassian-macro-output-type">INLINE</parameter><plain-text-body>//
Create a client config builder.
DefaultAsyncHttpClientConfig.Builder builder = new
DefaultAsyncHttpClientConfig.Builder();
// Use the builder to set the desired options.
DefaultAsyncHttpClientConfig config =
builder.setFollowRedirect(true).setMaxRequestRetry(3).build();
// Lookup the AhcComponent...
-AhcComponent component = context.getComponent("ahc",
AhcComponent.class);
+AhcComponent component = context.getComponent("ahc", AhcComponent.class);
// ...and set the custom client config.
-component.setClientConfig(config);]]></script>
-</div></div>In Camel <strong>2.9</strong>,
the <strong><code>ahc</code></strong> component uses <code>Async HTTP
library 1.6.4</code>. This newer version provides added support for plain bean
style configuration. The
<strong><code>AsyncHttpClientConfigBean</code></strong> class provides getters
and setters for the configuration options available in
<strong><code>AsyncHttpClientConfig</code></strong>. An instance of
<strong><code>AsyncHttpClientConfigBean</code></strong> may be passed directly
to the <strong><code>ahc</code></strong> component or referenced in an
endpoint URI using the <strong><code>clientConfig</code></strong> URI
parameter.<p>Also available in Camel <strong>2.9</strong> is the ability to set
configuration options directly in the URI. URI options starting with
<strong><code>clientConfig</code></strong> can be used to set the various
configurable properties of <strong><code>AsyncHttpClientConfig</code></strong>.
Options specified in the endpoint URI are mer
ged with those specified by
the <strong><code>clientConfig</code></strong> option. These options take
precedence over the options specified on the URI endpoint. A copy of the
<strong><code>AsyncHttpClientConfig</code></strong> is made for each new
endpoint. The example below shows how to configure
the <strong><code>ahc</code></strong> component using the
<strong><code>clientConfig</code></strong> URI options.</p><div class="code
panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
-<script class="brush: java; gutter: false; theme: Default"
type="syntaxhighlighter"><![CDATA[from("direct:start")
-
.to("ahc:http://localhost:8080/foo?clientConfig.maxRequestRetry=3&clientConfig.followRedirects=true")
-]]></script>
-</div></div><h3 id="AHC-SSLSupport(HTTPS)">SSL Support (HTTPS)</h3><h5
id="AHC-UsingtheJSSEConfigurationUtility">Using the JSSE Configuration
Utility</h5><p>From <strong>Camel 2.9</strong>,
the <strong><code>ahc</code></strong> component supports SSL/TLS
configuration through the <a shape="rect"
href="camel-configuration-utilities.html">Camel JSSE Configuration
Utility</a>.  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 <strong><code>ahc</code></strong> component.</p><h6
id="AHC-Programmaticconfigurationofthecomponent">Programmatic configuration of
the component</h6><div class="code panel pdl" style="border-width: 1px;"><div
class="codeContent panelContent pdl">
-<script class="brush: java; gutter: false; theme: Default"
type="syntaxhighlighter"><![CDATA[KeyStoreParameters ksp = new
KeyStoreParameters();
-ksp.setResource("/users/home/server/keystore.jks");
-ksp.setPassword("keystorePassword");
+component.setClientConfig(config);</plain-text-body>In Camel
<strong>2.9</strong>, the <strong><code>ahc</code></strong> component uses
<code>Async HTTP library 1.6.4</code>. This newer version provides added
support for plain bean style configuration. The
<strong><code>AsyncHttpClientConfigBean</code></strong> class provides getters
and setters for the configuration options available in
<strong><code>AsyncHttpClientConfig</code></strong>. An instance of
<strong><code>AsyncHttpClientConfigBean</code></strong> may be passed directly
to the <strong><code>ahc</code></strong> component or referenced in an
endpoint URI using the <strong><code>clientConfig</code></strong> URI
parameter.</p><p>Also available in Camel <strong>2.9</strong> is the ability to
set configuration options directly in the URI. URI options starting with
<strong><code>clientConfig</code></strong> can be used to set the various
configurable properties of <strong><code>AsyncHttpClientConfig</code></strong>.
O
ptions specified in the endpoint URI are merged with those specified by
the <strong><code>clientConfig</code></strong> option. These options take
precedence over the options specified on the URI endpoint. A copy of the
<strong><code>AsyncHttpClientConfig</code></strong> is made for each new
endpoint. The example below shows how to configure
the <strong><code>ahc</code></strong> component using the
<strong><code>clientConfig</code></strong> URI options.</p><parameter
ac:name="language">java</parameter><plain-text-body>from("direct:start")
+
.to("ahc:http://localhost:8080/foo?clientConfig.maxRequestRetry=3&clientConfig.followRedirects=true")
+</plain-text-body><h3 id="AHC-SSLSupport(HTTPS)">SSL Support (HTTPS)</h3><h5
id="AHC-UsingtheJSSEConfigurationUtility">Using the JSSE Configuration
Utility</h5><p>From <strong>Camel 2.9</strong>,
the <strong><code>ahc</code></strong> component supports SSL/TLS
configuration through the <a shape="rect"
href="camel-configuration-utilities.html">Camel JSSE Configuration
Utility</a>.  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 <strong><code>ahc</code></strong> component.</p><h6
id="AHC-Programmaticconfigurationofthecomponent">Programmatic configuration of
the component</h6><parameter
ac:name="language">java</parameter><plain-text-body>KeyStoreParameters ksp =
new KeyStoreParameters();
+ksp.setResource("/users/home/server/keystore.jks");
+ksp.setPassword("keystorePassword");
KeyManagersParameters kmp = new KeyManagersParameters();
kmp.setKeyStore(ksp);
-kmp.setKeyPassword("keyPassword");
+kmp.setKeyPassword("keyPassword");
SSLContextParameters scp = new SSLContextParameters();
scp.setKeyManagers(kmp);
-AhcComponent component = context.getComponent("ahc",
AhcComponent.class);
+AhcComponent component = context.getComponent("ahc", AhcComponent.class);
component.setSslContextParameters(scp));
-]]></script>
-</div></div><h6 id="AHC-SpringDSLbasedconfigurationofendpoint">Spring DSL
based configuration of endpoint</h6><div class="code panel pdl"
style="border-width: 1px;"><div class="codeContent panelContent pdl">
-<script class="brush: xml; gutter: false; theme: Default"
type="syntaxhighlighter"><![CDATA[<camel:sslContextParameters
id="sslContextParameters">
- <camel:keyManagers keyPassword="keyPassword">
- <camel:keyStore resource="/users/home/server/keystore.jks"
password="keystorePassword"/>
+</plain-text-body><h6 id="AHC-SpringDSLbasedconfigurationofendpoint">Spring
DSL based configuration of endpoint</h6><parameter
ac:name="language">xml</parameter><plain-text-body><camel:sslContextParameters
id="sslContextParameters">
+ <camel:keyManagers keyPassword="keyPassword">
+ <camel:keyStore resource="/users/home/server/keystore.jks"
password="keystorePassword"/>
</camel:keyManagers>
</camel:sslContextParameters>
-<to
uri="ahc:https://localhost/foo?sslContextParameters=#sslContextParameters"/>
-]]></script>
-</div></div><p></p><h3 id="AHC-SeeAlso">See Also</h3>
-<ul><li><a shape="rect" href="configuring-camel.html">Configuring
Camel</a></li><li><a shape="rect"
href="component.html">Component</a></li><li><a shape="rect"
href="endpoint.html">Endpoint</a></li><li><a shape="rect"
href="getting-started.html">Getting Started</a></li></ul><ul
class="alternate"><li><a shape="rect" href="jetty.html">Jetty</a></li><li><a
shape="rect" href="http.html">HTTP</a></li><li><a shape="rect"
href="http4.html">HTTP4</a></li></ul></div>
+<to
uri="ahc:https://localhost/foo?sslContextParameters=#sslContextParameters"/>
+</plain-text-body><p><parameter ac:name=""><a shape="rect"
href="endpoint-see-also.html">Endpoint See Also</a></parameter></p><ul
class="alternate"><li><a shape="rect" href="jetty.html">Jetty</a></li><li><a
shape="rect" href="http.html">HTTP</a></li><li><a shape="rect"
href="http4.html">HTTP4</a></li></ul></div>
</td>
<td valign="top">
<div class="navigation">