Modified: websites/production/camel/content/book-in-one-page.html ============================================================================== --- websites/production/camel/content/book-in-one-page.html (original) +++ websites/production/camel/content/book-in-one-page.html Mon May 14 16:24:00 2018 @@ -42,6 +42,7 @@ <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 src='//camel.apache.org/styles/highlighter/scripts/shBrushGroovy.js' type='text/javascript'></script> <script type="text/javascript"> SyntaxHighlighter.defaults['toolbar'] = false; @@ -4371,11 +4372,11 @@ So we completed the last piece in the pi <p>This example has been removed from <strong>Camel 2.9</strong> onwards. Apache Axis 1.4 is a very old and unsupported framework. We encourage users to use <a shape="rect" href="cxf.html">CXF</a> instead of Axis.</p></div></div> <style type="text/css">/*<![CDATA[*/ -div.rbtoc1525458007600 {padding: 0px;} -div.rbtoc1525458007600 ul {list-style: disc;margin-left: 0px;} -div.rbtoc1525458007600 li {margin-left: 0px;padding-left: 0px;} +div.rbtoc1526314867397 {padding: 0px;} +div.rbtoc1526314867397 ul {list-style: disc;margin-left: 0px;} +div.rbtoc1526314867397 li {margin-left: 0px;padding-left: 0px;} -/*]]>*/</style><div class="toc-macro rbtoc1525458007600"> +/*]]>*/</style><div class="toc-macro rbtoc1526314867397"> <ul class="toc-indentation"><li><a shape="rect" href="#BookInOnePage-TutorialusingAxis1.4withApacheCamel">Tutorial using Axis 1.4 with Apache Camel</a> <ul class="toc-indentation"><li><a shape="rect" href="#BookInOnePage-Prerequisites">Prerequisites</a></li><li><a shape="rect" href="#BookInOnePage-Distribution">Distribution</a></li><li><a shape="rect" href="#BookInOnePage-Introduction">Introduction</a></li><li><a shape="rect" href="#BookInOnePage-SettinguptheprojecttorunAxis">Setting up the project to run Axis</a> <ul class="toc-indentation"><li><a shape="rect" href="#BookInOnePage-Maven2">Maven 2</a></li><li><a shape="rect" href="#BookInOnePage-wsdl">wsdl</a></li><li><a shape="rect" href="#BookInOnePage-ConfiguringAxis">Configuring Axis</a></li><li><a shape="rect" href="#BookInOnePage-RunningtheExample">Running the Example</a></li></ul> @@ -6204,19 +6205,36 @@ This is done using the following syntax: <p>However any <a shape="rect" class="external-link" href="http://jcp.org/en/jsr/detail?id=223" rel="nofollow">JSR 223</a> scripting language can be used using the generic DSL methods.</p> -<h3 id="BookInOnePage-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><t d 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 <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><t d 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="BookInOnePage-PassingAdditionalArgumentstothe ScriptingEngine">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="BookInOnePage-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><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="BookInOnePage-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="BookInOnePage-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 -</plain-text-body><p> </p><h3 id="BookInOnePage-Dependencies.8">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> -</plain-text-body> +<h3 id="BookInOnePage-ScriptContextOptions"><code>ScriptContext</code> Options</h3><p> </p><p>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>.</p><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 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 <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 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="BookInOnePage-PassingAdditionalArgumentstotheScriptingEngine">Passing A dditional 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<>(); + 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="BookInOnePage-UsingPropertiesFunction"><br clear="none">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: groovy; 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="BookInOnePage-LoadingScriptFromExternalResource"><br clear="none">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="BookInOnePage-HowtoGettheResultfromMultipleStatementsScript"><br clear="none">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><p>textbar = "baz"; # some other statements ... # camel take the result value as the script evaluation result result = body * 2 + 1</p><p> </p><h3 id="BookInOnePage-Dependencies.8">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 us e 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> + <groupId>org.apache.camel</groupId> + <artifactId>camel-script</artifactId> + <version>x.x.x</version> +</dependency>]]></script> +</div></div> <h2 id="BookInOnePage-SeeAlso.6">See Also</h2> @@ -6251,19 +6269,36 @@ result = body * 2 + 1 <p>You could follow the examples above to create an <a shape="rect" href="predicate.html">Predicate</a> in a <a shape="rect" href="message-filter.html">Message Filter</a> or as an <a shape="rect" href="expression.html">Expression</a> for a <a shape="rect" href="recipient-list.html">Recipient List</a></p> -<h3 id="BookInOnePage-ScriptContextOptions.1"><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 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 <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 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="BookInOnePage-PassingAdditionalArgumentstot heScriptingEngine.1">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="BookInOnePage-UsingPropertiesFunction.1">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><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="BookInOnePage-LoadingScriptFromExternalResource.1">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="BookInOnePage-HowtoGettheResultfromMultipleStatementsScript.1">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 -</plain-text-body><p> </p><h3 id="BookInOnePage-Dependencies.9">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> -</plain-text-body> +<h3 id="BookInOnePage-ScriptContextOptions.1"><code>ScriptContext</code> Options</h3><p> </p><p>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>.</p><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 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 <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 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="BookInOnePage-PassingAdditionalArgumentstotheScriptingEngine.1">Passi ng 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<>(); + 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="BookInOnePage-UsingPropertiesFunction.1"><br clear="none">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: groovy; 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="BookInOnePage-LoadingScriptFromExternalResource.1"><br clear="none">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="BookInOnePage-HowtoGettheResultfromMultipleStatementsScript.1"><br clear="none">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><p>textbar = "baz"; # some other statements ... # camel take the result value as the script evaluation result result = body * 2 + 1</p><p> </p><h3 id="BookInOnePage-Dependencies.9">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> + <groupId>org.apache.camel</groupId> + <artifactId>camel-script</artifactId> + <version>x.x.x</version> +</dependency>]]></script> +</div></div> <h2 id="BookInOnePage-JavaScript">JavaScript</h2> <p>Camel supports <a shape="rect" class="external-link" href="http://en.wikipedia.org/wiki/JavaScript" rel="nofollow">JavaScript/ECMAScript</a> among other <a shape="rect" href="scripting-languages.html">Scripting Languages</a> to allow an <a shape="rect" href="expression.html">Expression</a> or <a shape="rect" href="predicate.html">Predicate</a> to be used in the <a shape="rect" href="dsl.html">DSL</a> or <a shape="rect" href="xml-configuration.html">Xml Configuration</a>.</p> @@ -6308,19 +6343,36 @@ result = body * 2 + 1 ]]></script> </div></div> -<h3 id="BookInOnePage-ScriptContextOptions.2"><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 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 <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 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="BookInOnePage-PassingAdditionalArgumentstot heScriptingEngine.2">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="BookInOnePage-UsingPropertiesFunction.2">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><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="BookInOnePage-LoadingScriptFromExternalResource.2">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="BookInOnePage-HowtoGettheResultfromMultipleStatementsScript.2">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 -</plain-text-body><p> </p><h3 id="BookInOnePage-Dependencies.10">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> -</plain-text-body> +<h3 id="BookInOnePage-ScriptContextOptions.2"><code>ScriptContext</code> Options</h3><p> </p><p>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>.</p><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 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 <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 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="BookInOnePage-PassingAdditionalArgumentstotheScriptingEngine.2">Passi ng 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<>(); + 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="BookInOnePage-UsingPropertiesFunction.2"><br clear="none">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: groovy; 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="BookInOnePage-LoadingScriptFromExternalResource.2"><br clear="none">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="BookInOnePage-HowtoGettheResultfromMultipleStatementsScript.2"><br clear="none">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><p>textbar = "baz"; # some other statements ... # camel take the result value as the script evaluation result result = body * 2 + 1</p><p> </p><h3 id="BookInOnePage-Dependencies.10">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> + <groupId>org.apache.camel</groupId> + <artifactId>camel-script</artifactId> + <version>x.x.x</version> +</dependency>]]></script> +</div></div> <h2 id="BookInOnePage-Groovy">Groovy</h2><p>Camel supports <a shape="rect" class="external-link" href="http://groovy.codehaus.org/" rel="nofollow">Groovy</a> among other <a shape="rect" href="scripting-languages.html">Scripting Languages</a> to allow an <a shape="rect" href="expression.html">Expression</a> or <a shape="rect" href="predicate.html">Predicate</a> to be used in the <a shape="rect" href="dsl.html">DSL</a> or <a shape="rect" href="xml-configuration.html">Xml Configuration</a>.</p><p>To use a Groovy expression use the following Java code</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[... groovy("someGroovyExpression") ... ]]></script> @@ -6349,19 +6401,36 @@ from("queue:foo").filter(groov </filter> </route> ]]></script> -</div></div><p></p><h3 id="BookInOnePage-ScriptContextOptions.3"><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>cont ext</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 <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 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="BookInOnePage-PassingAdd itionalArgumentstotheScriptingEngine.3">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="BookInOnePage-UsingPropertiesFunction.3">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 h eader named <strong><code>foo</code></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="BookInOnePage-LoadingScriptFromExternalResource.3">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="BookInOnePage-HowtoGettheResultfromMultipleStatementsScript.3">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 -</plain-text-body><p> </p><h3 id="BookInOnePage-Dependencies.11">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> -</plain-text-body> +</div></div><p></p><h3 id="BookInOnePage-ScriptContextOptions.3"><code>ScriptContext</code> Options</h3><p> </p><p>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>.</p><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 col span="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 col span="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="BookInOnePage-PassingAdditionalArgumentstotheScrip tingEngine.3">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<>(); + 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="BookInOnePage-UsingPropertiesFunction.3"><br clear="none">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: groovy; 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="BookInOnePage-LoadingScriptFromExternalResource.3"><br clear="none">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="BookInOnePage-HowtoGettheResultfromMultipleStatementsScript.3"><br clear="none">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><p>textbar = "baz"; # some other statements ... # camel take the result value as the script evaluation result result = body * 2 + 1</p><p> </p><h3 id="BookInOnePage-Dependencies.11">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> + <groupId>org.apache.camel</groupId> + <artifactId>camel-script</artifactId> + <version>x.x.x</version> +</dependency>]]></script> +</div></div> <h2 id="BookInOnePage-Python">Python</h2><p>Camel supports <a shape="rect" class="external-link" href="http://www.python.org/" rel="nofollow">Python</a> among other <a shape="rect" href="scripting-languages.html">Scripting Languages</a> to allow an <a shape="rect" href="expression.html">Expression</a> or <a shape="rect" href="predicate.html">Predicate</a> to be used in the <a shape="rect" href="dsl.html">DSL</a> or <a shape="rect" href="xml-configuration.html">Xml Configuration</a>.</p><p>To use a Python expression use the following Java code</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[... python("somePythonExpression") ... ]]></script> @@ -6386,19 +6455,36 @@ result = body * 2 + 1 </choice> </route> ]]></script> -</div></div><p></p><h3 id="BookInOnePage-ScriptContextOptions.4"><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>cont ext</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 <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 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="BookInOnePage-PassingAdd itionalArgumentstotheScriptingEngine.4">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="BookInOnePage-UsingPropertiesFunction.4">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 h eader named <strong><code>foo</code></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="BookInOnePage-LoadingScriptFromExternalResource.4">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="BookInOnePage-HowtoGettheResultfromMultipleStatementsScript.4">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 -</plain-text-body><p> </p><h3 id="BookInOnePage-Dependencies.12">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> -</plain-text-body> +</div></div><p></p><h3 id="BookInOnePage-ScriptContextOptions.4"><code>ScriptContext</code> Options</h3><p> </p><p>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>.</p><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 col span="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 col span="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="BookInOnePage-PassingAdditionalArgumentstotheScrip tingEngine.4">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<>(); + 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="BookInOnePage-UsingPropertiesFunction.4"><br clear="none">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: groovy; 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="BookInOnePage-LoadingScriptFromExternalResource.4"><br clear="none">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="BookInOnePage-HowtoGettheResultfromMultipleStatementsScript.4"><br clear="none">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><p>textbar = "baz"; # some other statements ... # camel take the result value as the script evaluation result result = body * 2 + 1</p><p> </p><h3 id="BookInOnePage-Dependencies.12">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> + <groupId>org.apache.camel</groupId> + <artifactId>camel-script</artifactId> + <version>x.x.x</version> +</dependency>]]></script> +</div></div> <h2 id="BookInOnePage-PHP">PHP</h2> <p>Camel supports <a shape="rect" class="external-link" href="http://www.php.net/" rel="nofollow">PHP</a> among other <a shape="rect" href="scripting-languages.html">Scripting Languages</a> to allow an <a shape="rect" href="expression.html">Expression</a> or <a shape="rect" href="predicate.html">Predicate</a> to be used in the <a shape="rect" href="dsl.html">DSL</a> or <a shape="rect" href="xml-configuration.html">Xml Configuration</a>.</p> @@ -6413,19 +6499,36 @@ result = body * 2 + 1 <p>For example you could use the <strong>php</strong> function to create an <a shape="rect" href="predicate.html">Predicate</a> in a <a shape="rect" href="message-filter.html">Message Filter</a> or as an <a shape="rect" href="expression.html">Expression</a> for a <a shape="rect" href="recipient-list.html">Recipient List</a></p> -<h3 id="BookInOnePage-ScriptContextOptions.5"><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 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 <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 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="BookInOnePage-PassingAdditionalArgumentstot heScriptingEngine.5">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="BookInOnePage-UsingPropertiesFunction.5">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><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="BookInOnePage-LoadingScriptFromExternalResource.5">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="BookInOnePage-HowtoGettheResultfromMultipleStatementsScript.5">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 -</plain-text-body><p> </p><h3 id="BookInOnePage-Dependencies.13">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> -</plain-text-body> +<h3 id="BookInOnePage-ScriptContextOptions.5"><code>ScriptContext</code> Options</h3><p> </p><p>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>.</p><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 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 <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 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="BookInOnePage-PassingAdditionalArgumentstotheScriptingEngine.5">Passi ng 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);
[... 81 lines stripped ...]