camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From conflue...@apache.org
Subject [CONF] Apache Camel > How do I configure endpoints
Date Mon, 25 Mar 2013 15:18:00 GMT
<html>
<head>
    <base href="https://cwiki.apache.org/confluence">
            <link rel="stylesheet" href="/confluence/s/2042/9/1/_/styles/combined.css?spaceKey=CAMEL&amp;forWysiwyg=true"
type="text/css">
    </head>
<body style="background: white;" bgcolor="white" class="email-body">
<div id="pageContent">
<div id="notificationFormat">
<div class="wiki-content">
<div class="email">
    <h2><a href="https://cwiki.apache.org/confluence/display/CAMEL/How+do+I+configure+endpoints">How
do I configure endpoints</a></h2>
    <h4>Page <b>edited</b> by             <a href="https://cwiki.apache.org/confluence/display/~davsclaus">Claus
Ibsen</a>
    </h4>
        <br/>
                         <h4>Changes (2)</h4>
                                 
    
<div id="page-diffs">
                    <table class="diff" cellpadding="0" cellspacing="0">
    
            <tr><td class="diff-snipped" >...<br></td></tr>
            <tr><td class="diff-unchanged" >In the above example, we have declare
the password value as raw, and the actual password would be as typed, eg {{se+re?t&amp;23}}.
<br> <br></td></tr>
            <tr><td class="diff-added-lines" style="background-color: #dfd;">h4.
Using property placeholders <br> <br>Camel have extensive support for using property
placeholders, which you can read more [about here|Using PropertyPlaceholder]. For example
in the ftp example above we can externalize the password to a .properties file. <br>
<br>For example configuring the property placeholder when using a [XML DSL|DSL], where
we declare the location of the .properties file. Though we can also define this in Java code.
See the [documentation|Using PropertyPlaceholder] for more details. <br>{code:xml} <br>&lt;camelContext
...&gt; <br>   &lt;propertyPlaceholder id=&quot;properties&quot; location=&quot;myftp.properties&quot;/&gt;
<br>   ... <br>&lt;/camelContext&gt; <br>{code} <br> <br>And
the Camel route now refers to the placeholder using the {{ key }} notation: <br>{code}
<br>.to(&quot;ftp:joe@myftpserver.com?password={{myFtpPassword}}&amp;binary=true&quot;
<br>{code} <br> <br>And have a myftp.properties file with password. Notice
we still define the RAW(value) style to ensure the password is used _as is_  <br>{code}
<br>myFtpPassword=RAW(se+re?t&amp;23) <br>{code} <br> <br>We could
still have used the RAW(value) in the Camel route instead: <br>{code} <br>.to(&quot;ftp:joe@myftpserver.com?password=RAW({{myFtpPassword}})&amp;binary=true&quot;
<br>{code} <br> <br>And then we would need to remove the RAW from the properties
file: <br>{code} <br>myFtpPassword=se+re?t&amp;23 <br>{code} <br>
<br>To understand more about property placeholders, read the [documentation|Using PropertyPlaceholder].
<br> <br></td></tr>
            <tr><td class="diff-unchanged" >h2. See Also <br> <br></td></tr>
            <tr><td class="diff-snipped" >...<br></td></tr>
            <tr><td class="diff-unchanged" >* [Spring] <br>* [URIs] <br></td></tr>
            <tr><td class="diff-added-lines" style="background-color: #dfd;">*
[Using PropertyPlaceholder] <br></td></tr>
    
            </table>
    </div>                            <h4>Full Content</h4>
                    <div class="notificationGreySide">
        <h2><a name="HowdoIconfigureendpoints-HowdoIconfigureendpoints%3F"></a>How
do I configure endpoints?</h2>

<p>There are a few different approaches to configuring components and endpoints. </p>

<h3><a name="HowdoIconfigureendpoints-UsingJavaCode"></a>Using Java Code</h3>

<p>You can explicitly configure a <a href="/confluence/display/CAMEL/Component" title="Component">Component</a>
using Java code as shown in this <a href="/confluence/display/CAMEL/Walk+through+an+Example"
title="Walk through an Example">example</a> </p>

<p>Or you can explicitly get hold of an <a href="/confluence/display/CAMEL/Endpoint"
title="Endpoint">Endpoint</a> and configure it using Java code as shown in the <a
href="/confluence/display/CAMEL/Mock" title="Mock">Mock endpoint examples</a>.</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
SomeEndpoint endpoint = camelContext.getEndpoint(<span class="code-quote">"someURI"</span>,
SomeEndpoint.class);
endpoint.setSomething(<span class="code-quote">"aValue"</span>);
</pre>
</div></div>

<h3><a name="HowdoIconfigureendpoints-UsingGuice"></a>Using Guice</h3>

<p>You can also use <a href="/confluence/display/CAMEL/Guice" title="Guice">Guice</a>
as the dependency injection framework. For example see the <a href="/confluence/display/CAMEL/Guice+JMS+Example"
title="Guice JMS Example">Guice JMS Example</a></p>

<h3><a name="HowdoIconfigureendpoints-UsingSpringXML"></a>Using Spring XML</h3>

<p>You can configure your <a href="/confluence/display/CAMEL/Component" title="Component">Component</a>
or <a href="/confluence/display/CAMEL/Endpoint" title="Endpoint">Endpoint</a>
instances in your <a href="/confluence/display/CAMEL/Spring" title="Spring">Spring</a>
XML as follows. </p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-xml"><span class="code-tag">&lt;camelContext id=<span
class="code-quote">"camel"</span> xmlns=<span class="code-quote">"http://camel.apache.org/schema/spring"</span>&gt;</span>
    <span class="code-tag">&lt;jmxAgent id=<span class="code-quote">"agent"</span>
disabled=<span class="code-quote">"true"</span>/&gt;</span>
<span class="code-tag">&lt;/camelContext&gt;</span>

<span class="code-tag">&lt;bean id=<span class="code-quote">"activemq"</span>
class=<span class="code-quote">"org.apache.activemq.camel.component.ActiveMQComponent"</span>&gt;</span>
  <span class="code-tag">&lt;property name=<span class="code-quote">"connectionFactory"</span>&gt;</span>
    <span class="code-tag">&lt;bean class=<span class="code-quote">"org.apache.activemq.ActiveMQConnectionFactory"</span>&gt;</span>
      <span class="code-tag">&lt;property name=<span class="code-quote">"brokerURL"</span>
value=<span class="code-quote">"vm://localhost?broker.persistent=false&amp;amp;broker.useJmx=false"</span>/&gt;</span>
    <span class="code-tag">&lt;/bean&gt;</span>
  <span class="code-tag">&lt;/property&gt;</span>
<span class="code-tag">&lt;/bean&gt;</span>
</pre>
</div></div>

<p>Which allows you to configure a component using some name (activemq in the above
example), then you can refer to the component using <b>activemq:[queue:&#124;topic:]destinationName</b>.
This works by the SpringCamelContext lazily fetching components from the spring context for
the scheme name you use for <a href="/confluence/display/CAMEL/Endpoint" title="Endpoint">Endpoint</a>
<a href="/confluence/display/CAMEL/URIs" title="URIs">URIs</a></p>

<h3><a name="HowdoIconfigureendpoints-UsingEndpointURIs"></a>Using Endpoint
URIs</h3>

<p>Another approach is to use the URI syntax. The URI syntax supports the query notation.
So for example with the <a href="/confluence/display/CAMEL/Mail" title="Mail">Mail</a>
component you can configure the password property via the URI</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
pop3:<span class="code-comment">//host:port?password=foo</span>
</pre>
</div></div>

<h4><a name="HowdoIconfigureendpoints-ReferringbeansfromEndpointURIs"></a>Referring
beans from Endpoint URIs </h4>
<p><b>Available as of Camel 2.0</b></p>

<p>When configuring endpoints using URI syntax you can now refer to beans in the <a
href="/confluence/display/CAMEL/Registry" title="Registry">Registry</a> using the
# notation.<br/>
If the parameter value starts with a <tt>#</tt> sign then Camel will lookup in
the <a href="/confluence/display/CAMEL/Registry" title="Registry">Registry</a>
for a bean of the given type. For instance:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
file:<span class="code-comment">//inbox?sorter=#mySpecialFileSorter</span>
</pre>
</div></div>
<p>Will lookup a bean with the id <b>mySpecialFileSorter</b> in the <a
href="/confluence/display/CAMEL/Registry" title="Registry">Registry</a>.</p>

<h4><a name="HowdoIconfigureendpoints-Configuringparametervaluesusingrawvalues%2Cegsuchaspasswords"></a>Configuring
parameter values using raw values, eg such as passwords</h4>
<p><b>Available as of Camel 2.11</b></p>

<p>When configuring endpoint options using URI syntax, then the values is by default
URI encoded. This can be a problem if you want to configure passwords and just use the value
<em>as is</em> without any encoding. For example you may have a plus sign in the
password, which would be decimal encoded by default.</p>

<p>So from Camel 2.11 onwards we made this easier as you can denote a parameter value
to be <b>raw</b> using the following syntax <tt>RAW(value)</tt>. eg
the value starts with <tt>RAW(</tt> and then ends with the parenthesis <tt>)</tt>.
Here is a little example:</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
.to(<span class="code-quote">"ftp:joe@myftpserver.com?password=RAW(se+re?t&amp;23)&amp;binary=<span
class="code-keyword">true</span>"</span>
</pre>
</div></div>

<p>In the above example, we have declare the password value as raw, and the actual password
would be as typed, eg <tt>se+re?t&amp;23</tt>.</p>

<h4><a name="HowdoIconfigureendpoints-Usingpropertyplaceholders"></a>Using
property placeholders</h4>

<p>Camel have extensive support for using property placeholders, which you can read
more <a href="/confluence/display/CAMEL/Using+PropertyPlaceholder" title="Using PropertyPlaceholder">about
here</a>. For example in the ftp example above we can externalize the password to a
.properties file.</p>

<p>For example configuring the property placeholder when using a <a href="/confluence/display/CAMEL/DSL"
title="DSL">XML DSL</a>, where we declare the location of the .properties file. Though
we can also define this in Java code. See the <a href="/confluence/display/CAMEL/Using+PropertyPlaceholder"
title="Using PropertyPlaceholder">documentation</a> for more details.</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-xml">
<span class="code-tag">&lt;camelContext ...&gt;</span>
   <span class="code-tag">&lt;propertyPlaceholder id=<span class="code-quote">"properties"</span>
location=<span class="code-quote">"myftp.properties"</span>/&gt;</span>
   ...
<span class="code-tag">&lt;/camelContext&gt;</span>
</pre>
</div></div>

<p>And the Camel route now refers to the placeholder using the {{ key }} notation:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
.to(<span class="code-quote">"ftp:joe@myftpserver.com?password={{myFtpPassword}}&amp;binary=<span
class="code-keyword">true</span>"</span>
</pre>
</div></div>

<p>And have a myftp.properties file with password. Notice we still define the RAW(value)
style to ensure the password is used <em>as is</em> </p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
myFtpPassword=RAW(se+re?t&amp;23)
</pre>
</div></div>

<p>We could still have used the RAW(value) in the Camel route instead:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
.to(<span class="code-quote">"ftp:joe@myftpserver.com?password=RAW({{myFtpPassword}})&amp;binary=<span
class="code-keyword">true</span>"</span>
</pre>
</div></div>

<p>And then we would need to remove the RAW from the properties file:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
myFtpPassword=se+re?t&amp;23
</pre>
</div></div>

<p>To understand more about property placeholders, read the <a href="/confluence/display/CAMEL/Using+PropertyPlaceholder"
title="Using PropertyPlaceholder">documentation</a>.</p>

<h2><a name="HowdoIconfigureendpoints-SeeAlso"></a>See Also</h2>

<ul>
	<li><a href="/confluence/display/CAMEL/How+do+I+add+a+component" title="How do I
add a component">How do I add a component</a></li>
	<li><a href="/confluence/display/CAMEL/Spring" title="Spring">Spring</a></li>
	<li><a href="/confluence/display/CAMEL/URIs" title="URIs">URIs</a></li>
	<li><a href="/confluence/display/CAMEL/Using+PropertyPlaceholder" title="Using PropertyPlaceholder">Using
PropertyPlaceholder</a></li>
</ul>

    </div>
        <div id="commentsSection" class="wiki-content pageSection">
        <div style="float: right;">
            <a href="https://cwiki.apache.org/confluence/users/viewnotifications.action"
class="grey">Change Notification Preferences</a>
        </div>
        <a href="https://cwiki.apache.org/confluence/display/CAMEL/How+do+I+configure+endpoints">View
Online</a>
        |
        <a href="https://cwiki.apache.org/confluence/pages/diffpagesbyversion.action?pageId=53767&revisedVersion=16&originalVersion=15">View
Changes</a>
                |
        <a href="https://cwiki.apache.org/confluence/display/CAMEL/How+do+I+configure+endpoints?showComments=true&amp;showCommentArea=true#addcomment">Add
Comment</a>
            </div>
</div>
</div>
</div>
</div>
</body>
</html>

Mime
View raw message