Modified: websites/production/camel/content/camel-test.html
==============================================================================
--- websites/production/camel/content/camel-test.html (original)
+++ websites/production/camel/content/camel-test.html Fri Aug 25 08:22:01 2017
@@ -36,17 +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 src='//camel.apache.org/styles/highlighter/scripts/shBrushPlain.js'
type='text/javascript'></script>
-
- <script type="text/javascript">
- SyntaxHighlighter.defaults['toolbar'] = false;
- SyntaxHighlighter.all();
- </script>
<title>
Apache Camel: Camel Test
@@ -86,24 +75,19 @@
<tbody>
<tr>
<td valign="top" width="100%">
-<div class="wiki-content maincontent"><h2 id="CamelTest-CamelTest">Camel
Test</h2><p>As a simple alternative to using <a shape="rect"
href="cdi-testing.html">CDI Testing</a>, <a shape="rect"
href="spring-testing.html">Spring Testing</a> or <a shape="rect"
href="guice.html">Guice</a> the <strong>camel-test</strong> module was
introduced so you can perform powerful <a shape="rect"
href="testing.html">Testing</a> of your <a shape="rect"
href="enterprise-integration-patterns.html">Enterprise Integration Patterns</a>
easily.</p><div class="confluence-information-macro
confluence-information-macro-information"><span class="aui-icon aui-icon-small
aui-iconfont-info confluence-information-macro-icon"></span><div
class="confluence-information-macro-body"><p>The
<strong><code>camel-test</code></strong> JAR is using JUnit. There is an
alternative <strong><code>camel-testng</code></strong> JAR (from <strong>Camel
2.8</strong>) using the <a shape="rect" class="external-link" href="http://te
stng.org/doc/index.html" rel="nofollow">TestNG</a> test
framework.</p></div></div><h3 id="CamelTest-Addingtoyourpom.xml">Adding to
your <code>pom.xml</code></h3><p>To get started using Camel Test you will
need to add an entry to your <strong><code>pom.xml</code></strong>:</p><h4
id="CamelTest-JUnit">JUnit</h4><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="CamelTest-CamelTest">Camel
Test</h2><p>As a simple alternative to using <a shape="rect"
href="cdi-testing.html">CDI Testing</a>, <a shape="rect"
href="spring-testing.html">Spring Testing</a> or <a shape="rect"
href="guice.html">Guice</a> the <strong>camel-test</strong> module was
introduced so you can perform powerful <a shape="rect"
href="testing.html">Testing</a> of your <a shape="rect"
href="enterprise-integration-patterns.html">Enterprise Integration Patterns</a>
easily.</p><parameter ac:name="tile">JUnit or
TestNG</parameter><rich-text-body><p>The
<strong><code>camel-test</code></strong> JAR is using JUnit. There is an
alternative <strong><code>camel-testng</code></strong> JAR (from <strong>Camel
2.8</strong>) using the <a shape="rect" class="external-link"
href="http://testng.org/doc/index.html" rel="nofollow">TestNG</a> test
framework.</p></rich-text-body><h3 id="CamelTest-Addingtoyourpom.xml">Adding to
your <code>pom.xm
l</code></h3><p>To get started using Camel Test you will need to add an entry
to your <strong><code>pom.xml</code></strong>:</p><h4
id="CamelTest-JUnit">JUnit</h4><parameter
ac:name="">xml</parameter><plain-text-body><dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-test</artifactId>
<version>${camel-version}</version>
<scope>test</scope>
</dependency>
-]]></script>
-</div></div><h4 id="CamelTest-TestNG">TestNG</h4><p><strong>Available as of
Camel 2.8</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[<dependency>
+</plain-text-body><h4 id="CamelTest-TestNG">TestNG</h4><p><strong>Available as
of Camel 2.8</strong></p><parameter
ac:name="">xml</parameter><plain-text-body><dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-testng</artifactId>
<version>${camel-version}</version>
<scope>test</scope>
</dependency>
-]]></script>
-</div></div><p>You might also want to
add <strong><code>slf4j</code></strong>
and <strong><code>log4j</code></strong> to ensure nice logging messages
(and maybe adding a <a shape="rect" class="external-link"
href="http://svn.apache.org/repos/asf/camel/trunk/components/camel-test/src/test/resources/log4j.properties">log4j.properties</a>
file into your <strong><code>src/test/resources</code></strong>
directory).</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><p>You might also want to
add <strong><code>slf4j</code></strong>
and <strong><code>log4j</code></strong> to ensure nice logging messages
(and maybe adding a <a shape="rect" class="external-link"
href="http://svn.apache.org/repos/asf/camel/trunk/components/camel-test/src/test/resources/log4j.properties">log4j.properties</a>
file into your <strong><code>src/test/resources</code></strong>
directory).</p><parameter
ac:name="">xml</parameter><plain-text-body><dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<scope>test</scope>
@@ -113,109 +97,15 @@
<artifactId>log4j</artifactId>
<scope>test</scope>
</dependency>
-]]></script>
-</div></div><h3 id="CamelTest-Writingyourtest">Writing your test</h3><p>You
firstly need to derive from the
class <strong><code>CamelTestSupport</code></strong> <strong>(<code>org.apache.camel.test.CamelTestSupport</code>,
<code>org.apache.camel.test.junit4.CamelTestSupport</code></strong>,
or <strong><code>org.apache.camel.testng.CamelTestSupport</code></strong>
for JUnit 3.x, JUnit 4.x, and TestNG, respectively) and typically you will
need to override
the <strong><strong><code>createRouteBuilder()</code></strong> or
<strong><code>createRouteBuilders()</code></strong></strong> method to create
routes to be tested.</p><p>Here is an <a shape="rect" class="external-link"
href="http://svn.apache.org/repos/asf/camel/trunk/components/camel-test/src/test/java/org/apache/camel/test/patterns/FilterTest.java">example</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[
-// tag::example[]
-public class FilterTest extends CamelTestSupport {
-
- @EndpointInject(uri = "mock:result")
- protected MockEndpoint resultEndpoint;
-
- @Produce(uri = "direct:start")
- protected ProducerTemplate template;
-
- @Override
- public boolean isDumpRouteCoverage() {
- return true;
- }
-
- @Test
- public void testSendMatchingMessage() throws Exception {
- String expectedBody = "<matched/>";
-
- resultEndpoint.expectedBodiesReceived(expectedBody);
-
- template.sendBodyAndHeader(expectedBody, "foo",
"bar");
-
- resultEndpoint.assertIsSatisfied();
- }
-
- @Test
- public void testSendNotMatchingMessage() throws Exception {
- resultEndpoint.expectedMessageCount(0);
-
- template.sendBodyAndHeader("<notMatched/>",
"foo", "notMatchedHeaderValue");
-
- resultEndpoint.assertIsSatisfied();
- }
-
- @Override
- protected RouteBuilder createRouteBuilder() {
- return new RouteBuilder() {
- public void configure() {
-
from("direct:start").filter(header("foo").isEqualTo("bar")).to("mock:result");
- }
- };
- }
-}
-// end::example[]
-]]></script>
-</div></div><strong>Note</strong>: how you can use the various <a shape="rect"
href="bean-integration.html">Camel binding and injection annotations</a> to
inject individual <a shape="rect" href="endpoint.html">Endpoint</a> objects -
particularly the <a shape="rect" href="mock.html">Mock endpoints</a> which are
very useful for <a shape="rect" href="testing.html">Testing</a>. Also you can
inject <a shape="rect" href="pojo-producing.html">producer objects such as
ProducerTemplate or some application code interface</a> for sending messages or
invoking services.<h4
id="CamelTest-FeaturesProvidedbyCamelTestSupport">Features Provided
by <code>CamelTestSupport</code></h4><p>The
various <strong><code>CamelTestSupport</code></strong> classes provide a
standard set of behaviors relating to
the <strong><code>CamelContext</code></strong> used to host the route(s)
under test.  The classes provide a number of methods that allow a test to
alter the configuration of the <str
ong><code>CamelContext</code></strong> used.  The following table
describes the available customization methods and the default behavior of tests
that are built from a <strong><code>CamelTestSupport</code></strong>
class.</p><div class="table-wrap"><table class="confluenceTable"><tbody><tr><th
colspan="1" rowspan="1" class="confluenceTh"><p>Method Name</p></th><th
colspan="1" rowspan="1" class="confluenceTh"><p>Description</p></th><th
colspan="1" rowspan="1" class="confluenceTh"><p>Default
Behavior</p></th></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>boolean isUseRouteBuilder()</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p>If the route builders returned
from either <strong><code>createRouteBuilder()</code></strong> or
<strong><code>createRouteBuilders()</code></strong> should be added to
the <strong><code>CamelContext</code></strong> for the test to be
started.</p></td><td colspan="1" rowspan="1" class="confluenceTd"><p>Retur
ns
<strong><code>true</code></strong>. </p><p><strong><strong><code>createRouteBuilder()</code></strong>
or <strong><code>createRouteBuilders()</code></strong></strong> are invoked
and the <strong><code>CamelContext</code></strong> is started
automatically.</p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>boolean isUseAdviceWith()</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p>If
the <strong><code>CamelContext</code></strong> use in the test should be
automatically started before test methods are invoked.</p><p><br clear="none"
class="atl-forced-newline"> Override when using <a shape="rect"
href="advicewith.html">advice with</a> and return
<strong><code>true</code></strong>.  This helps in knowing
the <strong><code>adviceWith()</code></strong> is to be used, and
the <strong><code>CamelContext</code></strong> will not be started
before the advice with takes place. This delay helps by ensuring the ad
vice with has been property setup before
the <strong><code>CamelContext</code></strong> is started.</p><div
class="confluence-information-macro
confluence-information-macro-information"><span class="aui-icon aui-icon-small
aui-iconfont-info confluence-information-macro-icon"></span><div
class="confluence-information-macro-body"><p>Its important to start
the <strong><code>CamelContext</code></strong> manually from the unit test
after you are done doing all the advice with.</p></div></div></td><td
colspan="1" rowspan="1" class="confluenceTd"><p>Returns
<strong><code>false</code></strong>. </p><p>The <strong><code>CamelContext</code></strong>
is started automatically before test methods are invoked.</p></td></tr><tr><td
colspan="1" rowspan="1" class="confluenceTd"><p><code>boolean
isCreateCamelContextPerClass()</code></p></td><td colspan="1" rowspan="1"
class="confluenceTd"><p>See <a shape="rect"
href="#CamelTest-SetupCamelContextonceperclass,orpereverytestmeth
od">Setup CamelContext once per class, or per every test
method</a>.</p></td><td colspan="1" rowspan="1"
class="confluenceTd"><p>The <strong><code>CamelContext</code></strong> and
routes are recreated for each test method.</p></td></tr><tr><td colspan="1"
rowspan="1" class="confluenceTd"><p><code>String
isMockEndpoints()</code></p></td><td colspan="1" rowspan="1"
class="confluenceTd"><p>Triggers the auto-mocking of endpoints whose URIs match
the provided filter.  The default filter
is <strong><code>null</code></strong> which disables this feature.
 </p><p>Return <strong><code>"*"</code></strong>  to match all
endpoints.
 </p><p>See <strong><code>org.apache.camel.impl.InterceptSendToMockEndpointStrategy</code></strong>
for more details on the registration of the mock endpoints.</p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p>Disabled</p></td></tr><tr><td
colspan="1" rowspan="1" class="confluenceTd"><p><code>boolean isUseDe
bugger()</code></p></td><td colspan="1" rowspan="1" class="confluenceTd"><p>If
this method returns <strong><code>true</code></strong>, the
methods:</p><ul><li><strong><code>debugBefore(Exchange exchange, Processor
processor, ProcessorDefinition<?> definition, String id, String
label)</code></strong></li><li><strong> <code>debugAfter(Exchange exchange,
Processor processor, ProcessorDefinition<?> definition, String id,
String label, long timeTaken)</code></strong></li></ul><p>are invoked for each
processor in the registered routes.</p></td><td colspan="1" rowspan="1"
class="confluenceTd"><p>Disabled</p><p>The methods are not invoked during the
test.</p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>int getShutdownTimeout()</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p>Returns the number of seconds
that Camel should wait for graceful shutdown.  </p><p>Useful for
decreasing test times when a message is still in fli
ght at the end of the test.</p></td><td colspan="1" rowspan="1"
class="confluenceTd"><p>10 seconds</p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>boolean useJmx()</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p>If JMX should be disabled on
the <strong><code>CamelContext</code></strong> used in the
test.</p></td><td colspan="1" rowspan="1" class="confluenceTd"><p>JMX is
disabled</p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>JndiRegistry createRegistry()</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p>Provides a hook for adding
objects into the registry.  Override this method to bind objects to the
registry before test methods are invoked.</p></td><td colspan="1" rowspan="1"
class="confluenceTd"><p>An empty registry is initialized</p></td></tr><tr><td
colspan="1" rowspan="1"
class="confluenceTd"><p><code>useOverridePropertiesWithPropertiesComponent</code></p></td><td
colspan="1" ro
wspan="1" class="confluenceTd"><p><strong>Camel 2.10:</strong> Allows to
add/override properties when <a shape="rect"
href="using-propertyplaceholder.html">Using PropertyPlaceholder</a> in
Camel.</p></td><td colspan="1" rowspan="1"
class="confluenceTd"><p><strong><code>null</code></strong></p></td></tr><tr><td
colspan="1" rowspan="1"
class="confluenceTd"><p><code>ignoreMissingLocationWithPropertiesComponent</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p><strong>Camel 2.10:</strong>
Allows to control if Camel should ignore missing locations for
properties.</p></td><td colspan="1" rowspan="1"
class="confluenceTd"><p><strong><code>null</code></strong></p></td></tr><tr><td
colspan="1" rowspan="1" class="confluenceTd"><p><code>boolean
isDumpRouteCoverage</code></p></td><td colspan="1" rowspan="1"
class="confluenceTd"><p><strong>Camel 2.16:</strong> If enabled, then Camel
will dump all route coverage statistics into XML files in the
target/camel-route-coverage director
y. These XML files contains information about "route coverage" of all the
routes that was used during the unit test. This allows tooling to inspect these
XML files and generate nice route coverage reports.</p></td><td colspan="1"
rowspan="1" class="confluenceTd">Disabled</td></tr></tbody></table></div><h3
id="CamelTest-JNDI">JNDI</h3><p>Camel uses a <a shape="rect"
href="registry.html">Registry</a> to allow you to configure <a shape="rect"
href="component.html">Component</a> or <a shape="rect"
href="endpoint.html">Endpoint</a> instances or <a shape="rect"
href="bean-integration.html">Beans used in your routes</a>. If you are not
using <a shape="rect" href="spring.html">Spring</a> or <a shape="rect"
class="unresolved" href="#">OSGi</a> then <a shape="rect"
href="jndi.html">JNDI</a> is used as the default registry
implementation.</p><p>So you will also need to create
a <strong><code>jndi.properties</code></strong> file in
your <strong><code>src/test/resources</code></strong>
directory so that there is a default registry available to initialize the <a
shape="rect" href="camelcontext.html">CamelContext</a>.</p><p>Here is <a
shape="rect" class="external-link"
href="http://svn.apache.org/repos/asf/camel/trunk/components/camel-test/src/test/resources/jndi.properties">an
example jndi.properties file</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[java.naming.factory.initial =
org.apache.camel.util.jndi.CamelInitialContextFactory
-]]></script>
-</div></div><h3 id="CamelTest-DynamicallyAssigningPorts">Dynamically Assigning
Ports</h3><p><strong>Available as of Camel 2.7</strong></p><p>Tests that use
port numbers will fail if that port is already on use.
<strong><code>AvailablePortFinder</code></strong> provides methods for finding
unused port numbers at run time.</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[// Get the next available port number
starting from the default starting port of 1024
+</plain-text-body><h3 id="CamelTest-Writingyourtest">Writing your
test</h3><p>You firstly need to derive from the
class <strong><code>CamelTestSupport</code></strong> <strong>(<code>org.apache.camel.test.CamelTestSupport</code>,
<code>org.apache.camel.test.junit4.CamelTestSupport</code></strong>,
or <strong><code>org.apache.camel.testng.CamelTestSupport</code></strong>
for JUnit 3.x, JUnit 4.x, and TestNG, respectively) and typically you will
need to override
the <strong><strong><code>createRouteBuilder()</code></strong> or
<strong><code>createRouteBuilders()</code></strong></strong> method to create
routes to be tested.</p><p>Here is an <a shape="rect" class="external-link"
href="http://svn.apache.org/repos/asf/camel/trunk/components/camel-test/src/test/java/org/apache/camel/test/patterns/FilterTest.java">example</a>.<plain-text-body>{snippet:lang=java|id=example|url=camel/trunk/components/camel-test/src/test/java/org/apache/camel/test/patterns/FilterTest.j
ava}</plain-text-body><strong>Note</strong>: how you can use the various <a
shape="rect" href="bean-integration.html">Camel binding and injection
annotations</a> to inject individual <a shape="rect"
href="endpoint.html">Endpoint</a> objects - particularly the <a shape="rect"
href="mock.html">Mock endpoints</a> which are very useful for <a shape="rect"
href="testing.html">Testing</a>. Also you can inject <a shape="rect"
href="pojo-producing.html">producer objects such as ProducerTemplate or some
application code interface</a> for sending messages or invoking
services.</p><h4 id="CamelTest-FeaturesProvidedbyCamelTestSupport">Features
Provided by <code>CamelTestSupport</code></h4><p>The
various <strong><code>CamelTestSupport</code></strong> classes provide a
standard set of behaviors relating to
the <strong><code>CamelContext</code></strong> used to host the route(s)
under test.  The classes provide a number of methods that allow a test to
alter the configuration of
the <strong><code>CamelContext</code></strong> used.  The following
table describes the available customization methods and the default behavior of
tests that are built from a <strong><code>CamelTestSupport</code></strong>
class.</p><div class="table-wrap"><table class="confluenceTable"><tbody><tr><th
colspan="1" rowspan="1" class="confluenceTh"><p>Method Name</p></th><th
colspan="1" rowspan="1" class="confluenceTh"><p>Description</p></th><th
colspan="1" rowspan="1" class="confluenceTh"><p>Default
Behavior</p></th></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>boolean isUseRouteBuilder()</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p>If the route builders returned
from either <strong><code>createRouteBuilder()</code></strong> or
<strong><code>createRouteBuilders()</code></strong> should be added to
the <strong><code>CamelContext</code></strong> for the test to be
started.</p></td><td colspan="1" rowspan="1" class="confluen
ceTd"><p>Returns
<strong><code>true</code></strong>. </p><p><strong><strong><code>createRouteBuilder()</code></strong>
or <strong><code>createRouteBuilders()</code></strong></strong> are invoked
and the <strong><code>CamelContext</code></strong> is started
automatically.</p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>boolean isUseAdviceWith()</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p>If
the <strong><code>CamelContext</code></strong> use in the test should be
automatically started before test methods are invoked.</p><p><br clear="none"
class="atl-forced-newline"> Override when using <a shape="rect"
href="advicewith.html">advice with</a> and return
<strong><code>true</code></strong>.  This helps in knowing
the <strong><code>adviceWith()</code></strong> is to be used, and
the <strong><code>CamelContext</code></strong> will not be started
before the advice with takes place. This delay helps by e
nsuring the advice with has been property setup before
the <strong><code>CamelContext</code></strong> is
started.</p><rich-text-body><p>Its important to start
the <strong><code>CamelContext</code></strong> manually from the unit test
after you are done doing all the advice with.</p></rich-text-body></td><td
colspan="1" rowspan="1" class="confluenceTd"><p>Returns
<strong><code>false</code></strong>. </p><p>The <strong><code>CamelContext</code></strong>
is started automatically before test methods are invoked.</p></td></tr><tr><td
colspan="1" rowspan="1" class="confluenceTd"><p><code>boolean
isCreateCamelContextPerClass()</code></p></td><td colspan="1" rowspan="1"
class="confluenceTd"><p>See <a shape="rect"
href="#CamelTest-SetupCamelContextonceperclass,orpereverytestmethod">Setup
CamelContext once per class, or per every test method</a>.</p></td><td
colspan="1" rowspan="1"
class="confluenceTd"><p>The <strong><code>CamelContext</code></strong> and
routes
are recreated for each test method.</p></td></tr><tr><td colspan="1"
rowspan="1" class="confluenceTd"><p><code>String
isMockEndpoints()</code></p></td><td colspan="1" rowspan="1"
class="confluenceTd"><p>Triggers the auto-mocking of endpoints whose URIs match
the provided filter.  The default filter
is <strong><code>null</code></strong> which disables this feature.
 </p><p>Return <strong><code>"*"</code></strong>  to match all
endpoints.
 </p><p>See <strong><code>org.apache.camel.impl.InterceptSendToMockEndpointStrategy</code></strong>
for more details on the registration of the mock endpoints.</p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p>Disabled</p></td></tr><tr><td
colspan="1" rowspan="1" class="confluenceTd"><p><code>boolean
isUseDebugger()</code></p></td><td colspan="1" rowspan="1"
class="confluenceTd"><p>If this method returns
<strong><code>true</code></strong>, the
methods:</p><ul><li><strong><code>debugBefore(Exchang
e exchange, Processor processor, ProcessorDefinition<?>
definition, String id, String label)</code></strong></li><li><strong>
<code>debugAfter(Exchange exchange, Processor processor,
ProcessorDefinition<?> definition, String id, String label, long
timeTaken)</code></strong></li></ul><p>are invoked for each processor in the
registered routes.</p></td><td colspan="1" rowspan="1"
class="confluenceTd"><p>Disabled</p><p>The methods are not invoked during the
test.</p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>int getShutdownTimeout()</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p>Returns the number of seconds
that Camel should wait for graceful shutdown.  </p><p>Useful for
decreasing test times when a message is still in flight at the end of the
test.</p></td><td colspan="1" rowspan="1" class="confluenceTd"><p>10
seconds</p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>boolean useJmx()</
code></p></td><td colspan="1" rowspan="1" class="confluenceTd"><p>If JMX
should be disabled on the <strong><code>CamelContext</code></strong> used
in the test.</p></td><td colspan="1" rowspan="1" class="confluenceTd"><p>JMX is
disabled</p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>JndiRegistry createRegistry()</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p>Provides a hook for adding
objects into the registry.  Override this method to bind objects to the
registry before test methods are invoked.</p></td><td colspan="1" rowspan="1"
class="confluenceTd"><p>An empty registry is initialized</p></td></tr><tr><td
colspan="1" rowspan="1"
class="confluenceTd"><p><code>useOverridePropertiesWithPropertiesComponent</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p><strong>Camel 2.10:</strong>
Allows to add/override properties when <a shape="rect"
href="using-propertyplaceholder.html">Using PropertyPlaceholder</a> in Cam
el.</p></td><td colspan="1" rowspan="1"
class="confluenceTd"><p><strong><code>null</code></strong></p></td></tr><tr><td
colspan="1" rowspan="1"
class="confluenceTd"><p><code>ignoreMissingLocationWithPropertiesComponent</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p><strong>Camel 2.10:</strong>
Allows to control if Camel should ignore missing locations for
properties.</p></td><td colspan="1" rowspan="1"
class="confluenceTd"><p><strong><code>null</code></strong></p></td></tr><tr><td
colspan="1" rowspan="1" class="confluenceTd"><p><code>boolean
isDumpRouteCoverage</code></p></td><td colspan="1" rowspan="1"
class="confluenceTd"><p><strong>Camel 2.16:</strong> If enabled, then Camel
will dump all route coverage statistics into XML files in the
target/camel-route-coverage directory. These XML files contains information
about "route coverage" of all the routes that was used during the unit test.
This allows tooling to inspect these XML files and generate nice route cove
rage reports.</p></td><td colspan="1" rowspan="1"
class="confluenceTd">Disabled</td></tr></tbody></table></div><h3
id="CamelTest-JNDI">JNDI</h3><p>Camel uses a <a shape="rect"
href="registry.html">Registry</a> to allow you to configure <a shape="rect"
href="component.html">Component</a> or <a shape="rect"
href="endpoint.html">Endpoint</a> instances or <a shape="rect"
href="bean-integration.html">Beans used in your routes</a>. If you are not
using <a shape="rect" href="spring.html">Spring</a> or <a shape="rect"
class="unresolved" href="#">OSGi</a> then <a shape="rect"
href="jndi.html">JNDI</a> is used as the default registry
implementation.</p><p>So you will also need to create
a <strong><code>jndi.properties</code></strong> file in
your <strong><code>src/test/resources</code></strong> directory so that
there is a default registry available to initialize the <a shape="rect"
href="camelcontext.html">CamelContext</a>.</p><p>Here is <a shape="rect"
class="external-link" href="
http://svn.apache.org/repos/asf/camel/trunk/components/camel-test/src/test/resources/jndi.properties">an
example jndi.properties
file</a></p><plain-text-body>java.naming.factory.initial =
org.apache.camel.util.jndi.CamelInitialContextFactory
+</plain-text-body><h3 id="CamelTest-DynamicallyAssigningPorts">Dynamically
Assigning Ports</h3><p><strong>Available as of Camel 2.7</strong></p><p>Tests
that use port numbers will fail if that port is already on use.
<strong><code>AvailablePortFinder</code></strong> provides methods for finding
unused port numbers at run time.</p><parameter
ac:name="language">java</parameter><plain-text-body>// Get the next available
port number starting from the default starting port of 1024
int port1 = AvailablePortFinder.getNextAvailable();
/*
* Get another port. Note that just getting a port number does not reserve it
so
* we look starting one past the last port number we got.
*/
int port2 = AvailablePortFinder.getNextAvailable(port1 + 1);
-]]></script>
-</div></div><h3
id="CamelTest-SetupCamelContextonceperclass,orpereverytestmethod">Setup
CamelContext once per class, or per every test method</h3><p><strong>Available
as of Camel 2.8</strong></p><p>The <a shape="rect" href="camel-test.html">Camel
Test</a> kit will by default setup and shutdown <a shape="rect"
href="camelcontext.html">CamelContext</a> per every test method in your test
class. So for example if you have 3 test methods, then <a shape="rect"
href="camelcontext.html">CamelContext</a> is started and shutdown after each
test, that is 3 times.</p><div class="confluence-information-macro
confluence-information-macro-tip"><p class="title">TestNG</p><span
class="aui-icon aui-icon-small aui-iconfont-approve
confluence-information-macro-icon"></span><div
class="confluence-information-macro-body"><p>This feature is also supported
in <strong><code>camel-testng</code></strong></p></div></div><div
class="confluence-information-macro confluence-information-macro-warning"><p
clas
s="title">Beware</p><span class="aui-icon aui-icon-small aui-iconfont-error
confluence-information-macro-icon"></span><div
class="confluence-information-macro-body"><p>When using this the <a
shape="rect" href="camelcontext.html">CamelContext</a> will keep state between
tests, so have that in mind. So if your unit tests start to fail for no
apparent reason, it could be due this fact. So use this feature with a bit of
care.</p></div></div><p>You may want to do this once, to share the <a
shape="rect" href="camelcontext.html">CamelContext</a> between test methods, to
speedup unit testing. This requires the use of JUnit 4! In your unit test
method you have to extend the
<strong><code>org.apache.camel.test.junit4.CamelTestSupport</code></strong> or
the
<strong><code>org.apache.camel.test.junit4.CamelSpringTestSupport</code></strong>
test class and override the
<strong><code>isCreateCamelContextPerClass</code></strong> method and return
<code>true</code> as shown in the following example:<
/p><div class="code panel pdl" style="border-width: 1px;"><div
class="codeHeader panelHeader pdl" style="border-bottom-width: 1px;"><b>Setup
CamelContext once per class</b></div><div class="codeContent panelContent pdl">
-<script class="brush: java; gutter: false; theme: Default"
type="syntaxhighlighter"><![CDATA[
-public class FilterCreateCamelContextPerClassTest extends CamelTestSupport {
-
- @Override
- public boolean isCreateCamelContextPerClass() {
- // we override this method and return true, to tell Camel test-kit that
- // it should only create CamelContext once (per class), so we will
- // re-use the CamelContext between each test method in this class
- return true;
- }
-
- @Test
- public void testSendMatchingMessage() throws Exception {
- String expectedBody = "<matched/>";
-
-
getMockEndpoint("mock:result").expectedBodiesReceived(expectedBody);
-
- template.sendBodyAndHeader("direct:start", expectedBody,
"foo", "bar");
-
- assertMockEndpointsSatisfied();
- }
-
- @Test
- public void testSendNotMatchingMessage() throws Exception {
- getMockEndpoint("mock:result").expectedMessageCount(0);
-
- template.sendBodyAndHeader("direct:start",
"<notMatched/>", "foo",
"notMatchedHeaderValue");
-
- assertMockEndpointsSatisfied();
- }
-
- @Override
- protected RouteBuilder createRouteBuilder() {
- return new RouteBuilder() {
- public void configure() {
-
from("direct:start").filter(header("foo").isEqualTo("bar")).to("mock:result");
- }
- };
- }
-}
-]]></script>
-</div></div><h3 id="CamelTest-SeeAlso">See Also</h3><ul><li><a shape="rect"
href="testing.html">Testing</a></li><li><a shape="rect"
href="mock.html">Mock</a></li><li><a shape="rect"
href="test.html">Test</a></li></ul><p> </p></div>
+</plain-text-body><h3
id="CamelTest-SetupCamelContextonceperclass,orpereverytestmethod">Setup
CamelContext once per class, or per every test method</h3><p><strong>Available
as of Camel 2.8</strong></p><p>The <a shape="rect" href="camel-test.html">Camel
Test</a> kit will by default setup and shutdown <a shape="rect"
href="camelcontext.html">CamelContext</a> per every test method in your test
class. So for example if you have 3 test methods, then <a shape="rect"
href="camelcontext.html">CamelContext</a> is started and shutdown after each
test, that is 3 times.</p><parameter
ac:name="title">TestNG</parameter><rich-text-body><p>This feature is also
supported
in <strong><code>camel-testng</code></strong></p></rich-text-body><parameter
ac:name="title">Beware</parameter><rich-text-body><p>When using this the <a
shape="rect" href="camelcontext.html">CamelContext</a> will keep state between
tests, so have that in mind. So if your unit tests start to fail for no
apparent reason, it could
be due this fact. So use this feature with a bit of
care.</p></rich-text-body><p>You may want to do this once, to share the <a
shape="rect" href="camelcontext.html">CamelContext</a> between test methods, to
speedup unit testing. This requires the use of JUnit 4! In your unit test
method you have to extend the
<strong><code>org.apache.camel.test.junit4.CamelTestSupport</code></strong> or
the
<strong><code>org.apache.camel.test.junit4.CamelSpringTestSupport</code></strong>
test class and override the
<strong><code>isCreateCamelContextPerClass</code></strong> method and return
<code>true</code> as shown in the following
example:<plain-text-body>{snippet:id=example|lang=java|title=Setup CamelContext
once per
class|url=camel/trunk/components/camel-test/src/test/java/org/apache/camel/test/patterns/FilterCreateCamelContextPerClassTest.java}</plain-text-body></p><h3
id="CamelTest-SeeAlso">See Also</h3><ul><li><a shape="rect"
href="testing.html">Testing</a></li><li><a shape="rect" href="moc
k.html">Mock</a></li><li><a shape="rect"
href="test.html">Test</a></li></ul><p> </p></div>
</td>
<td valign="top">
<div class="navigation">
Modified: websites/production/camel/content/camel-transport-for-cxf.html
==============================================================================
--- websites/production/camel/content/camel-transport-for-cxf.html (original)
+++ websites/production/camel/content/camel-transport-for-cxf.html Fri Aug 25
08:22:01 2017
@@ -36,17 +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 src='//camel.apache.org/styles/highlighter/scripts/shBrushPlain.js'
type='text/javascript'></script>
-
- <script type="text/javascript">
- SyntaxHighlighter.defaults['toolbar'] = false;
- SyntaxHighlighter.all();
- </script>
<title>
Apache Camel: Camel Transport for CXF
@@ -86,27 +75,24 @@
<tbody>
<tr>
<td valign="top" width="100%">
-<div class="wiki-content maincontent"><h2
id="CamelTransportforCXF-What'stheCamelTransportforCXF">What's the Camel
Transport for CXF</h2><p>In CXF you offer or consume a webservice by defining
its address. The first part of the address specifies the protocol to use. For
example address="http://localhost:9000" in an endpoint configuration means your
service will be offered using the http protocol on port 9000 of localhost. When
you integrate Camel Tranport into CXF you get a new transport "camel". So you
can specify address="camel://direct:MyEndpointName" to bind the CXF service
address to a camel direct endpoint.</p><p>Technically speaking Camel transport
for CXF is a component which implements the <a shape="rect"
class="external-link"
href="http://cwiki.apache.org/CXF20DOC/cxf-architecture.html#CXFArchitecture-Transports">CXF
transport API</a> with the Camel core library. This allows you to easily use
Camel's routing engine and integration patterns support together with your CXF
se
rvices.</p><h2
id="CamelTransportforCXF-IntegrateCamelintoCXFtransportlayer">Integrate Camel
into CXF transport layer</h2><p>To include the Camel Tranport into your CXF bus
you use the CamelTransportFactory. You can do this in Java as well as in
Spring.</p><h3
id="CamelTransportforCXF-SettinguptheCamelTransportinSpring">Setting up the
Camel Transport in Spring</h3><p>You can use the following snippet in your
applicationcontext if you want to configure anything special. If you only want
to activate the camel transport you do not have to do anything in your
application context. As soon as you include the camel-cxf-transport jar (or
camel-cxf.jar if your camel version is less than 2.7.x) in your app, cxf will
scan the jar and load a CamelTransportFactory for you.</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[<!-- you don't need to specify the
CamelTransportFactory configuration as it is auto load by CXF bus -->
-<bean
class="org.apache.camel.component.cxf.transport.CamelTransportFactory">
- <property name="bus" ref="cxf" />
- <property name="camelContext" ref="camelContext" />
+<div class="wiki-content maincontent"><h2
id="CamelTransportforCXF-What'stheCamelTransportforCXF">What's the Camel
Transport for CXF</h2><p>In CXF you offer or consume a webservice by defining
its address. The first part of the address specifies the protocol to use. For
example address="http://localhost:9000" in an endpoint configuration means your
service will be offered using the http protocol on port 9000 of localhost. When
you integrate Camel Tranport into CXF you get a new transport "camel". So you
can specify address="camel://direct:MyEndpointName" to bind the CXF service
address to a camel direct endpoint.</p><p>Technically speaking Camel transport
for CXF is a component which implements the <a shape="rect"
class="external-link"
href="http://cwiki.apache.org/CXF20DOC/cxf-architecture.html#CXFArchitecture-Transports">CXF
transport API</a> with the Camel core library. This allows you to easily use
Camel's routing engine and integration patterns support together with your CXF
se
rvices.</p><h2
id="CamelTransportforCXF-IntegrateCamelintoCXFtransportlayer">Integrate Camel
into CXF transport layer</h2><p>To include the Camel Tranport into your CXF bus
you use the CamelTransportFactory. You can do this in Java as well as in
Spring.</p><h3
id="CamelTransportforCXF-SettinguptheCamelTransportinSpring">Setting up the
Camel Transport in Spring</h3><p>You can use the following snippet in your
applicationcontext if you want to configure anything special. If you only want
to activate the camel transport you do not have to do anything in your
application context. As soon as you include the camel-cxf-transport jar (or
camel-cxf.jar if your camel version is less than 2.7.x) in your app, cxf will
scan the jar and load a CamelTransportFactory for you.</p><parameter
ac:name="">xml</parameter><plain-text-body><!-- you don't need to specify
the CamelTransportFactory configuration as it is auto load by CXF bus -->
+<bean
class="org.apache.camel.component.cxf.transport.CamelTransportFactory">
+ <property name="bus" ref="cxf" />
+ <property name="camelContext" ref="camelContext" />
<!-- checkException new added in Camel 2.1 and Camel 1.6.2 -->
- <!-- If checkException is true , CamelDestination will check the
outMessage's
+ <!-- If checkException is true , CamelDestination will check the
outMessage's
exception and set it into camel exchange. You can also override this
value
- in CamelDestination's configuration. The default value is false.
- This option should be set true when you want to leverage the camel's
error
+ in CamelDestination's configuration. The default value is false.
+ This option should be set true when you want to leverage the camel's
error
handler to deal with fault message -->
- <property name="checkException" value="true" />
- <property name="transportIds">
+ <property name="checkException" value="true" />
+ <property name="transportIds">
<list>
<value>http://cxf.apache.org/transports/camel</value>
</list>
</property>
</bean>
-]]></script>
-</div></div><h3
id="CamelTransportforCXF-IntegratingtheCamelTransportinaprogrammaticway">Integrating
the Camel Transport in a programmatic way</h3><p>Camel transport provides a
setContext method that you could use to set the Camel context into the
transport factory. If you want this factory take effect, you need to register
the factory into the CXF bus. Here is a full example for you.</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[import org.apache.cxf.Bus;
+</plain-text-body><h3
id="CamelTransportforCXF-IntegratingtheCamelTransportinaprogrammaticway">Integrating
the Camel Transport in a programmatic way</h3><p>Camel transport provides a
setContext method that you could use to set the Camel context into the
transport factory. If you want this factory take effect, you need to register
the factory into the CXF bus. Here is a full example for you.</p><parameter
ac:name="">java</parameter><plain-text-body>import org.apache.cxf.Bus;
import org.apache.cxf.BusFactory;
import org.apache.cxf.transport.ConduitInitiatorManager;
import org.apache.cxf.transport.DestinationFactoryManager;
@@ -129,106 +115,58 @@ DestinationFactoryManager dfm = bus.getE
dfm.registerDestinationFactory(CamelTransportFactory.TRANSPORT_ID,
camelTransportFactory);
// set or bus as the default bus for cxf
BusFactory.setDefaultBus(bus);
-]]></script>
-</div></div><h2
id="CamelTransportforCXF-ConfigurethedestinationandconduitwithSpring">Configure
the destination and conduit with Spring</h2><h3
id="CamelTransportforCXF-Namespace">Namespace</h3><p>The elements used to
configure an Camel transport endpoint are defined in the namespace <code><a
shape="rect"
href="http://cxf.apache.org/transports/camel">http://cxf.apache.org/transports/camel</a></code>.
It is commonly referred to using the prefix <code>camel</code>. In order to
use the Camel transport configuration elements, you will need to add the lines
shown below to the beans element of your endpoint's configuration file. In
addition, you will need to add the configuration elements' namespace to the
<code>xsi:schemaLocation</code> attribute.</p><div class="code panel pdl"
style="border-width: 1px;"><div class="codeHeader panelHeader pdl"
style="border-bottom-width: 1px;"><b>Adding the Configuration
Namespace</b></div><div class="codeContent panelContent pdl">
-<script class="brush: java; gutter: false; theme: Default"
type="syntaxhighlighter"><![CDATA[<beans ...
- xmlns:camel="http://cxf.apache.org/transports/camel
+</plain-text-body><h2
id="CamelTransportforCXF-ConfigurethedestinationandconduitwithSpring">Configure
the destination and conduit with Spring</h2><h3
id="CamelTransportforCXF-Namespace">Namespace</h3><p>The elements used to
configure an Camel transport endpoint are defined in the namespace <code><a
shape="rect"
href="http://cxf.apache.org/transports/camel">http://cxf.apache.org/transports/camel</a></code>.
It is commonly referred to using the prefix <code>camel</code>. In order to
use the Camel transport configuration elements, you will need to add the lines
shown below to the beans element of your endpoint's configuration file. In
addition, you will need to add the configuration elements' namespace to the
<code>xsi:schemaLocation</code> attribute.</p><parameter ac:name="title">Adding
the Configuration Namespace</parameter><plain-text-body><beans ...
+ xmlns:camel="http://cxf.apache.org/transports/camel
...
- xsi:schemaLocation="...
+ xsi:schemaLocation="...
http://cxf.apache.org/transports/camel
http://cxf.apache.org/transports/camel.xsd
...>
-]]></script>
-</div></div><h3 id="CamelTransportforCXF-Thedestinationelement">The
<code>destination</code> element</h3><p>You configure an Camel transport server
endpoint using the <code>camel:destination</code> element and its children. The
<code>camel:destination</code> element takes a single attribute,
<code>name</code>, that specifies the WSDL port element that corresponds to the
endpoint. The value for the <code>name</code> attribute takes the form
<em>portQName</em><code>.camel-destination</code>. The example below shows the
<code>camel:destination</code> element that would be used to add configuration
for an endpoint that was specified by the WSDL fragment <code><port
binding="widgetSOAPBinding" name="widgetSOAPPort"></code> if the endpoint's
target namespace was <code><a shape="rect" class="external-link"
href="http://widgets.widgetvendor.net"
rel="nofollow">http://widgets.widgetvendor.net</a></code>.</p><div class="code
panel pdl" style="border-width: 1px;"><div class="codeHeader p
anelHeader pdl" style="border-bottom-width: 1px;"><b>camel:destination
Element</b></div><div class="codeContent panelContent pdl">
-<script class="brush: java; gutter: false; theme: Default"
type="syntaxhighlighter"><![CDATA[...
- <camel:destination
name="{http://widgets/widgetvendor.net}widgetSOAPPort.http-destination>
- <camelContext id="context"
xmlns="http://activemq.apache.org/camel/schema/spring">
+</plain-text-body><h3 id="CamelTransportforCXF-Thedestinationelement">The
<code>destination</code> element</h3><p>You configure an Camel transport server
endpoint using the <code>camel:destination</code> element and its children. The
<code>camel:destination</code> element takes a single attribute,
<code>name</code>, that specifies the WSDL port element that corresponds to the
endpoint. The value for the <code>name</code> attribute takes the form
<em>portQName</em><code>.camel-destination</code>. The example below shows the
<code>camel:destination</code> element that would be used to add configuration
for an endpoint that was specified by the WSDL fragment <code><port
binding="widgetSOAPBinding" name="widgetSOAPPort"></code> if the endpoint's
target namespace was <code><a shape="rect" class="external-link"
href="http://widgets.widgetvendor.net"
rel="nofollow">http://widgets.widgetvendor.net</a></code>.</p><parameter
ac:name="title">camel:destination Element</parameter><plain-te
xt-body>...
+ <camel:destination
name="{http://widgets/widgetvendor.net}widgetSOAPPort.http-destination>
+ <camelContext id="context"
xmlns="http://activemq.apache.org/camel/schema/spring">
<route>
- <from uri="direct:EndpointC" />
- <to uri="direct:EndpointD" />
+ <from uri="direct:EndpointC" />
+ <to uri="direct:EndpointD" />
</route>
</camelContext>
</camel:destination>
<!-- new added feature since Camel 2.11.x
- <camel:destination
name="{http://widgets/widgetvendor.net}widgetSOAPPort.camel-destination"
camelContextId="context" />
+ <camel:destination
name="{http://widgets/widgetvendor.net}widgetSOAPPort.camel-destination"
camelContextId="context" />
...
-]]></script>
-</div></div><p>The <code>camel:destination</code> element for Spring has a
number of child elements that specify configuration information. They are
described below.</p><div class="table-wrap"><table
class="confluenceTable"><tbody><tr><th colspan="1" rowspan="1"
class="confluenceTh"><p>Element</p></th><th colspan="1" rowspan="1"
class="confluenceTh"><p>Description</p></th></tr><tr><td colspan="1"
rowspan="1"
class="confluenceTd"><p><code>camel-spring:camelContext</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p>You can specify the camel
context in the camel destination</p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>camel:camelContextRef</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p>The camel context id which you
want inject into the camel destination</p></td></tr></tbody></table></div><h3
id="CamelTransportforCXF-Theconduitelement">The <code>conduit</code>
element</h3><p>You configure a Camel transport client using t
he <code>camel:conduit</code> element and its children. The
<code>camel:conduit</code> element takes a single attribute, <code>name</code>,
that specifies the WSDL port element that corresponds to the endpoint. The
value for the <code>name</code> attribute takes the form
<em>portQName</em><code>.camel-conduit</code>. For example, the code below
shows the <code>camel:conduit</code> element that would be used to add
configuration for an endpoint that was specified by the WSDL fragment
<code><port binding="widgetSOAPBinding" name="widgetSOAPPort"></code> if
the endpoint's target namespace was <code><a shape="rect" class="external-link"
href="http://widgets.widgetvendor.net"
rel="nofollow">http://widgets.widgetvendor.net</a></code>.</p><div class="code
panel pdl" style="border-width: 1px;"><div class="codeHeader panelHeader pdl"
style="border-bottom-width: 1px;"><b>http-conf:conduit Element</b></div><div
class="codeContent panelContent pdl">
-<script class="brush: xml; gutter: false; theme: Default"
type="syntaxhighlighter"><![CDATA[...
- <camelContext id="conduit_context"
xmlns="http://activemq.apache.org/camel/schema/spring">
+</plain-text-body><p>The <code>camel:destination</code> element for Spring has
a number of child elements that specify configuration information. They are
described below.</p><div class="table-wrap"><table
class="confluenceTable"><tbody><tr><th colspan="1" rowspan="1"
class="confluenceTh"><p>Element</p></th><th colspan="1" rowspan="1"
class="confluenceTh"><p>Description</p></th></tr><tr><td colspan="1"
rowspan="1"
class="confluenceTd"><p><code>camel-spring:camelContext</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p>You can specify the camel
context in the camel destination</p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>camel:camelContextRef</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p>The camel context id which you
want inject into the camel destination</p></td></tr></tbody></table></div><h3
id="CamelTransportforCXF-Theconduitelement">The <code>conduit</code>
element</h3><p>You configure a Camel transport client u
sing the <code>camel:conduit</code> element and its children. The
<code>camel:conduit</code> element takes a single attribute, <code>name</code>,
that specifies the WSDL port element that corresponds to the endpoint. The
value for the <code>name</code> attribute takes the form
<em>portQName</em><code>.camel-conduit</code>. For example, the code below
shows the <code>camel:conduit</code> element that would be used to add
configuration for an endpoint that was specified by the WSDL fragment
<code><port binding="widgetSOAPBinding" name="widgetSOAPPort"></code> if
the endpoint's target namespace was <code><a shape="rect" class="external-link"
href="http://widgets.widgetvendor.net"
rel="nofollow">http://widgets.widgetvendor.net</a></code>.</p><parameter
ac:name="">xml</parameter><parameter ac:name="title">http-conf:conduit
Element</parameter><plain-text-body>...
+ <camelContext id="conduit_context"
xmlns="http://activemq.apache.org/camel/schema/spring">
<route>
- <from uri="direct:EndpointA" />
- <to uri="direct:EndpointB" />
+ <from uri="direct:EndpointA" />
+ <to uri="direct:EndpointB" />
</route>
</camelContext>
- <camel:conduit
name="{http://widgets/widgetvendor.net}widgetSOAPPort.camel-conduit">
+ <camel:conduit
name="{http://widgets/widgetvendor.net}widgetSOAPPort.camel-conduit">
<camel:camelContextRef>conduit_context</camel:camelContextRef>
</camel:conduit>
<!-- new added feature since Camel 2.11.x
- <camel:conduit
name="{http://widgets/widgetvendor.net}widgetSOAPPort.camel-conduit"
camelContextId="conduit_context" />
+ <camel:conduit
name="{http://widgets/widgetvendor.net}widgetSOAPPort.camel-conduit"
camelContextId="conduit_context" />
- <camel:conduit name="*.camel-conduit">
+ <camel:conduit name="*.camel-conduit">
<!-- you can also using the wild card to specify the camel-conduit that
you want to configure -->
...
</camel:conduit>
...
-]]></script>
-</div></div><p>The <code>camel:conduit</code> element has a number of child
elements that specify configuration information. They are described
below.</p><div class="table-wrap"><table class="confluenceTable"><tbody><tr><th
colspan="1" rowspan="1" class="confluenceTh"><p>Element</p></th><th colspan="1"
rowspan="1" class="confluenceTh"><p>Description</p></th></tr><tr><td
colspan="1" rowspan="1"
class="confluenceTd"><p><code>camel-spring:camelContext</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p>You can specify the camel
context in the camel conduit</p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>camel:camelContextRef</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p>The camel context id which you
want inject into the camel conduit</p></td></tr></tbody></table></div><h2
id="CamelTransportforCXF-ConfigurethedestinationandconduitwithBlueprint">Configure
the destination and conduit with Blueprint</h2><p>From <strong>Camel 2
.11.x</strong>, Camel Transport supports to be configured with
Blueprint.</p><p>If you are using blueprint, you should use the the namespace
<code><a shape="rect"
href="http://cxf.apache.org/transports/camel/blueprint">http://cxf.apache.org/transports/camel/blueprint</a></code>
and import the schema like the blow.</p><div class="code panel pdl"
style="border-width: 1px;"><div class="codeHeader panelHeader pdl"
style="border-bottom-width: 1px;"><b>Adding the Configuration Namespace for
blueprint</b></div><div class="codeContent panelContent pdl">
-<script class="brush: java; gutter: false; theme: Default"
type="syntaxhighlighter"><![CDATA[<beans ...
- xmlns:camel="http://cxf.apache.org/transports/camel/blueprint"
+</plain-text-body><p>The <code>camel:conduit</code> element has a number of
child elements that specify configuration information. They are described
below.</p><div class="table-wrap"><table class="confluenceTable"><tbody><tr><th
colspan="1" rowspan="1" class="confluenceTh"><p>Element</p></th><th colspan="1"
rowspan="1" class="confluenceTh"><p>Description</p></th></tr><tr><td
colspan="1" rowspan="1"
class="confluenceTd"><p><code>camel-spring:camelContext</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p>You can specify the camel
context in the camel conduit</p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>camel:camelContextRef</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p>The camel context id which you
want inject into the camel conduit</p></td></tr></tbody></table></div><h2
id="CamelTransportforCXF-ConfigurethedestinationandconduitwithBlueprint">Configure
the destination and conduit with Blueprint</h2><p>From <strong>C
amel 2.11.x</strong>, Camel Transport supports to be configured with
Blueprint.</p><p>If you are using blueprint, you should use the the namespace
<code><a shape="rect"
href="http://cxf.apache.org/transports/camel/blueprint">http://cxf.apache.org/transports/camel/blueprint</a></code>
and import the schema like the blow.</p><parameter ac:name="title">Adding the
Configuration Namespace for blueprint</parameter><plain-text-body><beans ...
+ xmlns:camel="http://cxf.apache.org/transports/camel/blueprint"
...
- xsi:schemaLocation="...
+ xsi:schemaLocation="...
http://cxf.apache.org/transports/camel/blueprint
http://cxf.apache.org/schmemas/blueprint/camel.xsd
...>
-]]></script>
-</div></div><p>In blueprint <code>camel:conduit</code>
<code>camel:destination</code> only has one camelContextId attribute, they
doesn't support to specify the camel context in the camel destination.</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[ <camel:conduit
id="*.camel-conduit" camelContextId="camel1" />
- <camel:destination id="*.camel-destination"
camelContextId="camel1" />
-]]></script>
-</div></div><h2
id="CamelTransportforCXF-ExampleUsingCamelasaloadbalancerforCXF">Example Using
Camel as a load balancer for CXF</h2><p>This example shows how to use the camel
load balancing feature in CXF. You need to load the configuration file in CXF
and publish the endpoints on the address "camel://direct:EndpointA" and
"camel://direct:EndpointB"</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"
- xmlns:camel="http://cxf.apache.org/transports/camel"
- xsi:schemaLocation="
- http://www.springframework.org/schema/beans
- http://www.springframework.org/schema/beans/spring-beans.xsd
- http://cxf.apache.org/transports/camel
http://cxf.apache.org/transports/camel.xsd
- http://camel.apache.org/schema/cxf
http://camel.apache.org/schema/cxf/cxfEndpoint.xsd
- http://camel.apache.org/schema/spring
http://camel.apache.org/schema/spring/camel-spring.xsd
- ">
-
- <!-- Enable bridge between Camel Property Placeholder and Spring
Property placeholder so we can use system properties
- to dynamically set the port number for unit testing the example. -->
- <bean id="bridgePropertyPlaceholder"
class="org.apache.camel.spring.spi.BridgePropertyPlaceholderConfigurer"/>
-
- <bean id="roundRobinRef"
class="org.apache.camel.processor.loadbalancer.RoundRobinLoadBalancer"
/>
-
- <camelContext id="dest_context"
xmlns="http://camel.apache.org/schema/spring">
- <route>
- <from
uri="jetty:http://localhost:{{port}}/GreeterContext/GreeterPort"/>
- <loadBalance>
- <custom ref="roundRobinRef"/>
- <to uri="direct:EndpointA"/>
- <to uri="direct:EndpointB"/>
- </loadBalance>
- </route>
- </camelContext>
-
- <!-- Inject the camel context to the Camel transport's destination
-->
- <camel:destination
name="{http://apache.org/hello_world_soap_http}CamelPort.camel-destination">
- <camel:camelContextRef>dest_context</camel:camelContextRef>
- </camel:destination>
-
-</beans>
-]]></script>
-</div></div><h2
id="CamelTransportforCXF-CompleteHowtoandExampleforattachingCameltoCXF">Complete
Howto and Example for attaching Camel to CXF</h2><p><a shape="rect"
href="better-jms-transport-for-cxf-webservice-using-apache-camel.html">Better
JMS Transport for CXF Webservice using Apache Camel</a> </p></div>
+</plain-text-body><p>In blueprint <code>camel:conduit</code>
<code>camel:destination</code> only has one camelContextId attribute, they
doesn't support to specify the camel context in the camel
destination.</p><plain-text-body> <camel:conduit id="*.camel-conduit"
camelContextId="camel1" />
+ <camel:destination id="*.camel-destination" camelContextId="camel1" />
+</plain-text-body><h2
id="CamelTransportforCXF-ExampleUsingCamelasaloadbalancerforCXF">Example Using
Camel as a load balancer for CXF</h2><p>This example shows how to use the camel
load balancing feature in CXF. You need to load the configuration file in CXF
and publish the endpoints on the address "camel://direct:EndpointA" and
"camel://direct:EndpointB"</p><plain-text-body>{snippet:id=example|lang=xml|url=camel/trunk/examples/camel-example-cxf/src/main/resources/org/apache/camel/example/camel/transport/CamelDestination.xml}</plain-text-body><h2
id="CamelTransportforCXF-CompleteHowtoandExampleforattachingCameltoCXF">Complete
Howto and Example for attaching Camel to CXF</h2><p><a shape="rect"
href="better-jms-transport-for-cxf-webservice-using-apache-camel.html">Better
JMS Transport for CXF Webservice using Apache Camel</a> </p></div>
</td>
<td valign="top">
<div class="navigation">
Modified: websites/production/camel/content/claim-check.html
==============================================================================
--- websites/production/camel/content/claim-check.html (original)
+++ websites/production/camel/content/claim-check.html Fri Aug 25 08:22:01 2017
@@ -36,17 +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 src='//camel.apache.org/styles/highlighter/scripts/shBrushPlain.js'
type='text/javascript'></script>
-
- <script type="text/javascript">
- SyntaxHighlighter.defaults['toolbar'] = false;
- SyntaxHighlighter.all();
- </script>
<title>
Apache Camel: Claim Check
@@ -100,48 +89,29 @@
<p><strong>Using the <a shape="rect" href="fluent-builders.html">Fluent
Builders</a></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("bean:checkLuggage",
"mock:testCheckpoint", "bean:dataEnricher",
"mock:result");
-]]></script>
-</div></div>
+<plain-text-body>{snippet:id=e1|lang=java|url=camel/trunk/camel-core/src/test/java/org/apache/camel/processor/ClaimCheckTest.java}</plain-text-body>
<p><strong>Using the <a shape="rect" href="spring-xml-extensions.html">Spring
XML Extensions</a></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[
+<parameter ac:name="">xml</parameter><plain-text-body>
<route>
- <from uri="direct:start"/>
+ <from uri="direct:start"/>
<pipeline>
- <to uri="bean:checkLuggage"/>
- <to uri="mock:testCheckpoint"/>
- <to uri="bean:dataEnricher"/>
- <to uri="mock:result"/>
+ <to uri="bean:checkLuggage"/>
+ <to uri="mock:testCheckpoint"/>
+ <to uri="bean:dataEnricher"/>
+ <to uri="mock:result"/>
</pipeline>
</route>
-]]></script>
-</div></div>
+</plain-text-body>
<p>The example route is pretty simple - its just a <a shape="rect"
href="pipes-and-filters.html">Pipeline</a>. In a real application you would
have some other steps where the <code>mock:testCheckpoint</code> endpoint is in
the example.</p>
<p>The message is first sent to the <code>checkLuggage</code> bean which looks
like</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 static final class CheckLuggageBean {
- public void checkLuggage(Exchange exchange, @Body String body,
@XPath("/order/@custId") String custId) {
- // store the message body into the data store, using the custId as the
claim check
- dataStore.put(custId, body);
- // add the claim check as a header
- exchange.getIn().setHeader("claimCheck", custId);
- // remove the body from the message
- exchange.getIn().setBody(null);
- }
-}
-]]></script>
-</div></div>
+<plain-text-body>{snippet:id=e2|lang=java|url=camel/trunk/camel-core/src/test/java/org/apache/camel/processor/ClaimCheckTest.java}</plain-text-body>
<p>This bean stores the message body into the data store, using the
<code>custId</code> as the claim check. In this example, we're just using a
<code>HashMap</code> to store the message body; in a real application you would
use a database or file system, etc. Next the claim check is added as a message
header for use later. Finally we remove the body from the message and pass it
down the pipeline. </p>
@@ -149,21 +119,7 @@ public static final class CheckLuggageBe
<p>To add the message body back into the message, we use the
<code>dataEnricher</code> bean which looks like</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 static final class DataEnricherBean {
- public void addDataBackIn(Exchange exchange,
@Header("claimCheck") String claimCheck) {
- // query the data store using the claim check as the key and add the
data
- // back into the message body
- exchange.getIn().setBody(dataStore.get(claimCheck));
- // remove the message data from the data store
- dataStore.remove(claimCheck);
- // remove the claim check header
- exchange.getIn().removeHeader("claimCheck");
- }
-}
-]]></script>
-</div></div>
+<plain-text-body>{snippet:id=e3|lang=java|url=camel/trunk/camel-core/src/test/java/org/apache/camel/processor/ClaimCheckTest.java}</plain-text-body>
<p>This bean queries the data store using the claim check as the key and then
adds the data back into the message. The message body is then removed from the
data store and finally the claim check is removed. Now the message is back to
what we started with!</p>
@@ -172,9 +128,7 @@ public static final class DataEnricherBe
<p><a shape="rect" class="external-link"
href="http://svn.apache.org/repos/asf/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/ClaimCheckTest.java">camel-core/src/test/java/org/apache/camel/processor/ClaimCheckTest.java</a></p>
-<h4 id="ClaimCheck-UsingThisPattern">Using This Pattern</h4>
-
-<p>If you would like to use this EIP Pattern then please read the <a
shape="rect" href="getting-started.html">Getting Started</a>, you may also find
the <a shape="rect" href="architecture.html">Architecture</a> useful
particularly the description of <a shape="rect"
href="endpoint.html">Endpoint</a> and <a shape="rect"
href="uris.html">URIs</a>. Then you could try out some of the <a shape="rect"
href="examples.html">Examples</a> first before trying this pattern
out.</p></div>
+<parameter ac:name=""><a shape="rect" href="using-this-pattern.html">Using
This Pattern</a></parameter></div>
</td>
<td valign="top">
<div class="navigation">
Modified: websites/production/camel/content/configuring-camel.html
==============================================================================
--- websites/production/camel/content/configuring-camel.html (original)
+++ websites/production/camel/content/configuring-camel.html Fri Aug 25
08:22:01 2017
@@ -36,17 +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 src='//camel.apache.org/styles/highlighter/scripts/shBrushPlain.js'
type='text/javascript'></script>
-
- <script type="text/javascript">
- SyntaxHighlighter.defaults['toolbar'] = false;
- SyntaxHighlighter.all();
- </script>
<title>
Apache Camel: Configuring Camel
@@ -88,31 +77,11 @@
<td valign="top" width="100%">
<div class="wiki-content maincontent"><div class="error"><span
class="error">Unable to render {include}</span> The included page could not be
found.</div>
<div class="error"><span class="error">Unable to render {include}</span> The
included page could not be found.</div>
-<h2 id="ConfiguringCamel-HowdoIaddacomponent">How do I add a
component</h2><p>You might first want to read <a shape="rect"
href="writing-components.html">Writing Components</a> for a background in how
to implement a new component.<br clear="none"> Typically it means you write an
implementation of the <a shape="rect" class="external-link"
href="http://camel.apache.org/maven/current/camel-core/apidocs/org/apache/camel/Component.html">Component</a>
interface, usually deriving from <a shape="rect" class="external-link"
href="http://camel.apache.org/maven/current/camel-core/apidocs/org/apache/camel/impl/DefaultComponent.html">DefaultComponent</a>.</p><p>You
can then register your component explicitly via</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 context = new
DefaultCamelContext();
-context.addComponent("foo", new FooComponent(context));
-]]></script>
-</div></div><p>However you can use the auto-discovery feature of Camel where
by Camel will automatically add a <a shape="rect"
href="component.html">Component</a> when an endpoint URI is used. To do this
you would create a file called</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[/META-INF/services/org/apache/camel/component/foo
-]]></script>
-</div></div><p>with contents</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[class=org.acme.FooComponent
-]]></script>
-</div></div><p>(you can add other property configurations in there too if you
like)</p><p>Then if you refer to an endpoint as
<strong><code>foo://somethingOrOther</code></strong> Camel will auto-discover
your component and register
it.</p><p>The <strong><code>FooComponent</code></strong> can then be
auto-injected with resources using the <a shape="rect" class="external-link"
href="http://camel.apache.org/maven/current/camel-core/apidocs/org/apache/camel/spi/Injector.html">Injector</a>,
such as to support <a shape="rect" href="spring.html">Spring</a> based
auto-wiring, or to support <strong><code>@Resource</code></strong> (EJB3
style) injection or Guice style <strong><code>@Inject</code></strong>
injection.</p><h3 id="ConfiguringCamel-WorkingwithSpringXML">Working with
Spring XML</h3><p>You can configure a component via Spring using the following
mechanism...</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 id="camel"
xmlns="http://camel.apache.org/schema/spring">
- <jmxAgent id="agent" disabled="true"/>
-</camelContext>
-
-<bean id="activemq"
class="org.apache.activemq.camel.component.ActiveMQComponent">
- <property name="connectionFactory">
- <bean
class="org.apache.activemq.ActiveMQConnectionFactory">
- <property name="brokerURL"
value="vm://localhost?broker.persistent=false&amp;broker.useJmx=false"/>
- </bean>
- </property>
-</bean>
-]]></script>
-</div></div>Which allows you to configure a component using some name
(activemq in the above example), then you can refer to the component using
<strong><code>activemq:[queue:|topic:]destinationName</code></strong>.<p>If you
want to add explicit Spring 2.x XML objects to your XML then you could use
the <strong><code>xbean-spring</code></strong> which tries to automate
most of the XML binding work for you; or you could look in camel-spring
at <strong><code>CamelNamespaceHandler</code></strong> you'll see how we
handle the Spring XML stuff (warning its kinda hairy code to look at <img
class="emoticon emoticon-smile"
src="https://cwiki.apache.org/confluence/s/en_GB/5997/6f42626d00e36f53fe51440403446ca61552e2a2.1/_/images/icons/emoticons/smile.png"
data-emoticon-name="smile" alt="(smile)">. If you
wanted <strong><code><fooComponent></code></strong> to be a standard
part of the core Camel schema then you'd hack that file to add your component
& <a shape="rect" hr
ef="contributing.html">conftribute a patch</a> to the camel XSD. Otherwise you
could write your own namespace & schema if you prefer.</p><h3
id="ConfiguringCamel-SeeAlso">See Also</h3><ul><li><a shape="rect"
href="writing-components.html">Writing Components</a></li><li><a shape="rect"
href="how-do-i-configure-endpoints.html">How Do I Configure
Endpoints?</a></li></ul></div>
+<h2 id="ConfiguringCamel-HowdoIaddacomponent">How do I add a
component</h2><p>You might first want to read <a shape="rect"
href="writing-components.html">Writing Components</a> for a background in how
to implement a new component.<br clear="none"> Typically it means you write an
implementation of the <a shape="rect" class="external-link"
href="http://camel.apache.org/maven/current/camel-core/apidocs/org/apache/camel/Component.html">Component</a>
interface, usually deriving from <a shape="rect" class="external-link"
href="http://camel.apache.org/maven/current/camel-core/apidocs/org/apache/camel/impl/DefaultComponent.html">DefaultComponent</a>.</p><p>You
can then register your component explicitly
via</p><plain-text-body>CamelContext context = new DefaultCamelContext();
+context.addComponent("foo", new FooComponent(context));
+</plain-text-body><p>However you can use the auto-discovery feature of Camel
where by Camel will automatically add a <a shape="rect"
href="component.html">Component</a> when an endpoint URI is used. To do this
you would create a file
called</p><plain-text-body>/META-INF/services/org/apache/camel/component/foo
+</plain-text-body><p>with
contents</p><plain-text-body>class=org.acme.FooComponent
+</plain-text-body><p>(you can add other property configurations in there too
if you like)</p><p>Then if you refer to an endpoint as
<strong><code>foo://somethingOrOther</code></strong> Camel will auto-discover
your component and register
it.</p><p>The <strong><code>FooComponent</code></strong> can then be
auto-injected with resources using the <a shape="rect" class="external-link"
href="http://camel.apache.org/maven/current/camel-core/apidocs/org/apache/camel/spi/Injector.html">Injector</a>,
such as to support <a shape="rect" href="spring.html">Spring</a> based
auto-wiring, or to support <strong><code>@Resource</code></strong> (EJB3
style) injection or Guice style <strong><code>@Inject</code></strong>
injection.</p><h3 id="ConfiguringCamel-WorkingwithSpringXML">Working with
Spring XML</h3><p>You can configure a component via Spring using the following
mechanism...<plain-text-body>{snippet:id=example|lang=xml|url=camel/trunk/components/camel-jms/src/test/resources/org/
apache/camel/component/jms/jmsRouteUsingSpring.xml}</plain-text-body>Which
allows you to configure a component using some name (activemq in the above
example), then you can refer to the component using
<strong><code>activemq:[queue:|topic:]destinationName</code></strong>.</p><p>If
you want to add explicit Spring 2.x XML objects to your XML then you could use
the <strong><code>xbean-spring</code></strong> which tries to automate
most of the XML binding work for you; or you could look in camel-spring
at <strong><code>CamelNamespaceHandler</code></strong> you'll see how we
handle the Spring XML stuff (warning its kinda hairy code to look at <img
class="emoticon emoticon-smile"
src="https://cwiki.apache.org/confluence/s/en_GB/5997/6f42626d00e36f53fe51440403446ca61552e2a2.1/_/images/icons/emoticons/smile.png"
data-emoticon-name="smile" alt="(smile)">. If you
wanted <strong><code><fooComponent></code></strong> to be a standard
part of the core Camel schema then you'd
hack that file to add your component & <a shape="rect"
href="contributing.html">conftribute a patch</a> to the camel XSD. Otherwise
you could write your own namespace & schema if you prefer.</p><h3
id="ConfiguringCamel-SeeAlso">See Also</h3><ul><li><a shape="rect"
href="writing-components.html">Writing Components</a></li><li><a shape="rect"
href="how-do-i-configure-endpoints.html">How Do I Configure
Endpoints?</a></li></ul></div>
</td>
<td valign="top">
<div class="navigation">
Modified: websites/production/camel/content/console-example.html
==============================================================================
--- websites/production/camel/content/console-example.html (original)
+++ websites/production/camel/content/console-example.html Fri Aug 25 08:22:01
2017
@@ -36,17 +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 src='//camel.apache.org/styles/highlighter/scripts/shBrushPlain.js'
type='text/javascript'></script>
-
- <script type="text/javascript">
- SyntaxHighlighter.defaults['toolbar'] = false;
- SyntaxHighlighter.all();
- </script>
<title>
Apache Camel: Console Example
@@ -96,52 +85,31 @@
<p>In this example we integrate with the console using the <a shape="rect"
href="stream.html">Stream</a> component. The example is interactive - it reads
input from the console, and then transforms the input to upper case and prints
it back to the console. </p>
<p>This is implemented with a Camel route defined in the Spring XML markup
shown below: </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 is the Camel runtime, where we can host Camel routes
-->
-<camelContext xmlns="http://camel.apache.org/schema/spring">
- <route>
- <!-- read input from the console using the stream component -->
- <from uri="stream:in?promptMessage=Enter something: "/>
- <!-- transform the input to upper case using the simple language -->
- <!-- you can also use other languages such as groovy, ognl, mvel,
javascript etc. -->
- <transform>
- <simple>${body.toUpperCase()}</simple>
- </transform>
- <!-- and then print to the console -->
- <to uri="stream:out"/>
- </route>
-</camelContext>
-]]></script>
-</div></div>
+<plain-text-body>{snippet:id=e1|lang=xml|url=camel/trunk/examples/camel-example-console/src/main/resources/META-INF/spring/camel-context.xml}</plain-text-body>
<p>This example can be launched from the command line using Maven:</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[
+<plain-text-body>
mvn compile exec:java
-]]></script>
-</div></div>
+</plain-text-body>
<p>In the console you can enter a message and press <ENTER>. Camel
responds by echoing the input message in upper case, as shown below:</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[
+<plain-text-body>
[onsole.CamelConsoleMain.main()] SpringCamelContext INFO Apache
Camel 2.10 (CamelContext: camel-1) started in 0.455 seconds
Enter something: camel rocks
CAMEL ROCKS
Enter something: and we have fun
AND WE HAVE FUN
Enter something:
-]]></script>
-</div></div>
+</plain-text-body>
<p>To stop the example, strike Control+C </p>
<p>You can also run this example from your editor. For example, from Eclipse
you can import this project using: File → Import … → Existing
Maven Project, and select <code>pom.xml</code> from the
<code>examples\camel-example-console</code> directory.</p>
<p>Next, navigate to the
<code>org.apache.camel.example.console.CamelConsoleMain</code> class,
right-click, and select Run As → Java Application.</p>
-<div class="confluence-information-macro
confluence-information-macro-tip"><span class="aui-icon aui-icon-small
aui-iconfont-approve confluence-information-macro-icon"></span><div
class="confluence-information-macro-body">
-<p>Click on the screenshot below, to make it bigger.</p></div></div>
-<p><span class="confluence-embedded-file-wrapper"><img
class="confluence-embedded-image confluence-thumbnail"
src="console-example.thumbs/run-as.png"
data-image-src="/confluence/download/attachments/27843710/run-as.png?version=1&modificationDate=1334026057000&api=v2"
data-unresolved-comment-count="0" data-linked-resource-id="28017569"
data-linked-resource-version="1" data-linked-resource-type="attachment"
data-linked-resource-default-alias="run-as.png"
data-base-url="https://cwiki.apache.org/confluence"
data-linked-resource-content-type="image/png"
data-linked-resource-container-id="27843710"
data-linked-resource-container-version="20"></span></p>
+<rich-text-body>
+<p>Click on the screenshot below, to make it bigger.</p></rich-text-body>
+<p><span class="confluence-embedded-file-wrapper"><img
class="confluence-embedded-image confluence-thumbnail"
src="console-example.thumbs/run-as.png"
data-image-src="/confluence/download/attachments/27843710/run-as.png?version=1&modificationDate=1334026057000&api=v2"
data-unresolved-comment-count="0" data-linked-resource-id="28017569"
data-linked-resource-version="1" data-linked-resource-type="attachment"
data-linked-resource-default-alias="run-as.png"
data-base-url="https://cwiki.apache.org/confluence"
data-linked-resource-content-type="image/png"
data-linked-resource-container-id="27843710"
data-linked-resource-container-version="21"></span></p>
<h3 id="ConsoleExample-Seealso">See also</h3>