Modified: websites/production/camel/content/intercept.html
==============================================================================
--- websites/production/camel/content/intercept.html (original)
+++ websites/production/camel/content/intercept.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: Intercept
@@ -86,268 +75,30 @@
<tbody>
<tr>
<td valign="top" width="100%">
-<div class="wiki-content maincontent"><h2
id="Intercept-Intercept">Intercept</h2><p>The intercept feature in Camel
supports intercepting <a shape="rect" href="exchange.html">Exchange</a>s while
they are <em>en route</em>.  We have overhauled the <a shape="rect"
href="intercept.html">Intercept</a> in Camel 2.0 so the following information
is based on Camel 2.0.</p><p>Camel supports three kinds of interceptors:</p><ul
class="alternate"><li><strong><code>intercept</code></strong> that intercepts
each and every processing step while routing an <a shape="rect"
href="exchange.html">Exchange</a> in the
route.</li><li><strong><code>interceptFrom</code></strong> that intercepts
incoming <a shape="rect" href="exchange.html">Exchange</a> in the
route.</li><li><strong><code>interceptSendToEndpoint</code></strong> that
intercepts when an <a shape="rect" href="exchange.html">Exchange</a> is about
to be sent to the given <a shape="rect"
href="endpoint.html">Endpoint</a>.</li></ul><p>These int
erceptors supports the following features:</p><ul class="alternate"><li><a
shape="rect" href="predicate.html">Predicate</a> using <code>when</code> to
only trigger the interceptor in certain
conditions</li><li><strong><code>stop</code></strong> forces to stop continue
routing the <a shape="rect" href="exchange.html">Exchange</a> and mark it as
completed successful. Camel will by default <strong>not
stop</strong>.</li><li><strong><code>skip</code></strong> when used with
<strong><code>interceptSendToEndpoint</code></strong> will
<strong>skip</strong> routing the <a shape="rect"
href="exchange.html">Exchange</a> to the original endpoint. Camel will by
default <strong>not
skip</strong>.</li><li><strong><code>interceptFrom</code></strong> and
<strong><code>interceptSendToEndpoint</code></strong> supports endpoint URI
matching by: exact URI, wildcard, regular expression. See advanced
section.</li><li>The intercepted endpoint URI is stored as message header
<strong><code>Exchange.INTERCEP
TED_ENDPOINT</code></strong>.</li></ul><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><strong><code>stop</code></strong>
can be used in general, it does not have to be used with an <a shape="rect"
href="intercept.html">Intercept</a> you can use it in regular routing as
well.</p><p>You can also instruct Camel to <code>stop</code> continue routing
your message if you set the <strong><code>Exchange.ROUTE_STOP</code></strong>
property to <code><strong>true</strong></code> or
<strong><code>Boolean.TRUE</code></strong> on the <a shape="rect"
href="exchange.html">Exchange</a>. You can for instance do this from regular
Java code in a <a shape="rect" href="pojo.html">Pojo</a> or <a shape="rect"
href="processor.html">Processor</a>.</p></div></div><h3
id="Intercept-Intercept.1"><code>Intercept</code></h3><p><strong><co
de>Intercept</code></strong> is like a regular interceptor that is applied on
each processing step the <a shape="rect" href="exchange.html">Exchange</a>
undergo while its being routed. You can think of it as a <em>AOP before</em>
that is applied at each DSL keyword you have defined in your route.</p><p>The
classic Hello World example is:</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[intercept()
- .to("log:hello");
+<div class="wiki-content maincontent"><h2
id="Intercept-Intercept">Intercept</h2><p>The intercept feature in Camel
supports intercepting <a shape="rect" href="exchange.html">Exchange</a>s while
they are <em>en route</em>.  We have overhauled the <a shape="rect"
href="intercept.html">Intercept</a> in Camel 2.0 so the following information
is based on Camel 2.0.</p><p>Camel supports three kinds of interceptors:</p><ul
class="alternate"><li><strong><code>intercept</code></strong> that intercepts
each and every processing step while routing an <a shape="rect"
href="exchange.html">Exchange</a> in the
route.</li><li><strong><code>interceptFrom</code></strong> that intercepts
incoming <a shape="rect" href="exchange.html">Exchange</a> in the
route.</li><li><strong><code>interceptSendToEndpoint</code></strong> that
intercepts when an <a shape="rect" href="exchange.html">Exchange</a> is about
to be sent to the given <a shape="rect"
href="endpoint.html">Endpoint</a>.</li></ul><p>These int
erceptors supports the following features:</p><ul class="alternate"><li><a
shape="rect" href="predicate.html">Predicate</a> using <code>when</code> to
only trigger the interceptor in certain
conditions</li><li><strong><code>stop</code></strong> forces to stop continue
routing the <a shape="rect" href="exchange.html">Exchange</a> and mark it as
completed successful. Camel will by default <strong>not
stop</strong>.</li><li><strong><code>skip</code></strong> when used with
<strong><code>interceptSendToEndpoint</code></strong> will
<strong>skip</strong> routing the <a shape="rect"
href="exchange.html">Exchange</a> to the original endpoint. Camel will by
default <strong>not
skip</strong>.</li><li><strong><code>interceptFrom</code></strong> and
<strong><code>interceptSendToEndpoint</code></strong> supports endpoint URI
matching by: exact URI, wildcard, regular expression. See advanced
section.</li><li>The intercepted endpoint URI is stored as message header
<strong><code>Exchange.INTERCEP
TED_ENDPOINT</code></strong>.</li></ul><parameter
ac:name="tile">stop</parameter><rich-text-body><p><strong><code>stop</code></strong>
can be used in general, it does not have to be used with an <a shape="rect"
href="intercept.html">Intercept</a> you can use it in regular routing as
well.</p><p>You can also instruct Camel to <code>stop</code> continue routing
your message if you set the <strong><code>Exchange.ROUTE_STOP</code></strong>
property to <code><strong>true</strong></code> or
<strong><code>Boolean.TRUE</code></strong> on the <a shape="rect"
href="exchange.html">Exchange</a>. You can for instance do this from regular
Java code in a <a shape="rect" href="pojo.html">Pojo</a> or <a shape="rect"
href="processor.html">Processor</a>.</p></rich-text-body><h3
id="Intercept-Intercept.1"><code>Intercept</code></h3><p><strong><code>Intercept</code></strong>
is like a regular interceptor that is applied on each processing step the <a
shape="rect" href="exchange.html">Exchange</a> underg
o while its being routed. You can think of it as a <em>AOP before</em> that is
applied at each DSL keyword you have defined in your route.</p><p>The classic
Hello World example is:</p><plain-text-body>intercept()
+ .to("log:hello");
-from("jms:queue:order")
- .to("bean:validateOrder")
- .to("bean:processOrder");
-]]></script>
-</div></div><p>What happens is that the <a shape="rect"
href="exchange.html">Exchange</a> is intercepted before each processing step,
that means that it will be intercepted before:</p><ul
class="alternate"><li><code>.to("bean:validateOrder")</code></li><li><code>.to("bean:processOrder")</code></li></ul><p>So
in this sample we intercept the <a shape="rect"
href="exchange.html">Exchange</a> twice.</p><p>The <code>when</code> predicate
is also support on the <strong><code>intercept</code></strong> so we can attach
a <a shape="rect" href="predicate.html">Predicate</a> to only trigger the
interception under certain conditions. For instance in the sample below we only
intercept if the message body contains the string word
<strong><code>Hello</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[
-intercept().when(body().contains("Hello")).to("mock:intercepted");
-
-from("direct:start")
- .to("mock:foo", "mock:bar", "mock:result");
-]]></script>
-</div></div>And in the route below we want to stop in certain conditions, when
the message contains the word
<strong><strong><code>Hello</code></strong></strong>:<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[
-intercept().when(body().contains("Hello")).to("mock:intercepted").stop();
-
-from("direct:start")
- .to("mock:foo", "mock:bar", "mock:result");
-]]></script>
-</div></div><h4 id="Intercept-UsingfromSpringDSL">Using from Spring
DSL</h4><p>The same hello world sample in Spring DSL would be:</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>
- <intercept>
- <to uri="log:hello"/>
- </intercept>
-
- <route>
- <from uri="jms:queue:order"/>
- <to uri="bean:validateOrder"/>
- <to uri="bean:handleOrder"/>
- </route>
-</camelContext>
-]]></script>
-</div></div><p>And the sample for using
the <strong><code>when()</code></strong> predicate would be:</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://camel.apache.org/schema/spring">
- <!-- here we intercept each processing step in the routing and do a
detour
- routing where we route the exhange to the mock:intercepted endpoint.
- We have applied a when predicate so the interceptor only applies
- if the message body contains the string word 'Hello' -->
- <intercept>
- <when>
- <simple>${in.body} contains 'Hello'</simple>
- </when>
- <to uri="mock:intercepted"/>
- </intercept>
-
- <!-- here we have a very simple route -->
- <route>
- <from uri="direct:start"/>
- <to uri="mock:foo"/>
- <to uri="mock:bar"/>
- <to uri="mock:result"/>
- </route>
-</camelContext>
-]]></script>
-</div></div>And the sample for using
the <strong><code>when()</code></strong>
and <strong><code>stop()</code></strong> would be:<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://camel.apache.org/schema/spring">
+from("jms:queue:order")
+ .to("bean:validateOrder")
+ .to("bean:processOrder");
+</plain-text-body><p>What happens is that the <a shape="rect"
href="exchange.html">Exchange</a> is intercepted before each processing step,
that means that it will be intercepted before:</p><ul
class="alternate"><li><code>.to("bean:validateOrder")</code></li><li><code>.to("bean:processOrder")</code></li></ul><p>So
in this sample we intercept the <a shape="rect"
href="exchange.html">Exchange</a> twice.</p><p>The <code>when</code> predicate
is also support on the <strong><code>intercept</code></strong> so we can attach
a <a shape="rect" href="predicate.html">Predicate</a> to only trigger the
interception under certain conditions. For instance in the sample below we only
intercept if the message body contains the string word
<strong><code>Hello</code></strong>:<plain-text-body>{snippet:id=e1|lang=java|url=camel/trunk/camel-core/src/test/java/org/apache/camel/processor/intercept/InterceptSimpleRouteWhenTest.java}</plain-text-body>And
in the route below we want to stop in certain conditi
ons, when the message contains the word
<strong><strong><code>Hello</code></strong></strong>:<plain-text-body>{snippet:id=e1|lang=java|url=camel/trunk/camel-core/src/test/java/org/apache/camel/processor/intercept/InterceptSimpleRouteWhenStopTest.java}</plain-text-body></p><h4
id="Intercept-UsingfromSpringDSL">Using from Spring DSL</h4><p>The same hello
world sample in Spring DSL would be:</p><parameter
ac:name="">xml</parameter><plain-text-body><camelContext>
<intercept>
- <!-- only trigger this interceptor if the message body contains the
word Hello -->
- <when>
- <simple>${in.body} contains 'Hello'</simple>
- </when>
- <to uri="mock:intercepted"/>
- <!-- stop continue routing -->
- <stop/>
+ <to uri="log:hello"/>
</intercept>
- <!-- here we have a very simple route -->
- <route>
- <from uri="direct:start"/>
- <to uri="mock:foo"/>
- <to uri="mock:bar"/>
- <to uri="mock:result"/>
- </route>
-</camelContext>
-]]></script>
-</div></div><h3
id="Intercept-InterceptFrom"><code>InterceptFrom</code></h3><p><strong><code>InterceptFrom</code></strong>
is for intercepting any incoming <a shape="rect"
href="exchange.html">Exchange</a>, in any route (it intercepts all the
<code>from</code> DSLs). This allows you to do some custom behavior for
received <a shape="rect" href="exchange.html">Exchange</a>s. You can provide a
specific URI for a given <a shape="rect" href="endpoint.html">Endpoint</a> then
it only applies for that particular route.</p><p>So lets start with the logging
example. We want to log all the <strong>incoming</strong> requests so we use
<strong><code>interceptFrom</code></strong> to route to the <a shape="rect"
href="log.html">Log</a> component. As <code>proceed</code> is default then the
<a shape="rect" href="exchange.html">Exchange</a> will continue its route, and
thus it will continue to <strong><code>mock:first</code></strong>.</p><div
class="code panel pdl" style="border-width: 1px;"><div cl
ass="codeContent panelContent pdl">
-<script class="brush: java; gutter: false; theme: Default"
type="syntaxhighlighter"><![CDATA[
-// intercept all incomming routes and log it
-interceptFrom().to("log:received");
-
-// and here we have a couple of routes
-from("direct:start").to("mock:first").to("seda:bar");
-
-from("seda:bar").to("mock:result");
-]]></script>
-</div></div>You can also attach a <a shape="rect"
href="predicate.html">Predicate</a> to only trigger if certain conditions is
meet. For instance in the route below we intercept when a test message is send
to us, so we can do some custom processing before we continue routing:<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[
-interceptFrom()
- .when(header("usertype").isEqualTo("test"))
- .process(new MyTestServiceProcessor())
- .to("mock:intercepted");
-
-// and here is our route
-from("direct:start").to("seda:bar").to("mock:result");
-]]></script>
-</div></div>And if we want to filter out certain messages we can use the
<strong><code>stop()</code></strong> to instruct Camel to stop continue routing
the <a shape="rect" href="exchange.html">Exchange</a>:<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[
-interceptFrom()
- .when(header("usertype").isEqualTo("test"))
- // here we use stop() to tell Camel to NOT continue routing the message.
- // this let us act as a filter, to drop certain messages.
- .stop();
-
-// and here is our route
-from("direct:start").to("seda:bar").to("mock:result");
-]]></script>
-</div></div>And if want to only apply a specific endpoint, as the
<strong><code>seda:bar</code></strong> endpoint in the sample below, we can do
it like this:<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[
-// only trigger when incoming from seda:bar endpoint
-interceptFrom("seda:bar").to("mock:bar");
-
-// and here we have a couple of routes
-from("direct:start").to("mock:first").to("seda:bar");
-
-from("seda:bar").to("mock:result");
-
-from("seda:foo").to("mock:result");
-]]></script>
-</div></div><h4 id="Intercept-UsingfromSpringDSL.1">Using from Spring
DSL</h4><p>Intercept is of course also available using Spring DSL as shown in
the sample 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 xmlns="http://camel.apache.org/schema/spring">
- <!-- intercept incoming messages and route them to the mock:middle1
endpoint
- before we proceed and continue routing from the point of
interceptions, that
- is mock:end will be the next target -->
- <interceptFrom>
- <to uri="mock:middle1"/>
- </interceptFrom>
-
- <!-- here we have a very simple route -->
- <route>
- <from uri="direct:start"/>
- <to uri="mock:end"/>
- </route>
-</camelContext>
-]]></script>
-</div></div><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><strong>Note:</strong>
<strong><code>stop()</code></strong> is also supported in
<strong><code>interceptFrom()</code></strong> so you can intercept from certain
endpoints and route then elsewhere
and <strong><code>stop()</code></strong> to not continue routing in the
original intended route path.</p></div></div><p><span
class="confluence-anchor-link"
id="Intercept-InterceptSendToEndpoint"></span></p><h3
id="Intercept-InterceptSendToEndpoint"><code>InterceptSendToEndpoint</code></h3><p><strong>Available
as of Camel 2.0</strong></p><p>Intercept send to endpoint is triggered when an
<a shape="rect" href="exchange.html">Exchange</a> is being sent to the
intercepted endpoint. This allows you to route the <a shape="rect"
href="exchange.html">Exchange<
/a> to a <a shape="rect" href="detour.html">Detour</a> or do some custom
processing before the <a shape="rect" href="exchange.html">Exchange</a> is sent
to the original intended destination. You can also skip sending to the intended
destination. By default Camel will send to the original intended destination
after the intercepted route completes. And as the regular intercept you can
also define an <code>when</code> <a shape="rect"
href="predicate.html">Predicate</a> so we only intercept if the <a shape="rect"
href="predicate.html">Predicate</a> evaluates to
<strong><code>true</code></strong>. This allows you do do a bit of filtering,
to only intercept when certain criteria is meet.</p><p>Let start with a simple
example, where we want to intercept when an <a shape="rect"
href="exchange.html">Exchange</a> is being sent to
<strong><code>mock:foo</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[
-// we intercept by endpoint, that means that whenever an exchange is about to
be sent to
-// this endpoint, its intercepted and routed with this detour route beforehand
-// afterwards its send to the original intended destination. So this is kinda
AOP before.
-// That means mock:foo will receive the message (Bye World).
-interceptSendToEndpoint("mock:foo")
- .to("mock:detour").transform(constant("Bye World"));
-
-from("direct:first")
- .to("mock:bar")
- .to("mock:foo")
- .to("mock:result");
-]]></script>
-</div></div>And this time we add the <a shape="rect"
href="predicate.html">Predicate</a> so its only when the message body is
<strong><code>Hello World</code></strong> we intercept.<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 can also attach a predicate to the endpoint interceptor. So in this
example the exchange is
-// only intercepted if the body is Hello World
-interceptSendToEndpoint("mock:foo").when(body().isEqualTo("Hello
World"))
- .to("mock:detour").transform(constant("Bye World"));
-
-from("direct:second")
- .to("mock:bar")
- .to("mock:foo")
- .to("mock:result");
-]]></script>
-</div></div>And to skip sending to the <code>mock:foo</code> endpoint we use
the <strong>*<code>skip()</code></strong> DSL in the route at the end to
instruct Camel to skip sending to the original intended endpoint.<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[
-// since we use the skipSendToOriginalEndpoint() we instruct Camel to skip
-// sending the exchange to the original intended destination after the
intercept
-// route is complete.
-// That means that mock:foo will NOT receive the message, but the message
-// is skipped and continued in the original route, so mock:result will receive
-// the message.
-interceptSendToEndpoint("mock:foo").skipSendToOriginalEndpoint()
- .transform(constant("Bye World")).to("mock:detour");
-
-from("direct:third")
- .to("mock:bar")
- .to("mock:foo")
- .to("mock:result");
-]]></script>
-</div></div><div class="confluence-information-macro
confluence-information-macro-tip"><p class="title">Conditional
skipping</p><span class="aui-icon aui-icon-small aui-iconfont-approve
confluence-information-macro-icon"></span><div
class="confluence-information-macro-body"><p>The combination of
<strong><code>skipSendToEndpoint</code></strong> with a <code>when</code>
predicate behaves differently depending on the Camel
version:</p><ul><li><p><strong>Before Camel 2.10:</strong> the skipping is
applied unconditionally whether the <strong><code>when()</code></strong>
predicate is matched or not, i.e. the <strong><code>when()</code></strong>
predicate only determines whether the body of the interception will execute,
but it does not control skipping behavior.</p></li><li><strong>From Camel
2.10:</strong> the skipping only occurs if
the <strong><code>when()</code></strong> predicate is matched, leading to
more natural logic altogether.</li></ul></div></div><h4 id="Interce
pt-UsingfromSpringDSL.2">Using from Spring DSL</h4><p>Intercept endpoint is of
course also available using Spring DSL. We start with the first example from
above in Spring DSL:</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://camel.apache.org/schema/spring">
-
- <!-- we intercept by endpoint, that means that whenever an exchange is
about to be sent to
- this endpoint, its intercepted and routed with this detour route
beforehand
- afterwards its send to the original intended destination. So this is
kinda AOP before.
- That means mock:foo will receive the message (Bye World). -->
- <interceptSendToEndpoint uri="mock:foo">
- <to uri="mock:detour"/>
- <transform>
- <constant>Bye World</constant>
- </transform>
- </interceptSendToEndpoint>
-
- <route>
- <from uri="direct:first"/>
- <to uri="mock:bar"/>
- <to uri="mock:foo"/>
- <to uri="mock:result"/>
- </route>
-</camelContext>
-]]></script>
-</div></div>And the second. Notice how we can leverage the <a shape="rect"
href="simple.html">Simple</a> language for the <a shape="rect"
href="predicate.html">Predicate</a>:<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://camel.apache.org/schema/spring">
-
- <interceptSendToEndpoint uri="mock:foo">
- <when><simple>${body} == 'Hello
World'</simple></when>
- <to uri="mock:detour"/>
- <transform>
- <constant>Bye World</constant>
- </transform>
- </interceptSendToEndpoint>
-
- <route>
- <from uri="direct:second"/>
- <to uri="mock:bar"/>
- <to uri="mock:foo"/>
- <to uri="mock:result"/>
- </route>
-</camelContext>
-]]></script>
-</div></div>And the third with the <strong><code>skip</code></strong>; notice
skip is set with the <strong><code>skipSendToOriginalEndpoint</code></strong>
attribute on the <strong><code>interceptSendToEndpoint</code></strong>
tag:<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://camel.apache.org/schema/spring">
-
- <!-- since we set the skipSendToOriginalEndpoint attribute to true we
instruct
- Camel to skip sending the exchange to the original intended
destination.
- That means that mock:foo will NOT receive the message, but the message
- is skipped and continued in the original route, so mock:result will
receive
- the message. -->
- <interceptSendToEndpoint uri="mock:foo"
skipSendToOriginalEndpoint="true">
- <transform>
- <constant>Bye World</constant>
- </transform>
- <to uri="mock:detour"/>
- </interceptSendToEndpoint>
-
<route>
- <from uri="direct:third"/>
- <to uri="mock:bar"/>
- <to uri="mock:foo"/>
- <to uri="mock:result"/>
+ <from uri="jms:queue:order"/>
+ <to uri="bean:validateOrder"/>
+ <to uri="bean:handleOrder"/>
</route>
</camelContext>
-]]></script>
-</div></div><h3 id="Intercept-AdvancedusageofIntercept">Advanced usage
of <code>Intercept</code></h3><p>The
<strong><code>interceptFrom</code></strong> and
<strong><code>interceptSendToEndpoint</code></strong> supports endpoint URI
matching by the following rules in the given order:</p><ul
class="alternate"><li>match by exact URI name. This is the sample we have seen
above.</li><li>match by wildcard</li><li>match by regular
expression.</li></ul><p>The real endpoint that was intercepted is stored as URI
in the message IN header with the key
<strong><code>Exchange.INTERCEPTED_ENDPOINT</code></strong>. This allows you to
get hold of this information, when you for instance match by wildcard. Then you
know the real endpoint that was intercepted and can react accordingly.</p><h4
id="Intercept-MatchbyWildcard">Match by Wildcard</h4><p>Match by wildcard
allows you to match a range of endpoint or all of a given type. For instance
use <strong><code>uri="file:*"</code></strong> will match
all <a shape="rect" href="file2.html">File</a> based endpoints:</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[intercept("jms:*")
- .to("log:fromjms");
-]]></script>
-</div></div><p>Wildcards is match that the text before
the <strong><code>*</code></strong> is matched against the given endpoint
and if it also starts with the same characters its a match. For instance you
can do:</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[intercept("file://order/inbox/*")
- .to("log:newfileorders");
-]]></script>
-</div></div><p>To intercept any files received from the
<strong><code>order/inbox</code></strong> folder.</p><h4
id="Intercept-MatchbyRegularExpression">Match by Regular
Expression</h4><p>Match by regular expression is just like match by wildcard
but using regex instead. So if we want to intercept incoming messages from gold
and silver JMS queues we can do:</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[intercept("jms:queue:(gold|silver)")
- .to("seda:handleFast");
-]]></script>
-</div></div><div class="confluence-information-macro
confluence-information-macro-information"><p class="title">About dynamic and
static behavior of interceptFrom and interceptSendToEndpoint</p><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>interceptSendToEndpoint</code></strong> is dynamic hence it will
also trigger if a dynamic URI is constructed that Camel was not aware of at
startup time.<br clear="none"> The <strong><code>interceptFrom</code></strong>
is not dynamic as it only intercepts input to routes registered as routes in
<strong><code>CamelContext</code></strong>. So if you dynamic construct a
<code>Consumer</code> using the Camel API and consumes an <a shape="rect"
href="endpoint.html">Endpoint</a> then the
<strong><code>interceptFrom</code></strong> is not
triggered.</p></div></div><h3 id="Intercept-SeeAlso">See Also</h3><ul
class="alternate"><li><a shap
e="rect" href="architecture.html">Architecture</a></li><li><a shape="rect"
href="aop.html">AOP</a></li></ul></div>
+</plain-text-body><p>And the sample for using
the <strong><code>when()</code></strong> predicate would
be:<plain-text-body>{snippet:id=e1|lang=xml|url=camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/SpringInterceptSimpleRouteWhenTest.xml}</plain-text-body>And
the sample for using the <strong><code>when()</code></strong>
and <strong><code>stop()</code></strong> would
be:<plain-text-body>{snippet:id=e1|lang=xml|url=camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/SpringInterceptSimpleRouteWhenStopTest.xml}</plain-text-body></p><h3
id="Intercept-InterceptFrom"><code>InterceptFrom</code></h3><p><strong><code>InterceptFrom</code></strong>
is for intercepting any incoming <a shape="rect"
href="exchange.html">Exchange</a>, in any route (it intercepts all the
<code>from</code> DSLs). This allows you to do some custom behavior for
received <a shape="rect" href="exchange.html">Exchange</a>s. You ca
n provide a specific URI for a given <a shape="rect"
href="endpoint.html">Endpoint</a> then it only applies for that particular
route.</p><p>So lets start with the logging example. We want to log all the
<strong>incoming</strong> requests so we use
<strong><code>interceptFrom</code></strong> to route to the <a shape="rect"
href="log.html">Log</a> component. As <code>proceed</code> is default then the
<a shape="rect" href="exchange.html">Exchange</a> will continue its route, and
thus it will continue to
<strong><code>mock:first</code></strong>.<plain-text-body>{snippet:id=e1|lang=java|url=camel/trunk/camel-core/src/test/java/org/apache/camel/processor/intercept/InterceptFromSimpleLogTest.java}</plain-text-body>You
can also attach a <a shape="rect" href="predicate.html">Predicate</a> to only
trigger if certain conditions is meet. For instance in the route below we
intercept when a test message is send to us, so we can do some custom
processing before we continue routing:<plain-text-bo
dy>{snippet:id=e1|lang=java|url=camel/trunk/camel-core/src/test/java/org/apache/camel/processor/intercept/InterceptFromSimplePredicateTest.java}</plain-text-body>And
if we want to filter out certain messages we can use the
<strong><code>stop()</code></strong> to instruct Camel to stop continue routing
the <a shape="rect"
href="exchange.html">Exchange</a>:<plain-text-body>{snippet:id=e1|lang=java|url=camel/trunk/camel-core/src/test/java/org/apache/camel/processor/intercept/InterceptFromSimplePredicateWithStopTest.java}</plain-text-body>And
if want to only apply a specific endpoint, as the
<strong><code>seda:bar</code></strong> endpoint in the sample below, we can do
it like
this:<plain-text-body>{snippet:id=e1|lang=java|url=camel/trunk/camel-core/src/test/java/org/apache/camel/processor/intercept/InterceptFromUriSimpleLogTest.java}</plain-text-body></p><h4
id="Intercept-UsingfromSpringDSL.1">Using from Spring DSL</h4><p>Intercept is
of course also available using Spring DSL as shown
in the sample
below:<plain-text-body>{snippet:id=example|lang=xml|url=camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/SpringInterceptFromTest.xml}</plain-text-body></p><rich-text-body><p><strong>Note:</strong>
<strong><code>stop()</code></strong> is also supported in
<strong><code>interceptFrom()</code></strong> so you can intercept from certain
endpoints and route then elsewhere
and <strong><code>stop()</code></strong> to not continue routing in the
original intended route path.</p></rich-text-body><p><parameter
ac:name="">InterceptSendToEndpoint</parameter></p><h3
id="Intercept-InterceptSendToEndpoint"><code>InterceptSendToEndpoint</code></h3><p><strong>Available
as of Camel 2.0</strong></p><p>Intercept send to endpoint is triggered when an
<a shape="rect" href="exchange.html">Exchange</a> is being sent to the
intercepted endpoint. This allows you to route the <a shape="rect"
href="exchange.html">Exchange</a> to a <a shape="rect" href=
"detour.html">Detour</a> or do some custom processing before the <a
shape="rect" href="exchange.html">Exchange</a> is sent to the original intended
destination. You can also skip sending to the intended destination. By default
Camel will send to the original intended destination after the intercepted
route completes. And as the regular intercept you can also define an
<code>when</code> <a shape="rect" href="predicate.html">Predicate</a> so we
only intercept if the <a shape="rect" href="predicate.html">Predicate</a>
evaluates to <strong><code>true</code></strong>. This allows you do do a bit of
filtering, to only intercept when certain criteria is meet.</p><p>Let start
with a simple example, where we want to intercept when an <a shape="rect"
href="exchange.html">Exchange</a> is being sent to
<strong><code>mock:foo</code></strong>:<plain-text-body>{snippet:id=e1|lang=java|url=camel/trunk/camel-core/src/test/java/org/apache/camel/processor/intercept/InterceptSendToEndpointTest.java}</p
lain-text-body>And this time we add the <a shape="rect"
href="predicate.html">Predicate</a> so its only when the message body is
<strong><code>Hello World</code></strong> we
intercept.<plain-text-body>{snippet:id=e2|lang=java|url=camel/trunk/camel-core/src/test/java/org/apache/camel/processor/intercept/InterceptSendToEndpointTest.java}</plain-text-body>And
to skip sending to the <code>mock:foo</code> endpoint we use the
<strong>*<code>skip()</code></strong> DSL in the route at the end to instruct
Camel to skip sending to the original intended
endpoint.<plain-text-body>{snippet:id=e3|lang=java|url=camel/trunk/camel-core/src/test/java/org/apache/camel/processor/intercept/InterceptSendToEndpointTest.java}</plain-text-body></p><parameter
ac:name="title">Conditional skipping</parameter><rich-text-body><p>The
combination of <strong><code>skipSendToEndpoint</code></strong> with a
<code>when</code> predicate behaves differently depending on the Camel
version:</p><ul><li><p><strong>Before Ca
mel 2.10:</strong> the skipping is applied unconditionally whether
the <strong><code>when()</code></strong> predicate is matched or not, i.e.
the <strong><code>when()</code></strong> predicate only determines whether
the body of the interception will execute, but it does not control skipping
behavior.</p></li><li><strong>From Camel 2.10:</strong> the skipping only
occurs if the <strong><code>when()</code></strong> predicate is matched,
leading to more natural logic altogether.</li></ul></rich-text-body><h4
id="Intercept-UsingfromSpringDSL.2">Using from Spring DSL</h4><p>Intercept
endpoint is of course also available using Spring DSL. We start with the first
example from above in Spring
DSL:<plain-text-body>{snippet:id=e1|lang=xml|url=camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/interceptSendToEndpoint.xml}</plain-text-body>And
the second. Notice how we can leverage the <a shape="rect"
href="simple.html">Simple</a> language f
or the <a shape="rect"
href="predicate.html">Predicate</a>:<plain-text-body>{snippet:id=e1|lang=xml|url=camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/interceptSendToEndpointWhen.xml}</plain-text-body>And
the third with the <strong><code>skip</code></strong>; notice skip is set with
the <strong><code>skipSendToOriginalEndpoint</code></strong> attribute on
the <strong><code>interceptSendToEndpoint</code></strong>
tag:<plain-text-body>{snippet:id=e1|lang=xml|url=camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/interceptSendToEndpointSkip.xml}</plain-text-body></p><h3
id="Intercept-AdvancedusageofIntercept">Advanced usage
of <code>Intercept</code></h3><p>The
<strong><code>interceptFrom</code></strong> and
<strong><code>interceptSendToEndpoint</code></strong> supports endpoint URI
matching by the following rules in the given order:</p><ul
class="alternate"><li>match by exact URI name. This is the
sample we have seen above.</li><li>match by wildcard</li><li>match by regular
expression.</li></ul><p>The real endpoint that was intercepted is stored as URI
in the message IN header with the key
<strong><code>Exchange.INTERCEPTED_ENDPOINT</code></strong>. This allows you to
get hold of this information, when you for instance match by wildcard. Then you
know the real endpoint that was intercepted and can react accordingly.</p><h4
id="Intercept-MatchbyWildcard">Match by Wildcard</h4><p>Match by wildcard
allows you to match a range of endpoint or all of a given type. For instance
use <strong><code>uri="file:*"</code></strong> will match all <a shape="rect"
href="file2.html">File</a> based endpoints:</p><parameter
ac:name="">java</parameter><plain-text-body>intercept("jms:*")
+ .to("log:fromjms");
+</plain-text-body><p>Wildcards is match that the text before
the <strong><code>*</code></strong> is matched against the given endpoint
and if it also starts with the same characters its a match. For instance you
can do:</p><parameter
ac:name="">java</parameter><plain-text-body>intercept("file://order/inbox/*")
+ .to("log:newfileorders");
+</plain-text-body><p>To intercept any files received from the
<strong><code>order/inbox</code></strong> folder.</p><h4
id="Intercept-MatchbyRegularExpression">Match by Regular
Expression</h4><p>Match by regular expression is just like match by wildcard
but using regex instead. So if we want to intercept incoming messages from gold
and silver JMS queues we can do:</p><parameter
ac:name="">java</parameter><plain-text-body>intercept("jms:queue:(gold|silver)")
+ .to("seda:handleFast");
+</plain-text-body><parameter ac:name="title">About dynamic and static behavior
of interceptFrom and interceptSendToEndpoint</parameter><rich-text-body><p>The
<strong><code>interceptSendToEndpoint</code></strong> is dynamic hence it will
also trigger if a dynamic URI is constructed that Camel was not aware of at
startup time.<br clear="none"> The <strong><code>interceptFrom</code></strong>
is not dynamic as it only intercepts input to routes registered as routes in
<strong><code>CamelContext</code></strong>. So if you dynamic construct a
<code>Consumer</code> using the Camel API and consumes an <a shape="rect"
href="endpoint.html">Endpoint</a> then the
<strong><code>interceptFrom</code></strong> is not
triggered.</p></rich-text-body><h3 id="Intercept-SeeAlso">See Also</h3><ul
class="alternate"><li><a shape="rect"
href="architecture.html">Architecture</a></li><li><a shape="rect"
href="aop.html">AOP</a></li></ul></div>
</td>
<td valign="top">
<div class="navigation">
Modified: websites/production/camel/content/javascript.html
==============================================================================
--- websites/production/camel/content/javascript.html (original)
+++ websites/production/camel/content/javascript.html Fri Aug 25 08:22:01 2017
@@ -41,7 +41,6 @@
<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;
@@ -130,46 +129,19 @@
]]></script>
</div></div>
-<h3 id="JavaScript-ScriptContextOptions"><code>ScriptContext</code>
Options</h3><p> </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">The <code>JSR-223</code>
scripting language's <strong><code>ScriptContext</code></strong> is
pre-configured with the following attributes all set at
<strong><code>ENGINE_SCOPE</code></strong>.</div></div><div
class="table-wrap"><table class="confluenceTable"><tbody><tr><th colspan="1"
rowspan="1" class="confluenceTh"><p>Attribute</p></th><th colspan="1"
rowspan="1" class="confluenceTh"><p>Type</p></th><th colspan="1" rowspan="1"
class="confluenceTh"><p>Value</p></th></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p><span><code>camelContext</code><br
clear="none"></span></p></td><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>org.apache.ca
mel.CamelContext</code></p></td><td colspan="1" rowspan="1"
class="confluenceTd"><p>The Camel Context.</p></td></tr><tr><td colspan="1"
rowspan="1" class="confluenceTd"><p><code>context</code></p></td><td
colspan="1" rowspan="1"
class="confluenceTd"><p><code>org.apache.camel.CamelContext</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p>The Camel Context (cannot be
used in groovy).</p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>exchange</code></p></td><td colspan="1"
rowspan="1"
class="confluenceTd"><p><code>org.apache.camel.Exchange</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p>The current
Exchange.</p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>properties</code></p></td><td colspan="1"
rowspan="1"
class="confluenceTd"><p><code>org.apache.camel.builder.script.PropertiesFunction</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p><strong>Camel 2.9:</strong>
Function with a <s
trong><code>resolve</code></strong> method to make it easier to use Camels <a
shape="rect" href="properties.html">Properties</a> component from scripts. See
further below for example.</p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>request</code></p></td><td colspan="1"
rowspan="1"
class="confluenceTd"><p><code>org.apache.camel.Message</code></p></td><td
colspan="1" rowspan="1"
class="confluenceTd"><p>The <strong><code>IN</code></strong>
message.</p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>response</code></p></td><td colspan="1"
rowspan="1"
class="confluenceTd"><p><code>org.apache.camel.Message</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p><strong>Deprecated</strong>:
The <strong><code>OUT</code></strong> message.
The <strong><code>OUT</code></strong> message
is <strong><code>null</code></strong> by default. Use the
<strong><code>IN</code></strong> message instead.</p></td></tr></tbody
></table></div><p>See <a shape="rect"
>href="scripting-languages.html">Scripting Languages</a> for the list of
>languages with explicit DSL support.</p><h3
>id="JavaScript-PassingAdditionalArgumentstotheScriptingEngine">Passing
>Additional Arguments to
>the <code>ScriptingEngine</code></h3><p><strong>Available from Camel
>2.8</strong></p><p>You can provide additional arguments to the
><strong><code>ScriptingEngine</code></strong> using a header on the Camel
>message with the key
><strong><code>CamelScriptArguments</code></strong>.</p><p>Example:</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 void testArgumentsExample() throws Exception {
- getMockEndpoint("mock:result").expectedMessageCount(0);
- getMockEndpoint("mock:unmatched").expectedMessageCount(1);
-
- // additional arguments to ScriptEngine
- Map<String, Object> arguments = new HashMap<String, Object>();
- arguments.put("foo", "bar");
- arguments.put("baz", 7);
-
- // those additional arguments is provided as a header on the Camel Message
- template.sendBodyAndHeader("direct:start", "hello",
ScriptBuilder.ARGUMENTS, arguments);
-
- assertMockEndpointsSatisfied();
-}
-]]></script>
-</div></div><h3 id="JavaScript-UsingPropertiesFunction">Using Properties
Function</h3><p><strong>Available from Camel 2.9</strong></p><p>If you need to
use the <a shape="rect" href="properties.html">Properties</a> component from a
script to lookup property placeholders, then its a bit cumbersome to do so. For
example, to set a header name <strong><code>myHeader</code></strong> with
a value from a property placeholder, whose key is taken from a header named
<strong><code>foo</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[.setHeader("myHeader").groovy("context.resolvePropertyPlaceholders('{{'
+ request.headers.get('foo') + '}}')")
-]]></script>
-</div></div><p>From <strong>Camel 2.9</strong>: you can now use the properties
function and the same example is simpler:</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[.setHeader("myHeader").groovy("properties.resolve(request.headers.get('foo'))")
-]]></script>
-</div></div><h3 id="JavaScript-LoadingScriptFromExternalResource">Loading
Script From External Resource</h3><p><strong>Available from Camel
2.11</strong></p><p>You can externalize the script and have Camel load it from
a resource such as <strong><code>classpath:</code></strong>,
<strong><code>file:</code></strong>, or <strong><code>http:</code></strong>.
This is done using the following syntax:
<strong><code>resource:scheme:location</code></strong> e.g. to refer to a file
on the classpath you can do:</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[.setHeader("myHeader").groovy("resource:classpath:mygroovy.groovy")
-]]></script>
-</div></div><h3
id="JavaScript-HowtoGettheResultfromMultipleStatementsScript">How to Get the
Result from Multiple Statements Script</h3><p><strong>Available from Camel
2.14</strong></p><p>The script engine's eval method returns
a <strong><code>null</code></strong> when it runs a multi-statement
script. However, Camel can look up the value of a script's result by using the
key <strong><code>result</code></strong> from the value set. When writing a
multi-statement script set the value of
the <strong><code>result</code></strong> variable as the script return
value.</p><div class="code panel pdl" style="border-width: 1px;"><div
class="codeContent panelContent pdl">
-<script class="brush: text; gutter: false; theme: Default"
type="syntaxhighlighter"><![CDATA[bar = "baz";
+<h3 id="JavaScript-ScriptContextOptions"><code>ScriptContext</code>
Options</h3><p> </p><rich-text-body>The <code>JSR-223</code>
scripting language's <strong><code>ScriptContext</code></strong> is
pre-configured with the following attributes all set at
<strong><code>ENGINE_SCOPE</code></strong>.</rich-text-body><div
class="table-wrap"><table class="confluenceTable"><tbody><tr><th colspan="1"
rowspan="1" class="confluenceTh"><p>Attribute</p></th><th colspan="1"
rowspan="1" class="confluenceTh"><p>Type</p></th><th colspan="1" rowspan="1"
class="confluenceTh"><p>Value</p></th></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p><span><code>camelContext</code><br
clear="none"></span></p></td><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>org.apache.camel.CamelContext</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p>The Camel
Context.</p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>context</code></p></td><td c
olspan="1" rowspan="1"
class="confluenceTd"><p><code>org.apache.camel.CamelContext</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p>The Camel Context (cannot be
used in groovy).</p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>exchange</code></p></td><td colspan="1"
rowspan="1"
class="confluenceTd"><p><code>org.apache.camel.Exchange</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p>The current
Exchange.</p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>properties</code></p></td><td colspan="1"
rowspan="1"
class="confluenceTd"><p><code>org.apache.camel.builder.script.PropertiesFunction</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p><strong>Camel 2.9:</strong>
Function with a <strong><code>resolve</code></strong> method to make it easier
to use Camels <a shape="rect" href="properties.html">Properties</a> component
from scripts. See further below for example.</p></td></tr><tr><td c
olspan="1" rowspan="1"
class="confluenceTd"><p><code>request</code></p></td><td colspan="1"
rowspan="1"
class="confluenceTd"><p><code>org.apache.camel.Message</code></p></td><td
colspan="1" rowspan="1"
class="confluenceTd"><p>The <strong><code>IN</code></strong>
message.</p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>response</code></p></td><td colspan="1"
rowspan="1"
class="confluenceTd"><p><code>org.apache.camel.Message</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p><strong>Deprecated</strong>:
The <strong><code>OUT</code></strong> message.
The <strong><code>OUT</code></strong> message
is <strong><code>null</code></strong> by default. Use the
<strong><code>IN</code></strong> message
instead.</p></td></tr></tbody></table></div><p>See <a shape="rect"
href="scripting-languages.html">Scripting Languages</a> for the list of
languages with explicit DSL support.</p><h3
id="JavaScript-PassingAdditionalArgumentstotheScript
ingEngine">Passing Additional Arguments to
the <code>ScriptingEngine</code></h3><p><strong>Available from Camel
2.8</strong></p><p>You can provide additional arguments to the
<strong><code>ScriptingEngine</code></strong> using a header on the Camel
message with the key
<strong><code>CamelScriptArguments</code></strong>.</p><p>Example:<plain-text-body>{snippet:id=e1|lang=java|url=camel/trunk/components/camel-script/src/test/java/org/apache/camel/builder/script/JavaScriptExpressionTest.java}</plain-text-body></p><h3
id="JavaScript-UsingPropertiesFunction">Using Properties
Function</h3><p><strong>Available from Camel 2.9</strong></p><p>If you need to
use the <a shape="rect" href="properties.html">Properties</a> component from a
script to lookup property placeholders, then its a bit cumbersome to do so. For
example, to set a header name <strong><code>myHeader</code></strong> with
a value from a property placeholder, whose key is taken from a header named
<strong><code>foo</cod
e></strong>.</p><plain-text-body>.setHeader("myHeader").groovy("context.resolvePropertyPlaceholders('{{'
+ request.headers.get('foo') + '}}')")
+</plain-text-body><p>From <strong>Camel 2.9</strong>: you can now use the
properties function and the same example is simpler:</p><parameter
ac:name="language">java</parameter><plain-text-body>.setHeader("myHeader").groovy("properties.resolve(request.headers.get('foo'))")
+</plain-text-body><h3
id="JavaScript-LoadingScriptFromExternalResource">Loading Script From External
Resource</h3><p><strong>Available from Camel 2.11</strong></p><p>You can
externalize the script and have Camel load it from a resource such as
<strong><code>classpath:</code></strong>, <strong><code>file:</code></strong>,
or <strong><code>http:</code></strong>. This is done using the following
syntax: <strong><code>resource:scheme:location</code></strong> e.g. to refer to
a file on the classpath you can do:</p><parameter
ac:name="language">java</parameter><plain-text-body>.setHeader("myHeader").groovy("resource:classpath:mygroovy.groovy")
+</plain-text-body><h3
id="JavaScript-HowtoGettheResultfromMultipleStatementsScript">How to Get the
Result from Multiple Statements Script</h3><p><strong>Available from Camel
2.14</strong></p><p>The script engine's eval method returns
a <strong><code>null</code></strong> when it runs a multi-statement
script. However, Camel can look up the value of a script's result by using the
key <strong><code>result</code></strong> from the value set. When writing a
multi-statement script set the value of
the <strong><code>result</code></strong> variable as the script return
value.</p><parameter ac:name="language">text</parameter><plain-text-body>bar =
"baz";
# some other statements ...
# camel take the result value as the script evaluation result
result = body * 2 + 1
-]]></script>
-</div></div><p> </p><h3
id="JavaScript-Dependencies">Dependencies</h3><p>To use scripting languages in
your camel routes you need to add the a dependency on
<strong><code>camel-script</code></strong> which integrates the JSR-223
scripting engine.</p><p>If you use maven you could just add the following to
your <strong><code>pom.xml</code></strong>, substituting the version number for
the latest & greatest release (see <a shape="rect" href="download.html">the
download page for the latest versions</a>).</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> </p><h3
id="JavaScript-Dependencies">Dependencies</h3><p>To use scripting languages in
your camel routes you need to add the a dependency on
<strong><code>camel-script</code></strong> which integrates the JSR-223
scripting engine.</p><p>If you use maven you could just add the following to
your <strong><code>pom.xml</code></strong>, substituting the version number for
the latest & greatest release (see <a shape="rect" href="download.html">the
download page for the latest versions</a>).</p><parameter
ac:name="">xml</parameter><plain-text-body><dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-script</artifactId>
<version>x.x.x</version>
</dependency>
-]]></script>
-</div></div></div>
+</plain-text-body></div>
</td>
<td valign="top">
<div class="navigation">
Modified: websites/production/camel/content/jcifs.html
==============================================================================
--- websites/production/camel/content/jcifs.html (original)
+++ websites/production/camel/content/jcifs.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: JCIFS
@@ -92,27 +81,23 @@
<p>This component provides access to remote file systems over the CIFS/SMB
networking protocol. The <strong>camel-jcifs</strong> library is provided by
the <a shape="rect" class="external-link"
href="http://code.google.com/p/camel-extra/" rel="nofollow">Camel Extra</a>
project which hosts all *GPL related components for Camel.</p>
<p>Maven users will need to add the following dependency to their
<code>pom.xml</code> 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[
+<parameter ac:name="">xml</parameter><plain-text-body>
<dependency>
<groupId>org.apache-extras.camel-extra</groupId>
<artifactId>camel-jcifs</artifactId>
<version>x.x.x</version>
<!-- use the same version as your Camel core version -->
</dependency>
-]]></script>
-</div></div>
+</plain-text-body>
-<div class="confluence-information-macro confluence-information-macro-tip"><p
class="title">Consuming from remote server</p><span class="aui-icon
aui-icon-small aui-iconfont-approve
confluence-information-macro-icon"></span><div
class="confluence-information-macro-body">
-<p>Make sure you read the section titled <em>Default when consuming files</em>
further below for details related to consuming files. </p></div></div>
+<parameter ac:name="title">Consuming from remote
server</parameter><rich-text-body>
+<p>Make sure you read the section titled <em>Default when consuming files</em>
further below for details related to consuming files. </p></rich-text-body>
<h3 id="JCIFS-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[
+<plain-text-body>
smb://[[[domain;]username[:password]@]server[:port]/[[share/[dir/]]]][?options]
-]]></script>
-</div></div>
+</plain-text-body>
<p>Where <strong>share</strong> represents the share to connect to and
<strong>dir</strong> is optionaly any underlying directory. Can contain nested
folders. </p>
@@ -124,23 +109,18 @@ smb://[[[domain;]username[:password]@]se
<p>The options below are exclusive for the JCIFS component.</p>
-<div class="confluenceTableSmall">
+<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>password</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>Mandatory</strong> Specifies the password to use to log in to the
remote file system. </p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p> <code>localWorkDirectory</code> </p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p> <code>null</code> </p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p> When consuming, a local work
directory can be used to store the remote file content directly in local files,
to avoid loading the content into memory
. This is beneficial, if you consume a very big remote file and thus can
conserve memory. See below for more details.
</p></td></tr></tbody></table></div>
-</div>
-
-
-
+</rich-text-body>
-<div class="confluence-information-macro
confluence-information-macro-information"><p class="title">More
options</p><span class="aui-icon aui-icon-small aui-iconfont-info
confluence-information-macro-icon"></span><div
class="confluence-information-macro-body">
-<p>See <a shape="rect" href="file2.html">File</a> for more options as all the
options from <a shape="rect" href="file2.html">File</a> is inherited.
</p></div></div>
+<parameter ac:name="title">More options</parameter><rich-text-body>
+<p>See <a shape="rect" href="file2.html">File</a> for more options as all the
options from <a shape="rect" href="file2.html">File</a> is inherited.
</p></rich-text-body>
<p>For example to set the <code>localWorkDirectory</code> to ''/tmp'' you can
do: </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("smb://[email protected]/sharename?password=secret&localWorkDirectory=/tmp")
- .to("bean:foo");
-]]></script>
-</div></div>
+<parameter ac:name="">java</parameter><plain-text-body>
+from("smb://[email protected]/sharename?password=secret&localWorkDirectory=/tmp")
+ .to("bean:foo");
+</plain-text-body>
<p>You can have as many of these options as you like.</p>
@@ -150,19 +130,16 @@ from("smb://[email protected]
<p><code><a shape="rect"
href="smb://[email protected]/sharename?password=secret"
rel="nofollow">smb://[email protected]/sharename?password=secret</a></code>
<br clear="none">
<code><a shape="rect"
href="smb://companydomain;[email protected]/sharename?password=secret"
rel="nofollow">smb://companydomain;[email protected]/sharename?password=secret</a></code>
</p>
-<div class="confluence-information-macro confluence-information-macro-tip"><p
class="title">More information</p><span class="aui-icon aui-icon-small
aui-iconfont-approve confluence-information-macro-icon"></span><div
class="confluence-information-macro-body">
-<p>This component is an extension of the <a shape="rect"
href="file2.html">File</a> component. So there are more samples and details on
the <a shape="rect" href="file2.html">File</a> component page. </p></div></div>
+<parameter ac:name="title">More information</parameter><rich-text-body>
+<p>This component is an extension of the <a shape="rect"
href="file2.html">File</a> component. So there are more samples and details on
the <a shape="rect" href="file2.html">File</a> component page.
</p></rich-text-body>
<h3 id="JCIFS-MessageHeaders">Message Headers </h3>
<p>The following message headers can be used to affect the behavior of the
component </p>
-<div class="confluenceTableSmall">
+<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> Header </p></th><th
colspan="1" rowspan="1" class="confluenceTh"><p> Description
</p></th></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"><p>
<code>CamelFileName</code> </p></td><td colspan="1" rowspan="1"
class="confluenceTd"><p> Specifies the output file name (relative to the
endpoint directory) to be used for the output message when sending to the
endpoint. If this is not present and no expression either, then a generated
message ID is used as the filename instead. </p></td></tr><tr><td colspan="1"
rowspan="1" class="confluenceTd"><p> <code>CamelFileNameProduced</code>
</p></td><td colspan="1" rowspan="1" class="confluenceTd"><p> The actual
absolute filepath (path + name) for the output file that was written. This
header is set by Camel and its purpose is providing end-users the name of the
file that was written. </p></td></tr><tr><td colspan="1" rowspa
n="1" class="confluenceTd"><p> <code>CamelFileBatchIndex</code> </p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p> Current index out of total
number of files being consumed in this batch. </p></td></tr><tr><td colspan="1"
rowspan="1" class="confluenceTd"><p> <code>CamelFileBatchSize</code>
</p></td><td colspan="1" rowspan="1" class="confluenceTd"><p> Total number of
files being consumed in this batch. </p></td></tr><tr><td colspan="1"
rowspan="1" class="confluenceTd"><p> <code>CamelFileHost</code> </p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p> The remote hostname.
</p></td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"><p>
<code>CamelFileLocalWorkPath</code> </p></td><td colspan="1" rowspan="1"
class="confluenceTd"><p> Path to the local work file, if local work directory
is used. </p></td></tr></tbody></table></div>
-</div>
-
-
-
+</rich-text-body>
<h3 id="JCIFS-UsingLocalWorkDirectory">Using Local Work Directory </h3>
@@ -172,21 +149,18 @@ from("smb://[email protected]
<p>Camel JCIFS will store to a local file with the same name as the remote
file. And finally, when the <a shape="rect" href="exchange.html">Exchange</a>
is complete the local file is deleted. </p>
<p>So if you want to download files from a remote server and store it as files
then you need to route to a file endpoint such as: </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("smb://[email protected]/sharename?password=secret&localWorkDirectory=/tmp")
- .to("file://inbox");
-]]></script>
-</div></div>
+<parameter ac:name="">java</parameter><plain-text-body>
+from("smb://[email protected]/sharename?password=secret&localWorkDirectory=/tmp")
+ .to("file://inbox");
+</plain-text-body>
-<div class="confluence-information-macro confluence-information-macro-tip"><p
class="title">Optimization by renaming work file</p><span class="aui-icon
aui-icon-small aui-iconfont-approve
confluence-information-macro-icon"></span><div
class="confluence-information-macro-body">
-<p>The route above is ultra efficient as it avoids reading the entire file
content into memory. It will download the remote file directly to a local file
stream. The <code>java.io.File</code> handle is then used as the <a
shape="rect" href="exchange.html">Exchange</a> body. The file producer
leverages this fact and can work directly on the work file
<code>java.io.File</code> handle and perform a <code>java.io.File.rename</code>
to the target filename. As Camel knows it's a local work file, it can optimize
and use a rename instead of a file copy, as the work file is meant to be
deleted anyway. </p></div></div>
+<parameter ac:name="title">Optimization by renaming work
file</parameter><rich-text-body>
+<p>The route above is ultra efficient as it avoids reading the entire file
content into memory. It will download the remote file directly to a local file
stream. The <code>java.io.File</code> handle is then used as the <a
shape="rect" href="exchange.html">Exchange</a> body. The file producer
leverages this fact and can work directly on the work file
<code>java.io.File</code> handle and perform a <code>java.io.File.rename</code>
to the target filename. As Camel knows it's a local work file, it can optimize
and use a rename instead of a file copy, as the work file is meant to be
deleted anyway. </p></rich-text-body>
<h3 id="JCIFS-Samples">Samples </h3>
<p>In the sample below we set up Camel to download all the reports from the
SMB/CIFS server once every hour (60 min) and store it as files on the local
file system. </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[
+<parameter ac:name="">java</parameter><plain-text-body>
protected RouteBuilder createRouteBuilder() throws Exception {
return new RouteBuilder() {
public void configure() throws Exception {
@@ -196,56 +170,41 @@ protected RouteBuilder createRouteBuilde
// from the given server we poll (= download) all the files
// from the public/reports folder and store this as files
// in a local directory. Camel will use the filenames from the server
-
from("smb://[email protected]/public/reports?password=secret&delay="
+ delay)
- .to("file://target/test-reports");
+
from("smb://[email protected]/public/reports?password=secret&delay="
+ delay)
+ .to("file://target/test-reports");
}
};
}
-from("smb://[email protected]/sharename?password=secret&amp;delay=60000")
- .to("file://target/test-reports")
-]]></script>
-</div></div>
+from("smb://[email protected]/sharename?password=secret&amp;delay=60000")
+ .to("file://target/test-reports")
+</plain-text-body>
<p>And the route using Spring DSL: </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="smb://[email protected]/sharename?password=secret&amp;delay=60000"/>
- <to uri="file://target/test-reports"/>
+ <from
uri="smb://[email protected]/sharename?password=secret&amp;delay=60000"/>
+ <to uri="file://target/test-reports"/>
</route>
-]]></script>
-</div></div>
+</plain-text-body>
<h3
id="JCIFS-Filterusingorg.apache.camel.component.file.GenericFileFilter">Filter
using <code>org.apache.camel.component.file.GenericFileFilter</code> </h3>
<p>Camel supports pluggable filtering strategies. This strategy it to use the
build in <code>org.apache.camel.component.file.GenericFileFilter</code> in
Java. You can then configure the endpoint with such a filter to skip certain
filters before being processed. </p>
<p>In the sample we have built our own filter that only accepts files starting
with report in the filename. </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 MyFileFilter<T> implements GenericFileFilter<T> {
-
- public boolean accept(GenericFile<T> file) {
- // we only want report files
- return file.getFileName().startsWith("report");
- }
-}
-]]></script>
-</div></div>
+<plain-text-body>{snippet:id=e1|lang=java|url=camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FromFtpRemoteFileFilterTest.java}</plain-text-body>
<p>And then we can configure our route using the <strong>filter</strong>
attribute to reference our filter (using <code>#</code> notation) that we have
defined in the spring XML file: </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>
<!-- define our sorter as a plain spring bean -->
-<bean id="myFilter"
class="com.mycompany.MyFileFilter"/>
+<bean id="myFilter" class="com.mycompany.MyFileFilter"/>
<route>
- <from
uri="smb://[email protected]/sharename?password=secret&amp;filter=#myFilter"/>
- <to uri="bean:processInbox"/>
+ <from
uri="smb://[email protected]/sharename?password=secret&amp;filter=#myFilter"/>
+ <to uri="bean:processInbox"/>
</route>
-]]></script>
-</div></div>
+</plain-text-body>
<h3 id="JCIFS-FilteringusingANTpathmatcher">Filtering using ANT path matcher
</h3>
@@ -258,32 +217,29 @@ The reason is that we leverage Spring's
<p>The sample below demonstrates how to use it: </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://camel.apache.org/schema/spring">
- <template id="camelTemplate"/>
+<parameter ac:name="">xml</parameter><plain-text-body>
+<camelContext xmlns="http://camel.apache.org/schema/spring">
+ <template id="camelTemplate"/>
<!-- use myFilter as filter to allow setting ANT paths for which files to
scan for -->
- <endpoint id="mySMBEndpoint"
uri="smb://[email protected]/sharename?password=secret&amp;recursive=true&amp;filter=#myAntFilter"/>
+ <endpoint id="mySMBEndpoint"
uri="smb://[email protected]/sharename?password=secret&amp;recursive=true&amp;filter=#myAntFilter"/>
<route>
- <from ref="mySMBEndpoint"/>
- <to uri="mock:result"/>
+ <from ref="mySMBEndpoint"/>
+ <to uri="mock:result"/>
</route>
</camelContext>
<!-- we use the AntPathMatcherRemoteFileFilter to use ant paths for
includes and exclude -->
-<bean id="myAntFilter"
class="org.apache.camel.component.file.AntPathMatcherGenericFileFilter">
+<bean id="myAntFilter"
class="org.apache.camel.component.file.AntPathMatcherGenericFileFilter">
<!-- include any files in the sub folder that has day in the name -->
- <property name="includes"
value="**/subfolder/**/*day*"/>
+ <property name="includes" value="**/subfolder/**/*day*"/>
<!-- exclude all files with bad in name or .xml files. Use comma to
separate multiple excludes -->
- <property name="excludes"
value="**/*bad*,**/*.xml"/>
+ <property name="excludes" value="**/*bad*,**/*.xml"/>
</bean>
-]]></script>
-</div></div>
+</plain-text-body>
-<h3 id="JCIFS-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>
+<parameter ac:name=""><a shape="rect" href="endpoint-see-also.html">Endpoint
See Also</a></parameter>
<ul class="alternate"><li><a shape="rect"
href="file2.html">File2</a></li></ul></div>
</td>
<td valign="top">