camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From conflue...@apache.org
Subject [CONF] Apache Camel > CXF Bean Component
Date Sun, 08 Aug 2010 11:24:00 GMT
<html>
<head>
    <base href="https://cwiki.apache.org/confluence">
            <link rel="stylesheet" href="/confluence/s/1810/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/CXF+Bean+Component">CXF
Bean Component</a></h2>
    <h4>Page  <b>added</b> by             <a href="https://cwiki.apache.org/confluence/display/~christian%2Bschneider">Christian
Schneider</a>
    </h4>
         <br/>
    <div class="notificationGreySide">
         <h2><a name="CXFBeanComponent-CXFBeanComponent%282.0orlater%29"></a>CXF
Bean Component (<b>2.0 or later</b>)</h2>

<p>The <b>cxfbean:</b> component allows other Camel endpoints to send exchange
and invoke Web service bean objects.  (<b>Currently, it only supports JAXRS, JAXWS(new
to camel2.1) annotated service bean.</b>)</p>

<p><b>Note</b>: <tt>CxfBeanEndpoint</tt> is a <tt>ProcessorEndpoint</tt>
so it has no consumers.  It works similarly to a Bean component.</p>

<h3><a name="CXFBeanComponent-URIformat"></a>URI format</h3>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
cxfbean:serviceBeanRef
</pre>
</div></div>
<p>Where <b>serviceBeanRef</b> is a registry key to look up the service
bean object. If <tt>serviceBeanRef</tt> references a <tt>List</tt>
object, elements of the <tt>List</tt> are the service bean objects accepted by
the endpoint.</p>

<h3><a name="CXFBeanComponent-Options"></a>Options</h3>
<div class="confluenceTableSmall"><div class='table-wrap'>
<table class='confluenceTable'><tbody>
<tr>
<th class='confluenceTh'> Name </th>
<th class='confluenceTh'> Description </th>
<th class='confluenceTh'> Example </th>
<th class='confluenceTh'> Required? </th>
<th class='confluenceTh'> Default Value </th>
</tr>
<tr>
<td class='confluenceTd'> <tt>cxfBeanBinding</tt> </td>
<td class='confluenceTd'> CXF bean binding specified by the <tt>&#35;</tt>
notation.  The referenced object must be an instance of <tt>org.apache.camel.component.cxf.cxfbean.CxfBeanBinding</tt>.
</td>
<td class='confluenceTd'> <tt>cxfBinding=#bindingName</tt> </td>
<td class='confluenceTd'> No </td>
<td class='confluenceTd'> An instance of <tt>org.apache.camel.component.cxf.cxfbean.DefaultCxfBeanBinding</tt>
</td>
</tr>
<tr>
<td class='confluenceTd'> <tt>bus</tt> </td>
<td class='confluenceTd'> CXF bus reference specified by the <tt>&#35;</tt>
notation. The referenced object must be an instance of <tt>org.apache.cxf.Bus</tt>.
</td>
<td class='confluenceTd'> <tt>bus=#busName</tt> </td>
<td class='confluenceTd'> No </td>
<td class='confluenceTd'> Default bus created by CXF Bus Factory </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>headerFilterStrategy</tt> </td>
<td class='confluenceTd'> Header filter strategy specified by the <tt>&#35;</tt>
notation.  The referenced object must be an instance of <tt>org.apache.camel.spi.HeaderFilterStrategy</tt>.
</td>
<td class='confluenceTd'> <tt>headerFilterStrategy=#strategyName</tt> </td>
<td class='confluenceTd'> No </td>
<td class='confluenceTd'> An instance of <tt>org.apache.camel.component.cxf.CxfHeaderFilterStrategy</tt>
</td>
</tr>
<tr>
<td class='confluenceTd'> <tt>setDefaultBus</tt> </td>
<td class='confluenceTd'> Will set the default bus when CXF endpoint create a bus by
itself. </td>
<td class='confluenceTd'> <tt>true</tt>, <tt>false</tt> </td>
<td class='confluenceTd'> No </td>
<td class='confluenceTd'> <tt>false</tt> </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>populateFromClass</tt><br class="atl-forced-newline"
/> </td>
<td class='confluenceTd'> Since 2.3, the wsdlLocation annotated in the POJO is ignored
(by default) unless this option is set to&nbsp; <tt>false.</tt> Prior to 2.3,
the wsdlLocation annotated in the POJO is always honored and it is not possible to ignore.<br
class="atl-forced-newline" /> </td>
<td class='confluenceTd'> <tt>true</tt>, <tt>false</tt> </td>
<td class='confluenceTd'> No </td>
<td class='confluenceTd'> <tt>true</tt> </td>
</tr>
</tbody></table>
</div>
</div>

<h3><a name="CXFBeanComponent-Headers"></a>Headers</h3>
<div class="confluenceTableSmall"><div class='table-wrap'>
<table class='confluenceTable'><tbody>
<tr>
<th class='confluenceTh'> Name </th>
<th class='confluenceTh'> Description </th>
<th class='confluenceTh'> Type </th>
<th class='confluenceTh'> Required? </th>
<th class='confluenceTh'> Default Value </th>
<th class='confluenceTh'> In/Out </th>
<th class='confluenceTh'> Examples </th>
</tr>
<tr>
<td class='confluenceTd'> <tt>CamelHttpCharacterEncoding</tt> (before 2.0-m2:
<tt>CamelCxfBeanCharacterEncoding</tt>) </td>
<td class='confluenceTd'> Character encoding </td>
<td class='confluenceTd'> <tt>String</tt> </td>
<td class='confluenceTd'> No </td>
<td class='confluenceTd'> None </td>
<td class='confluenceTd'> In </td>
<td class='confluenceTd'> ISO-8859-1 </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>CamelContentType</tt> (before 2.0-m2: <tt>CamelCxfBeanContentType</tt>)
</td>
<td class='confluenceTd'> Content type </td>
<td class='confluenceTd'> <tt>String</tt> </td>
<td class='confluenceTd'> No </td>
<td class='confluenceTd'> &#42;<b>/</b>&#42; </td>
<td class='confluenceTd'> In </td>
<td class='confluenceTd'> <tt>text/xml</tt> </td>
</tr>
<tr>
<td class='confluenceTd'> CamelHttpBaseUri <br class="atl-forced-newline" />
(2.0-m3 and before: <tt>CamelCxfBeanRequestBasePath</tt>) </td>
<td class='confluenceTd'> The value of this header will be set in the CXF message as
the <tt>Message.BASE_PATH</tt> property.  It is needed by CXF JAX-RS processing.
 Basically, it is the scheme, host and port portion of the request URI. </td>
<td class='confluenceTd'> <tt>String</tt> </td>
<td class='confluenceTd'> Yes </td>
<td class='confluenceTd'> The Endpoint URI of the source endpoint in the Camel exchange
</td>
<td class='confluenceTd'> In </td>
<td class='confluenceTd'> <a href="http://localhost:9000" class="external-link" rel="nofollow">http://localhost:9000</a>
</td>
</tr>
<tr>
<td class='confluenceTd'> <tt>CamelHttpPath</tt> (before 2.0-m2: <tt>CamelCxfBeanRequestPat</tt>h)
</td>
<td class='confluenceTd'> Request URI's path </td>
<td class='confluenceTd'> <tt>String</tt> </td>
<td class='confluenceTd'> Yes </td>
<td class='confluenceTd'> None </td>
<td class='confluenceTd'> In </td>
<td class='confluenceTd'> <tt>consumer/123</tt> </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>CamelHttpMethod</tt> (before 2.0-m2: <tt>CamelCxfBeanVerb</tt>)
</td>
<td class='confluenceTd'> RESTful request verb </td>
<td class='confluenceTd'> <tt>String</tt> </td>
<td class='confluenceTd'> Yes </td>
<td class='confluenceTd'> None </td>
<td class='confluenceTd'> In </td>
<td class='confluenceTd'> <tt>GET</tt>, <tt>PUT</tt>, <tt>POST</tt>,
<tt>DELETE</tt> </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>CamelHttpResponseCode</tt> </td>
<td class='confluenceTd'> HTTP response code </td>
<td class='confluenceTd'> <tt>Integer</tt> </td>
<td class='confluenceTd'> No <br class="atl-forced-newline" /> </td>
<td class='confluenceTd'> None </td>
<td class='confluenceTd'> Out <br class="atl-forced-newline" /> </td>
<td class='confluenceTd'> 200 <br class="atl-forced-newline" /> </td>
</tr>
</tbody></table>
</div>
</div>
<p><b>Note: Currently, CXF Bean component has (only) been tested with Jetty HTTP
component it can understand headers from Jetty HTTP component without requiring conversion.</b></p>

<h3><a name="CXFBeanComponent-AWorkingSample"></a>A Working Sample</h3>

<p>This sample shows how to create a route that starts a Jetty HTTP server.  The route
sends requests to a CXF Bean and invokes a JAXRS annotated service.</p>

<p>First, create a route as follows.  The <tt>from</tt> endpoint is a Jetty
HTTP endpoint that is listening on port 9000.  Notice that the <tt>matchOnUriPrefix</tt>
option must be set to <tt>true</tt> because RESTful request URI will not match
the endpoint's URI http:­//localhost:9000 exactly.</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-xml"><span class="code-tag">&lt;route&gt;</span>
	<span class="code-tag">&lt;from uri=<span class="code-quote">"jetty:http://localhost:9000?matchOnUriPrefix=true"</span>
/&gt;</span>
	<span class="code-tag">&lt;to uri=<span class="code-quote">"cxfbean:customerServiceBean"</span>
/&gt;</span>
<span class="code-tag">&lt;/route&gt;</span>
</pre>
</div></div>
<p>The <tt>to</tt> endpoint is a CXF Bean with bean name <tt>customerServiceBean</tt>.
The name will be looked up from the registry.  Next, we make sure our service bean is available
in Spring registry.  We create a bean definition in the Spring configuration.  In this example,
we create a List of service beans (of one element).  We could have created just a single bean
without a List.</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-xml"><span class="code-tag">&lt;util:list id=<span class="code-quote">"customerServiceBean"</span>&gt;</span>
	<span class="code-tag">&lt;bean class=<span class="code-quote">"org.apache.camel.component.cxf.jaxrs.testbean.CustomerService"</span>
/&gt;</span>
<span class="code-tag">&lt;/util:list&gt;</span>

<span class="code-tag">&lt;bean class=<span class="code-quote">"org.apache.camel.wsdl_first.PersonImpl"</span>
id=<span class="code-quote">"jaxwsBean"</span> /&gt;</span>

</pre>
</div></div>
<p>That's it.  Once the route is started, the web service is ready for business.  A
HTTP client can make a request and receive response.</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">url = <span class="code-keyword">new</span> URL(<span
class="code-quote">"http:<span class="code-comment">//localhost:9000/customerservice/orders/223/products/323"</span>);
</span>in = url.openStream();
assertEquals(<span class="code-quote">"{\"</span>Product\<span class="code-quote">":{\"</span>description\<span
class="code-quote">":\"</span>product 323\<span class="code-quote">",\"</span>id\<span
class="code-quote">":323}}"</span>, CxfUtils.getStringFromInputStream(in));
</pre>
</div></div>

    </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/CXF+Bean+Component">View
Online</a>
              |
       <a href="https://cwiki.apache.org/confluence/display/CAMEL/CXF+Bean+Component?showComments=true&amp;showCommentArea=true#addcomment">Add
Comment</a>
           </div>
</div>
</div>
</div>
</div>
</body>
</html>

Mime
View raw message