Modified: websites/production/camel/content/using-camelproxy.html
==============================================================================
--- websites/production/camel/content/using-camelproxy.html (original)
+++ websites/production/camel/content/using-camelproxy.html Mon Aug 10 17:18:42
2015
@@ -86,14 +86,7 @@
<tbody>
<tr>
<td valign="top" width="100%">
-<div class="wiki-content maincontent"><h2
id="UsingCamelProxy-UsingCamelProxy">Using CamelProxy</h2>
-
-<p>Camel allows you to proxy a producer sending to an <a shape="rect"
href="endpoint.html">Endpoint</a> by a regular interface. Then when clients
using this interface can work with it as if its regular java code but in
reality its proxied and does a <a shape="rect"
href="request-reply.html">Request Reply</a> to a given endpoint.</p>
-
-<h3 id="UsingCamelProxy-ProxyfromSpring">Proxy from Spring</h3>
-
-<p>You can define a proxy in the spring XML file as shown below</p>
-<div class="code panel pdl" style="border-width: 1px;"><div class="codeContent
panelContent pdl">
+<div class="wiki-content maincontent"><h2
id="UsingCamelProxy-UsingCamelProxy">Using CamelProxy</h2><p>Camel allows you
to proxy a producer sending to an <a shape="rect"
href="endpoint.html">Endpoint</a> by a regular interface. Then when clients
using this interface can work with it as if its regular java code but in
reality its proxied and does a <a shape="rect"
href="request-reply.html">Request Reply</a> to a given endpoint.</p><h3
id="UsingCamelProxy-ProxyfromSpring">Proxy from Spring</h3><p>You can define a
proxy in the spring XML file as shown below</p><div class="code panel pdl"
style="border-width: 1px;"><div class="codeContent panelContent pdl">
<script class="brush: xml; gutter: false; theme: Default"
type="syntaxhighlighter"><![CDATA[
<camelContext xmlns="http://camel.apache.org/schema/spring">
@@ -113,11 +106,7 @@
</camelContext>
]]></script>
-</div></div>
-
-<p>Now the client can grab this bean using regular spring bean coding and
invoke it as if its just another bean.<br clear="none">
-The code is based on an unit test but proves the point:</p>
-<div class="code panel pdl" style="border-width: 1px;"><div class="codeContent
panelContent pdl">
+</div></div>Now the client can grab this bean using regular spring bean coding
and invoke it as if its just another bean.<br clear="none"> The code is based
on an unit test but proves the point:<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[
ApplicationContext ac = new
ClassPathXmlApplicationContext("org/apache/camel/spring/config/AnotherCamelProxyTest.xml");
@@ -126,20 +115,11 @@ String reply = sender.hello("Camel&
assertEquals("Bye Camel", reply);
]]></script>
-</div></div>
-
-<h3 id="UsingCamelProxy-ProxyfromJava">Proxy from Java</h3>
-
-<p>You can also create a proxy from regular Java using a
<code>org.apache.camel.component.bean.ProxyHelper</code> as shown below:</p>
-<div class="code panel pdl" style="border-width: 1px;"><div class="codeContent
panelContent pdl">
-<script class="brush: java; gutter: false; theme: Default"
type="syntaxhighlighter"><![CDATA[
- Endpoint endpoint = context.getEndpoint("direct:start");
+</div></div><h3 id="UsingCamelProxy-ProxyfromJava">Proxy from Java</h3><p>You
can also create a proxy from regular Java using a
<code>org.apache.camel.component.bean.ProxyHelper</code> as shown
below:</p><div class="code panel pdl" style="border-width: 1px;"><div
class="codeContent panelContent pdl">
+<script class="brush: java; gutter: false; theme: Default"
type="syntaxhighlighter"><![CDATA[ Endpoint endpoint =
context.getEndpoint("direct:start");
MyProxySender sender = ProxyHelper.createProxy(endpoint,
MyProxySender.class);
]]></script>
-</div></div>
-
-<p>In <strong>Camel 2.3</strong> you can use
<code>org.apache.camel.builder.ProxyBuilder</code> which may be easier to use
than ProxyHelper:</p>
-<div class="code panel pdl" style="border-width: 1px;"><div class="codeContent
panelContent pdl">
+</div></div><p>In <strong>Camel 2.3</strong> you can use
<code>org.apache.camel.builder.ProxyBuilder</code> which may be easier to use
than ProxyHelper:</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 testProxyBuilderProxyCallAnotherBean() throws Exception {
// use ProxyBuilder to easily create the proxy
@@ -149,44 +129,26 @@ public void testProxyBuilderProxyCallAno
assertEquals("Hello World", reply);
}
]]></script>
-</div></div>
-
-
-<h3 id="UsingCamelProxy-ProxywithAnnotation">Proxy with Annotation</h3>
-
-<p>Another way to configure the proxy from java is by using the @Produce
annotation. Also see <a shape="rect" href="pojo-producing.html">POJO
Producing</a>.</p>
-<div class="code panel pdl" style="border-width: 1px;"><div class="codeContent
panelContent pdl">
-<script class="brush: java; gutter: false; theme: Default"
type="syntaxhighlighter"><![CDATA[
-@Produce(uri="direct:start")
+</div></div><h3 id="UsingCamelProxy-ProxywithAnnotation">Proxy with
Annotation</h3><p>Another way to configure the proxy from java is by using the
@Produce annotation. Also see <a shape="rect" href="pojo-producing.html">POJO
Producing</a>.</p><div class="code panel pdl" style="border-width: 1px;"><div
class="codeContent panelContent pdl">
+<script class="brush: java; gutter: false; theme: Default"
type="syntaxhighlighter"><![CDATA[@Produce(uri="direct:start")
MyProxySender sender;
]]></script>
-</div></div>
-
-<p>This basically does the same as ProxyHelper.createProxy.</p>
-
-<h3 id="UsingCamelProxy-WhatissendontheMessage">What is send on the
Message</h3>
-<p>When using a proxy Camel will send the message payload as a
<code>org.apache.camel.component.bean.BeanInvocation</code> object which holds
the details of which method was invoked and what the argument was.</p>
-
-<h3
id="UsingCamelProxy-TurningtheBeanInvocationintoafirstclasspayload">Turning the
BeanInvocation into a first class payload</h3>
-<p><strong>Available as of Camel 2.1</strong></p>
-
-<p>If you proxied method signature only have one parameter such as:</p>
-<div class="code panel pdl" style="border-width: 1px;"><div class="codeContent
panelContent pdl">
-<script class="brush: java; gutter: false; theme: Default"
type="syntaxhighlighter"><![CDATA[
-String hello(String name);
+</div></div><p>This basically does the same as ProxyHelper.createProxy.</p><h3
id="UsingCamelProxy-WhatissendontheMessage">What is send on the
Message</h3><p>When using a proxy Camel will send the message payload as a
<code>org.apache.camel.component.bean.BeanInvocation</code> object (*Camel 2.15
or older) which holds the details of which method was invoked and what the
argument was. From <strong style="line-height: 1.4285715;">Camel
2.16</strong> onwards Camel parameter binding is enabled by default, which will
use binding information from the method signature parameters to bind to the
Exchange/Message with the following annotations</p><div
class="table-wrap"><table class="confluenceTable"><tbody><tr><th colspan="1"
rowspan="1" class="confluenceTh">Annotation</th><th colspan="1" rowspan="1"
class="confluenceTh">Binds to</th></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd">@Body</td><td colspan="1" rowspan="1"
class="confluenceTd">Binds the parameter to the messag
e body</td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd">@Header(name)</td><td colspan="1" rowspan="1"
class="confluenceTd">Binds the parameter to the message header with the given
name</td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd">@ExchangeProperty(name)</td><td colspan="1" rowspan="1"
class="confluenceTd">Binds the parameter to the exchange property with the
given name</td></tr></tbody></table></div><p>If a parameter does not have any
annotation then the parameter is bound to the message body.</p><p>For example
given the following interface</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 interface MyAuditService {
+ void auditMessage(@Header("uuid") String uuid, @Body String
body);
+}]]></script>
+</div></div><p>Then from Java DSL we can create a proxy and call the
method</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[// must enable binding on proxy
+MyAuditService service = new
ProxyBuilder(context).endpoint("jms:queue:foo").build(MyAuditService.class);
+service.auditMessage("1234", "Hello World");]]></script>
+</div></div><p>Which will send the message to the JMS queue foo, with the
header(uuid)=1234 and body=Hello World. The message is sent as InOnly as the
method is void.</p><p>The old behavior can be enabled by setting binding off,
such as:</p><div class="code panel pdl" style="border-width: 1px;"><div
class="codeContent panelContent pdl">
+<script class="brush: java; gutter: false; theme: Default"
type="syntaxhighlighter"><![CDATA[// must enable binding on proxy
+MyAuditService service = new
ProxyBuilder(context).endpoint("jms:queue:foo").binding(false).build(MyAuditService.class);
+service.auditMessage("1234", "Hello World");]]></script>
+</div></div><h3
id="UsingCamelProxy-TurningtheBeanInvocationintoafirstclasspayload">Turning the
BeanInvocation into a first class payload</h3><p><strong>Available as of Camel
2.1</strong></p><p>If you proxied method signature only have one parameter such
as:</p><div class="code panel pdl" style="border-width: 1px;"><div
class="codeContent panelContent pdl">
+<script class="brush: java; gutter: false; theme: Default"
type="syntaxhighlighter"><![CDATA[String hello(String name);
]]></script>
-</div></div>
-
-<p>Then it gives another advantage in Camel as it allows Camel to regard the
value passed in to this single parameter as the <em>real</em> payload. In other
words if you pass in <code>Camel</code> to the hello method, then Camel can
<em>see</em> that as a <code>java.lang.String</code> payload with the value of
<code>Camel</code>. This gives you a great advantage as you can use the proxy
as first class services with Camel.</p>
-
-<p>You can proxy Camel and let clients use the pure and clean interfaces as if
Camel newer existed. Then Camel can proxy the invocation and receive the input
passed into the single method parameter and regard that as if it was
<em>just</em> the message payload.</p>
-
-<p>Okay lets try that with an example</p>
-
-<h4 id="UsingCamelProxy-Examplewithproxyusingsingleparametermethods.">Example
with proxy using single parameter methods.</h4>
-
-<p>At first we have the interface we wish to proxy</p>
-<div class="code panel pdl" style="border-width: 1px;"><div class="codeContent
panelContent pdl">
+</div></div><p>Then it gives another advantage in Camel as it allows Camel to
regard the value passed in to this single parameter as the <em>real</em>
payload. In other words if you pass in <code>Camel</code> to the hello method,
then Camel can <em>see</em> that as a <code>java.lang.String</code> payload
with the value of <code>Camel</code>. This gives you a great advantage as you
can use the proxy as first class services with Camel.</p><p>You can proxy Camel
and let clients use the pure and clean interfaces as if Camel newer existed.
Then Camel can proxy the invocation and receive the input passed into the
single method parameter and regard that as if it was <em>just</em> the message
payload.</p><div class="confluence-information-macro
confluence-information-macro-information"><span class="aui-icon aui-icon-small
aui-iconfont-info confluence-information-macro-icon"></span><div
class="confluence-information-macro-body"><p>From <strong>Camel
2.16</strong> onwards this is im
proved as binding is enabled out of the box, where Camel binds to the message
parameters using the annotation listed in the table above. If a parameter has
no annotation then the parameter is bound to the message
body.</p></div></div><p> </p><p>Okay lets try that with an example</p><h4
id="UsingCamelProxy-Examplewithproxyusingsingleparametermethods.">Example with
proxy using single parameter methods.</h4><p>At first we have the interface we
wish to proxy</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 interface OrderService {
@@ -206,16 +168,7 @@ public interface OrderService {
}
]]></script>
-</div></div>
-
-<p>Notice that all methods have single parameters. The return type is
optional, as you can see one of them is void.<br clear="none">
-Also what you should know is that Camel uses its <a shape="rect"
href="type-converter.html">Type Converter</a> mechanism to adapt to the types
defined on the methods.</p>
-
-<p>This allows us to easily use <code>org.w3c.dom.Document</code> and
<code>String</code> types with no hazzle.</p>
-
-<p>Okay then we have the following route where we route using a <a
shape="rect" href="content-based-router.html">Content Based Router</a> that is
XML based. See that we use <a shape="rect" href="xpath.html">XPath</a> in the
choices to route the message depending on its a book order or not.</p>
-
-<div class="code panel pdl" style="border-width: 1px;"><div class="codeContent
panelContent pdl">
+</div></div>Notice that all methods have single parameters. The return type is
optional, as you can see one of them is void.<br clear="none"> Also what you
should know is that Camel uses its <a shape="rect"
href="type-converter.html">Type Converter</a> mechanism to adapt to the types
defined on the methods.<p>This allows us to easily use
<code>org.w3c.dom.Document</code> and <code>String</code> types with no
hazzle.</p><p>Okay then we have the following route where we route using a <a
shape="rect" href="content-based-router.html">Content Based Router</a> that is
XML based. See that we use <a shape="rect" href="xpath.html">XPath</a> in the
choices to route the message depending on its a book order or not.</p><div
class="code panel pdl" style="border-width: 1px;"><div class="codeContent
panelContent pdl">
<script class="brush: java; gutter: false; theme: Default"
type="syntaxhighlighter"><![CDATA[
from("direct:start")
.choice()
@@ -227,11 +180,7 @@ from("direct:book").transform(
from("direct:other").transform(constant("<order>FAIL</order>"));
]]></script>
-</div></div>
-
-<p>Now there is a couple of tests that shows using the Camel Proxy how we can
easily invoke the proxy and do not know its actually Camel doing some routing
underneath.</p>
-
-<div class="code panel pdl" style="border-width: 1px;"><div class="codeContent
panelContent pdl">
+</div></div>Now there is a couple of tests that shows using the Camel Proxy
how we can easily invoke the proxy and do not know its actually Camel doing
some routing underneath.<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[
Endpoint endpoint = context.getEndpoint("direct:start");
OrderService service = ProxyHelper.createProxy(endpoint, OrderService.class);
@@ -239,10 +188,7 @@ OrderService service = ProxyHelper.creat
String reply = service.submitOrderStringReturnString("<order
type=\"book\">Camel in action</order>");
assertEquals("<order id=\"123\">OK</order>",
reply);
]]></script>
-</div></div>
-
-<p>And this one below shows using different types that Camel adapts to.</p>
-<div class="code panel pdl" style="border-width: 1px;"><div class="codeContent
panelContent pdl">
+</div></div>And this one below shows using different types that Camel adapts
to.<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[
Endpoint endpoint = context.getEndpoint("direct:start");
OrderService service = ProxyHelper.createProxy(endpoint, OrderService.class);
@@ -254,18 +200,7 @@ assertNotNull(reply);
String s = context.getTypeConverter().convertTo(String.class, reply);
assertEquals("<order id=\"123\">OK</order>",
s);
]]></script>
-</div></div>
-
-<p>Isn't this cool?</p>
-
-
-<h3 id="UsingCamelProxy-AsynchronoususingFuture">Asynchronous using Future</h3>
-<p><strong>Available as of Camel 2.8</strong></p>
-
-<p>By default the <a shape="rect" href="using-camelproxy.html">Camel Proxy</a>
invocation is synchronous when invoked from the client. If you want this to be
asynchronous you define the return type to be of
<code>java.util.concurrent.Future</code> type. The <code>Future</code> is a
handle to the task which the client can use to obtain the result.</p>
-
-<p>For example given this client interface</p>
-<div class="code panel pdl" style="border-width: 1px;"><div class="codeHeader
panelHeader pdl" style="border-bottom-width: 1px;"><b>Client
Interface</b></div><div class="codeContent panelContent pdl">
+</div></div>Isn't this cool?<h3
id="UsingCamelProxy-AsynchronoususingFuture">Asynchronous using
Future</h3><p><strong>Available as of Camel 2.8</strong></p><p>By default the
<a shape="rect" href="using-camelproxy.html">Camel Proxy</a> invocation is
synchronous when invoked from the client. If you want this to be asynchronous
you define the return type to be of <code>java.util.concurrent.Future</code>
type. The <code>Future</code> is a handle to the task which the client can use
to obtain the result.</p><p>For example given this client interface</p><div
class="code panel pdl" style="border-width: 1px;"><div class="codeHeader
panelHeader pdl" style="border-bottom-width: 1px;"><b>Client
Interface</b></div><div class="codeContent panelContent pdl">
<script class="brush: java; gutter: false; theme: Default"
type="syntaxhighlighter"><![CDATA[
public interface Echo {
@@ -274,10 +209,7 @@ public interface Echo {
}
]]></script>
-</div></div>
-
-<p>The client can use this with a <a shape="rect"
href="using-camelproxy.html">Camel Proxy</a> as shown from the following
snippet from an unit test:</p>
-<div class="code panel pdl" style="border-width: 1px;"><div class="codeHeader
panelHeader pdl" style="border-bottom-width: 1px;"><b>Using
Client</b></div><div class="codeContent panelContent pdl">
+</div></div>The client can use this with a <a shape="rect"
href="using-camelproxy.html">Camel Proxy</a> as shown from the following
snippet from an unit test:<div class="code panel pdl" style="border-width:
1px;"><div class="codeHeader panelHeader pdl" style="border-bottom-width:
1px;"><b>Using Client</b></div><div class="codeContent panelContent pdl">
<script class="brush: java; gutter: false; theme: Default"
type="syntaxhighlighter"><![CDATA[
public void testFutureEcho() throws Exception {
Echo service =
ProxyHelper.createProxy(context.getEndpoint("direct:echo"),
Echo.class);
@@ -290,15 +222,7 @@ public void testFutureEcho() throws Exce
assertEquals("Four", reply);
}
]]></script>
-</div></div>
-
-<p>This allows you to fully define your client API without any Camel
dependency at all, and decide whether the invocation should be synchronous or
asynchronous.</p>
-
-<p>If the Client is asynchronous (return type is Future) then Camel will
continue processing the invocation using a thread pool which is being looked up
using the key <code>CamelInvocationHandler</code>. Its a shared thread pool for
all <a shape="rect" href="using-camelproxy.html">Camel Proxy</a> in the <a
shape="rect" href="camelcontext.html">CamelContext</a>. You can define a <a
shape="rect" href="threading-model.html">thread pool profile</a> with the id
<code>CamelInvocationHandler</code> to configure settings such as min/max
threads etc.</p>
-
-
-<h3 id="UsingCamelProxy-Seealso">See also</h3>
-<ul class="alternate"><li><a shape="rect" href="bean.html">Bean</a></li><li><a
shape="rect" href="user-guide.html">User Guide</a></li><li><a shape="rect"
href="tutorial-jmsremoting.html">Tutorial-JmsRemoting</a></li></ul></div>
+</div></div>This allows you to fully define your client API without any Camel
dependency at all, and decide whether the invocation should be synchronous or
asynchronous.<p>If the Client is asynchronous (return type is Future) then
Camel will continue processing the invocation using a thread pool which is
being looked up using the key <code>CamelInvocationHandler</code>. Its a shared
thread pool for all <a shape="rect" href="using-camelproxy.html">Camel
Proxy</a> in the <a shape="rect" href="camelcontext.html">CamelContext</a>. You
can define a <a shape="rect" href="threading-model.html">thread pool
profile</a> with the id <code>CamelInvocationHandler</code> to configure
settings such as min/max threads etc.</p><h3 id="UsingCamelProxy-Seealso">See
also</h3><ul class="alternate"><li><a shape="rect"
href="bean.html">Bean</a></li><li><a shape="rect" href="user-guide.html">User
Guide</a></li><li><a shape="rect"
href="tutorial-jmsremoting.html">Tutorial-JmsRemoting</a></li></ul></div>
</td>
<td valign="top">
<div class="navigation">