Modified: websites/production/camel/content/cxfrs.html
==============================================================================
--- websites/production/camel/content/cxfrs.html (original)
+++ websites/production/camel/content/cxfrs.html Fri Aug 25 08:22:01 2017
@@ -36,17 +36,6 @@
<![endif]-->
- <link href='//camel.apache.org/styles/highlighter/styles/shCoreCamel.css'
rel='stylesheet' type='text/css' />
- <link href='//camel.apache.org/styles/highlighter/styles/shThemeCamel.css'
rel='stylesheet' type='text/css' />
- <script src='//camel.apache.org/styles/highlighter/scripts/shCore.js'
type='text/javascript'></script>
- <script src='//camel.apache.org/styles/highlighter/scripts/shBrushJava.js'
type='text/javascript'></script>
- <script src='//camel.apache.org/styles/highlighter/scripts/shBrushXml.js'
type='text/javascript'></script>
- <script src='//camel.apache.org/styles/highlighter/scripts/shBrushPlain.js'
type='text/javascript'></script>
-
- <script type="text/javascript">
- SyntaxHighlighter.defaults['toolbar'] = false;
- SyntaxHighlighter.all();
- </script>
<title>
Apache Camel: CXFRS
@@ -86,103 +75,28 @@
<tbody>
<tr>
<td valign="top" width="100%">
-<div class="wiki-content maincontent"><h2 id="CXFRS-CXFRSComponent">CXFRS
Component</h2><div class="confluence-information-macro
confluence-information-macro-note"><span class="aui-icon aui-icon-small
aui-iconfont-warning confluence-information-macro-icon"></span><div
class="confluence-information-macro-body"><p>When using CXF as a consumer, the
<a shape="rect" href="cxf-bean-component.html">CXF Bean Component</a> allows
you to factor out how message payloads are received from their processing as a
RESTful or SOAP web service. This has the potential of using a multitude of
transports to consume web services. The bean component's configuration is also
simpler and provides the fastest method to implement web services using Camel
and CXF.</p></div></div><p>The <strong>cxfrs:</strong> component provides
integration with <a shape="rect" href="http://cxf.apache.org">Apache CXF</a>
for connecting to JAX-RS 1.1 and 2.0 services hosted in CXF.</p><p>Maven users
will need to add the following
dependency to their pom.xml for this component:</p><div class="code panel
pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
-<script class="brush: xml; gutter: false; theme: Default"
type="syntaxhighlighter"><![CDATA[<dependency>
+<div class="wiki-content maincontent"><h2 id="CXFRS-CXFRSComponent">CXFRS
Component</h2><rich-text-body><p>When using CXF as a consumer, the <a
shape="rect" href="cxf-bean-component.html">CXF Bean Component</a> allows you
to factor out how message payloads are received from their processing as a
RESTful or SOAP web service. This has the potential of using a multitude of
transports to consume web services. The bean component's configuration is also
simpler and provides the fastest method to implement web services using Camel
and CXF.</p></rich-text-body><p>The <strong>cxfrs:</strong> component provides
integration with <a shape="rect" href="http://cxf.apache.org">Apache CXF</a>
for connecting to JAX-RS 1.1 and 2.0 services hosted in CXF.</p><p>Maven users
will need to add the following dependency to their pom.xml for this
component:</p><parameter
ac:name="">xml</parameter><plain-text-body><dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-cxf</artifactId>
<version>x.x.x</version> <!-- use the same version as your
Camel core version -->
</dependency>
-]]></script>
-</div></div><h3 id="CXFRS-URIformat">URI format</h3><div class="code panel
pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
-<script class="brush: java; gutter: false; theme: Default"
type="syntaxhighlighter"><![CDATA[cxfrs://address?options
-]]></script>
-</div></div><p>Where <strong>address</strong> represents the CXF endpoint's
address</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[cxfrs:bean:rsEndpoint
-]]></script>
-</div></div><p>Where <strong>rsEndpoint</strong> represents the spring bean's
name which presents the CXFRS client or server</p><p>For either style above,
you can append options to the URI as follows:</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[cxfrs:bean:cxfEndpoint?resourceClasses=org.apache.camel.rs.Example
-]]></script>
-</div></div><h3 id="CXFRS-Options">Options</h3><div class="table-wrap"><table
class="confluenceTable"><tbody><tr><th colspan="1" rowspan="1"
class="confluenceTh"><p>Name</p></th><th colspan="1" rowspan="1"
class="confluenceTh"><p>Description</p></th><th colspan="1" rowspan="1"
class="confluenceTh"><p>Example</p></th><th colspan="1" rowspan="1"
class="confluenceTh"><p>Required?</p></th><th colspan="1" rowspan="1"
class="confluenceTh"><p>default value</p></th></tr><tr><td colspan="1"
rowspan="1" class="confluenceTd"><p><code>resourceClasses</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p>The resource classes which you
want to export as REST service. Multiple classes can be separated by
comma.</p></td><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>resourceClasses=org.apache.camel.rs.Example1,</code><br
clear="none"> <code>org.apache.camel.rs.Exchange2</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p>No</p></td><td colspan="1"
rowspan="1"
class="confluenceTd"><p><em>None</em></p></td></tr><tr><td colspan="1"
rowspan="1" class="confluenceTd"><p><code>resourceClass</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p><strong>Deprecated</strong>:
Use <code>resourceClasses</code> The resource class which you want to export as
REST service.</p></td><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>resourceClass
=org.apache.camel.rs.Example1</code></p></td><td colspan="1" rowspan="1"
class="confluenceTd"><p>No</p></td><td colspan="1" rowspan="1"
class="confluenceTd"><p><em>None</em></p></td></tr><tr><td colspan="1"
rowspan="1" class="confluenceTd"><p><code>httpClientAPI</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p><strong>new to Camel
2.1</strong> If it is true, the CxfRsProducer will use the HttpClientAPI to
invoke the service <br clear="none" class="atl-forced-newline"> If it is false,
the CxfRsProducer will use the ProxyClientAPI to invoke the service</p></td><td
colspan="1" r
owspan="1" class="confluenceTd"><p>httpClientAPI=true</p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p>No</p></td><td colspan="1" rowspan="1"
class="confluenceTd"><p><em>true</em></p></td></tr><tr><td colspan="1"
rowspan="1" class="confluenceTd"><p><code>synchronous</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p>This option will let you decide
to use sync or async API to do the underlying work. The default value is false
which means it will try to use async API by default.</p><p>This option is
available as of <strong>2.5</strong> for CxfRsConsumer and as of
<strong>2.19</strong> for CxfRsProducer.</p></td><td colspan="1" rowspan="1"
class="confluenceTd"><p>synchronous=true</p></td><td colspan="1" rowspan="1"
class="confluenceTd"><p>No</p></td><td colspan="1" rowspan="1"
class="confluenceTd"><p>false</p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>throwExceptionOnFailure</code></p></td><td
colspan="1" rowspan="1" class="conflu
enceTd"><p>New in 2.6, this option tells the CxfRsProducer to inspect return
codes and will generate an Exception if the return code is larger than
207.</p></td><td colspan="1" rowspan="1"
class="confluenceTd"><p>throwExceptionOnFailure=true</p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p>No</p></td><td colspan="1" rowspan="1"
class="confluenceTd"><p>true</p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>maxClientCacheSize</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p>New in 2.6, you can set a IN message header
CamelDestinationOverrideUrl to dynamically override the target destination Web
Service or REST Service defined in your routes.  The implementation caches
CXF clients or ClientFactoryBean in CxfProvider and CxfRsProvider.  This
option allows you to configure the maximum size of the cache.</p></td><td
colspan="1" rowspan="1"
class="confluenceTd"><p>maxClientCacheSize=5</p></td><td colspan="1"
rowspan="1" class=
"confluenceTd"><p>No</p></td><td colspan="1" rowspan="1"
class="confluenceTd"><p>10</p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>setDefaultBus</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p>New in 2.9.0. <strong>deprecated</strong>
use defaultBus option from Camel 2.16 onwards. Will set the default bus when
CXF endpoint create a bus by itself</p></td><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>setDefaultBus=true</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p>No</p></td><td colspan="1" rowspan="1"
class="confluenceTd"><p><em>false</em></p></td></tr><tr><td colspan="1"
rowspan="1" class="confluenceTd"><code>defaultBus</code></td><td colspan="1"
rowspan="1" class="confluenceTd"><strong>Camel 2.16:</strong> <span>Will set
the default bus when CXF endpoint create a bus by itself</span></td><td
colspan="1" rowspan="1"
class="confluenceTd"><code>defaultBus=true</code></td><td colspan="1"
rowspan="1" class="
confluenceTd">No</td><td colspan="1" rowspan="1"
class="confluenceTd"><em>false</em></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>bus</code></p></td><td colspan="1" rowspan="1"
class="confluenceTd"><p>New in 2.9.0. A default bus created by CXF Bus Factory.
Use <code>#</code> notation to reference a bus object from the registry. The
referenced object must be an instance of
<code>org.apache.cxf.Bus</code>.</p></td><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>bus=#busName</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p>No</p></td><td colspan="1" rowspan="1"
class="confluenceTd"><p><em>None</em></p></td></tr><tr><td colspan="1"
rowspan="1" class="confluenceTd"><p><code>bindingStyle</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p><strong>As of 2.11</strong>.
Sets how requests and responses will be mapped to/from Camel. Two values are
possible:</p><ul class="alternate"><li><code>SimpleConsumer</code> => see th
e <a shape="rect"
href="#CXFRS-ConsumingaRESTRequest-SimpleBindingStyle">Consuming a REST Request
with the Simple Binding Style</a> below.</li><li><code>Default</code> => the
default style. For consumers this passes on a <code>MessageContentsList</code>
to the route, requiring low-level processing in the route.</li><li><span
style="font-family: monospace;">Custom</span> => allows you to specify a
custom binding through the <code>binding</code> option.</li></ul></td><td
colspan="1" rowspan="1"
class="confluenceTd"><p><code>bindingStyle=SimpleConsumer</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p>No</p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p><em>Default</em></p></td></tr><tr><td
colspan="1" rowspan="1"
class="confluenceTd"><p><code><span>binding</span></code></p></td><td
colspan="1" rowspan="1" class="confluenceTd">Allows you to specify a custom
<code>CxfRsBinding</code> implementation to perform low-level processing of the
raw CXF request a
nd response objects. The implementation must be bound in the Camel registry,
and you must use the hash (#) notation to refer to it.</td><td colspan="1"
rowspan="1"
class="confluenceTd"><code><span>binding=#myBinding</span></code></td><td
colspan="1" rowspan="1" class="confluenceTd">No</td><td colspan="1" rowspan="1"
class="confluenceTd"><code>DefaultCxfRsBinding</code></td></tr><tr><td
colspan="1" rowspan="1" class="confluenceTd"><p><code><span style="line-height:
1.4285715;">providers</span></code></p></td><td colspan="1" rowspan="1"
class="confluenceTd"><p><strong style="line-height: 1.4285715;">Since Camel
2.12.2</strong><span style="line-height: 1.4285715;"> set custom JAX-RS
providers list to the CxfRs endpoint.</span></p></td><td colspan="1"
rowspan="1"
class="confluenceTd"><p><code>providers=#MyProviders</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p>No</p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p><em style="line-height: 1.4285715;">None</em
></p></td></tr><tr><td colspan="1" rowspan="1"
>class="confluenceTd"><p><code><span style="line-height:
>1.4285715;">schemaLocations</span></code></p></td><td colspan="1" rowspan="1"
>class="confluenceTd"><p><strong style="line-height: 1.4285715;">Since Camel
>2.12.2</strong><span style="line-height: 1.4285715;"> Sets the locations of
>the schemas which can be used to validate the incoming XML or JAXB-driven
>JSON.</span></p></td><td colspan="1" rowspan="1"
>class="confluenceTd"><p><code>schemaLocations=#MySchemaLocations</code></p></td><td
> colspan="1" rowspan="1" class="confluenceTd"><p>No</p></td><td colspan="1"
>rowspan="1" class="confluenceTd"><p><em style="line-height:
>1.4285715;">None</em></p></td></tr><tr><td colspan="1" rowspan="1"
>class="confluenceTd"><p><code><span style="line-height:
>1.4285715;">features</span></code></p></td><td colspan="1" rowspan="1"
>class="confluenceTd"><p><strong style="line-height: 1.4285715;">Since Camel
>2.12.3</strong><span style="line-height: 1.4285715;"
> Set the feature list to the CxfRs endpoint.</span></p></td><td colspan="1"
> rowspan="1"
> class="confluenceTd"><p><code>features=#MyFeatures</code></p></td><td
> colspan="1" rowspan="1" class="confluenceTd"><p>No</p></td><td colspan="1"
> rowspan="1" class="confluenceTd"><p><em style="line-height:
> 1.4285715;">None</em></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><strong style="line-height:
> 1.4285715;">Since Camel 2.12.4</strong><span style="line-height:
> 1.4285715;"> Set the properties to the CxfRs endpoint.</span></p></td><td
> colspan="1" rowspan="1"
> class="confluenceTd"><p><code>properties=#MyProperties</code></p></td><td
> colspan="1" rowspan="1" class="confluenceTd"><p>No</p></td><td colspan="1"
> rowspan="1" class="confluenceTd"><p><em style="line-height:
> 1.4285715;">None</em></p></td></tr><tr><td colspan="1" rowspan="1"
> class="confluenceTd"><p><code>inInterceptors</code></p></td><
td colspan="1" rowspan="1" class="confluenceTd"><p><strong style="line-height:
1.4285715;">Since Camel 2.12.4</strong><span style="line-height: 1.4285715;">
Set the inInterceptors to the CxfRs endpoint.</span></p></td><td colspan="1"
rowspan="1"
class="confluenceTd"><p><code>inInterceptors=#MyInterceptors</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p>No</p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p><em style="line-height:
1.4285715;">None</em></p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>outInterceptors</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p><strong style="line-height:
1.4285715;">Since Camel 2.12.4</strong><span style="line-height: 1.4285715;">
Set the outInterceptor to the CxfRs endpoint.</span></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p><code><span style="line-height:
1.4285715;">outInterceptors=#MyInterceptors</span></code></p></td><td
colspan="1" rowspan="1" class="conf
luenceTd"><p><span style="line-height: 1.4285715;">No</span></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p><em style="line-height:
1.4285715;">None</em></p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p><code><span>inFaultInterceptors</span></code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p><strong style="line-height:
1.4285715;">Since Camel 2.12.4</strong><span style="line-height: 1.4285715;">
Set the inFaultInterceptors to the CxfRs endpoint.</span></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p><code><span style="line-height:
1.4285715;">inFaultInterceptors=#MyInterceptors</span></code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p><span style="line-height:
1.4285715;">No</span></p></td><td colspan="1" rowspan="1"
class="confluenceTd"><p><em style="line-height:
1.4285715;">None</em></p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>outFaultIntercetpros</code></p></td><td colspan=
"1" rowspan="1" class="confluenceTd"><p><strong style="line-height:
1.4285715;">Since Camel 2.12.4</strong><span style="line-height: 1.4285715;">
Set the outFaultInterceptors to the CxfRs endpoint.</span></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p><code><span style="line-height:
1.4285715;">outFaultInterceptors=#MyInterceptors</span></code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p><span style="line-height:
1.4285715;">No</span></p></td><td colspan="1" rowspan="1"
class="confluenceTd"><p><em style="line-height:
1.4285715;">None</em></p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>continuationTimeout</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p><span style="line-height:
1.4285715;"><strong>Since</strong> </span><strong style="line-height:
1.4285715;">Camel 2.14.0 </strong><span style="line-height:
1.4285715;">This option is used to set the CXF continuation timeout which could
be used in CxfC
onsumer by default when the CXF server is using Jetty or Servlet transport.
(Before </span><strong style="line-height: 1.4285715;">Camel
2.14.0</strong><span style="line-height: 1.4285715;">, CxfConsumer just set the
continuation timeout to be 0, which means the continuation suspend operation
never timeout.)</span></p></td><td colspan="1" rowspan="1"
class="confluenceTd"><p><code><span style="line-height:
1.4285715;">continuationTimeout=800000</span></code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p>No</p></td><td colspan="1" rowspan="1"
class="confluenceTd"><p><em style="line-height:
1.4285715;">30000</em></p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><code>ignoreDeleteMethodMessageBody</code></td><td
colspan="1" rowspan="1" class="confluenceTd"><strong>Since Camel
2.14.1</strong> This option is used to tell CxfRsProducer to ignore the message
body of the DELETE method when using HTTP API.</td><td colspan="1" rowspan="1"
class="confluenceTd
"><code><span>ignoreDeleteMethodMessageBody=true</span></code></td><td
colspan="1" rowspan="1" class="confluenceTd">No</td><td colspan="1" rowspan="1"
class="confluenceTd"><em>false</em></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>modelRef</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p><strong>Since Camel 2.14.2</strong> This
option is used to specify the <a shape="rect"
href="http://cxf.apache.org/docs/jax-rs-advanced-features.html#JAX-RSAdvancedFeatures-RESTfulserviceswithoutannotations">model
file</a> which is useful for the resource class without
annotation.</p><p><strong>Since Camel 2.15</strong> This option can point to a
model file without specifying a service class for emulating document-only
endpoints</p></td><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>modelRef=</code><a shape="rect"
class="external-link"
href="http://classpath/org/apache/camel/component/cxf/jaxrs/CustomerServiceModel.xml"
rel="nofollow" style="fo
nt-family: monospace;line-height:
1.4285715;">classpath:/CustomerServiceModel.xml</a></p></td><td colspan="1"
rowspan="1" class="confluenceTd">No</td><td colspan="1" rowspan="1"
class="confluenceTd"><em>None</em></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p class="p1"><code>performInvocation</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><strong>Since Camel 2.15</strong>
When the option is true, camel will perform the invocation of the resource
class instance and put the response object into the exchange for further
processing.</td><td colspan="1" rowspan="1" class="confluenceTd"><p
class="p1"><code>performInvocation= true</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd">No</td><td colspan="1" rowspan="1"
class="confluenceTd"><em>false</em></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><code>propagateContexts</code></td><td colspan="1"
rowspan="1" class="confluenceTd"><strong>Since Camel 2.15</strong> When the
optio
n is true, JAXRS <a shape="rect" class="external-link"
href="https://jax-rs-spec.java.net/nonav/2.0-rev-a/apidocs/javax/ws/rs/core/UriInfo.html"
rel="nofollow">UriInfo</a>, <a shape="rect" class="external-link"
href="https://jax-rs-spec.java.net/nonav/2.0-rev-a/apidocs/javax/ws/rs/core/HttpHeaders.html"
rel="nofollow">HttpHeaders</a>, <a shape="rect" class="external-link"
href="https://jax-rs-spec.java.net/nonav/2.0-rev-a/apidocs/javax/ws/rs/core/Request.html"
rel="nofollow">Request</a> and <a shape="rect" class="external-link"
href="https://jax-rs-spec.java.net/nonav/2.0-rev-a/apidocs/javax/ws/rs/core/SecurityContext.html"
rel="nofollow">SecurityContext</a> contexts will be available to custom CXFRS
processors as typed Camel exchange properties. These contexts can be used to
analyze the current requests using JAX-RS API.</td><td colspan="1" rowspan="1"
class="confluenceTd"> </td><td colspan="1" rowspan="1"
class="confluenceTd"> </td><td colspan="1" rowspan="1" class="conf
luenceTd"> </td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><code>loggingFeatureEnabled</code></td><td colspan="1"
rowspan="1" class="confluenceTd">This option enables CXF Logging Feature which
writes inbound and outbound REST messages to log.</td><td colspan="1"
rowspan="1" class="confluenceTd"> </td><td colspan="1" rowspan="1"
class="confluenceTd">No</td><td colspan="1" rowspan="1"
class="confluenceTd"><em>false</em></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><code>skipFaultLogging</code></td><td colspan="1"
rowspan="1" class="confluenceTd">This option controls whether the
<code>PhaseInterceptorChain</code> skips logging the Fault that it
catches.</td><td colspan="1" rowspan="1" class="confluenceTd"> </td><td
colspan="1" rowspan="1" class="confluenceTd">No</td><td colspan="1" rowspan="1"
class="confluenceTd"><em>false</em></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><code>loggingSizeLimit</code></td><td colspan="1"
rowspan="1" class="confluenceTd">To limit the total size of number of bytes
the logger will output when logging feature has been enabled.</td><td
colspan="1" rowspan="1" class="confluenceTd"> </td><td colspan="1"
rowspan="1" class="confluenceTd">No</td><td colspan="1" rowspan="1"
class="confluenceTd"><code>0</code></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><code>cookieHandler</code></td><td colspan="1" rowspan="1"
class="confluenceTd">Since <strong>Camel 2.19.0</strong> Configure a cookie
handler to maintain a HTTP session</td><td colspan="1" rowspan="1"
class="confluenceTd"><code>cookieHandler=#exchangeCookieHandler</code></td><td
colspan="1" rowspan="1" class="confluenceTd">No</td><td colspan="1" rowspan="1"
class="confluenceTd"><em>None</em></td></tr></tbody></table></div><p>You can
also configure the CXF REST endpoint through the spring configuration. Since
there are lots of difference between the CXF REST client and CXF REST Server,
we provide different
configuration for them.<br clear="none"> Please check out the <a shape="rect"
class="external-link"
href="http://svn.apache.org/repos/asf/camel/trunk/components/camel-cxf/src/main/resources/schema/cxfEndpoint.xsd">schema
file</a> and <a shape="rect" class="external-link"
href="https://cwiki.apache.org/CXF20DOC/JAX-RS">CXF JAX-RS documentation</a>
for more information.</p><h3
id="CXFRS-HowtoconfiguretheRESTendpointinCamel">How to configure the REST
endpoint in Camel</h3><p>In <a shape="rect" class="external-link"
href="http://svn.apache.org/repos/asf/camel/trunk/components/camel-cxf/src/main/resources/schema/cxfEndpoint.xsd">camel-cxf
schema file</a>, there are two elements for the REST endpoint definition.
<strong>cxf:rsServer</strong> for REST consumer, <strong>cxf:rsClient</strong>
for REST producer.<br clear="none"> You can find a Camel REST service route
configuration example here.</p><div class="code panel pdl" style="border-width:
1px;"><div class="codeContent panelContent pd
l">
-<script class="brush: xml; gutter: false; theme: Default"
type="syntaxhighlighter"><![CDATA[
-<beans xmlns="http://www.springframework.org/schema/beans"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xmlns:cxf="http://camel.apache.org/schema/cxf"
- xmlns:jaxrs="http://cxf.apache.org/jaxrs"
- xsi:schemaLocation="
- http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
- http://camel.apache.org/schema/cxf
http://camel.apache.org/schema/cxf/camel-cxf.xsd
- http://cxf.apache.org/jaxrs http://cxf.apache.org/schemas/jaxrs.xsd
- http://camel.apache.org/schema/spring
http://camel.apache.org/schema/spring/camel-spring.xsd
- ">
-
- <bean
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"/>
-
- <!-- Defined the real JAXRS back end service -->
- <jaxrs:server id="restService"
-
address="http://localhost:${CXFTestSupport.port2}/CxfRsRouterTest/rest"
- staticSubresourceResolution="true">
- <jaxrs:serviceBeans>
- <ref bean="customerService"/>
- </jaxrs:serviceBeans>
- </jaxrs:server>
-
- <bean id="jsonProvider"
class="org.apache.cxf.jaxrs.provider.json.JSONProvider"/>
-
- <bean id="customerService"
class="org.apache.camel.component.cxf.jaxrs.testbean.CustomerService"
/>
-
- <!-- Defined the server endpoint to create the cxf-rs consumer -->
- <cxf:rsServer id="rsServer"
address="http://localhost:${CXFTestSupport.port1}/CxfRsRouterTest/route"
-
serviceClass="org.apache.camel.component.cxf.jaxrs.testbean.CustomerService"
- loggingFeatureEnabled="true" loggingSizeLimit="20"
skipFaultLogging="true">
- <cxf:providers>
- <ref bean="jsonProvider"/>
- </cxf:providers>
- </cxf:rsServer>
-
- <!-- Defined the client endpoint to create the cxf-rs producer -->
- <cxf:rsClient id="rsClient"
address="http://localhost:${CXFTestSupport.port2}/CxfRsRouterTest/rest"
-
serviceClass="org.apache.camel.component.cxf.jaxrs.testbean.CustomerService"
- loggingFeatureEnabled="true"
skipFaultLogging="true">
- <cxf:providers>
- <ref bean="jsonProvider"/>
- </cxf:providers>
- </cxf:rsClient>
-
- <!-- The camel route context -->
- <camelContext id="camel"
xmlns="http://camel.apache.org/schema/spring">
- <route>
- <!-- Just need to ignoreDeleteMethodMessageBody -->
- <from uri="cxfrs://bean://rsServer"/>
- <to uri="log:body?level=INFO"/>
- <to
uri="cxfrs://bean://rsClient?ignoreDeleteMethodMessageBody=true&amp;synchronous=true"/>
- </route>
- </camelContext>
-
-</beans>
-]]></script>
-</div></div><h3
id="CXFRS-HowtooverridetheCXFproduceraddressfrommessageheader">How to override
the CXF producer address from message
header</h3><p>The <code>camel-cxfrs</code> producer supports to
override the services address by setting the message with the key of
"<span>CamelDestinationOverrideUrl".</span></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[ // set up the service address from the
message header to override the setting of CXF endpoint
+</plain-text-body><h3 id="CXFRS-URIformat">URI format</h3><parameter
ac:name="language">java</parameter><plain-text-body>cxfrs://address?options
+</plain-text-body><p>Where <strong>address</strong> represents the CXF
endpoint's address</p><parameter
ac:name="language">java</parameter><plain-text-body>cxfrs:bean:rsEndpoint
+</plain-text-body><p>Where <strong>rsEndpoint</strong> represents the spring
bean's name which presents the CXFRS client or server</p><p>For either style
above, you can append options to the URI as follows:</p><parameter
ac:name="language">java</parameter><plain-text-body>cxfrs:bean:cxfEndpoint?resourceClasses=org.apache.camel.rs.Example
+</plain-text-body><h3 id="CXFRS-Options">Options</h3><div
class="table-wrap"><table class="confluenceTable"><tbody><tr><th colspan="1"
rowspan="1" class="confluenceTh"><p>Name</p></th><th colspan="1" rowspan="1"
class="confluenceTh"><p>Description</p></th><th colspan="1" rowspan="1"
class="confluenceTh"><p>Example</p></th><th colspan="1" rowspan="1"
class="confluenceTh"><p>Required?</p></th><th colspan="1" rowspan="1"
class="confluenceTh"><p>default value</p></th></tr><tr><td colspan="1"
rowspan="1" class="confluenceTd"><p><code>resourceClasses</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p>The resource classes which you
want to export as REST service. Multiple classes can be separated by
comma.</p></td><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>resourceClasses=org.apache.camel.rs.Example1,</code><br
clear="none"> <code>org.apache.camel.rs.Exchange2</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p>No</p></td><td colspan="1"
rowspa
n="1" class="confluenceTd"><p><em>None</em></p></td></tr><tr><td colspan="1"
rowspan="1" class="confluenceTd"><p><code>resourceClass</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p><strong>Deprecated</strong>:
Use <code>resourceClasses</code> The resource class which you want to export as
REST service.</p></td><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>resourceClass
=org.apache.camel.rs.Example1</code></p></td><td colspan="1" rowspan="1"
class="confluenceTd"><p>No</p></td><td colspan="1" rowspan="1"
class="confluenceTd"><p><em>None</em></p></td></tr><tr><td colspan="1"
rowspan="1" class="confluenceTd"><p><code>httpClientAPI</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p><strong>new to Camel
2.1</strong> If it is true, the CxfRsProducer will use the HttpClientAPI to
invoke the service <br clear="none" class="atl-forced-newline"> If it is false,
the CxfRsProducer will use the ProxyClientAPI to invoke the service</p></td><td
colspan
="1" rowspan="1" class="confluenceTd"><p>httpClientAPI=true</p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p>No</p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p><em>true</em></p></td></tr><tr><td
colspan="1" rowspan="1"
class="confluenceTd"><p><code>synchronous</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p>This option will let you decide to use sync
or async API to do the underlying work. The default value is false which means
it will try to use async API by default.</p><p>This option is available as of
<strong>2.5</strong> for CxfRsConsumer and as of <strong>2.19</strong> for
CxfRsProducer.</p></td><td colspan="1" rowspan="1"
class="confluenceTd"><p>synchronous=true</p></td><td colspan="1" rowspan="1"
class="confluenceTd"><p>No</p></td><td colspan="1" rowspan="1"
class="confluenceTd"><p>false</p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>throwExceptionOnFailure</code></p></td><td
colspan="1" rowspan="1" class="
confluenceTd"><p>New in 2.6, this option tells the CxfRsProducer to inspect
return codes and will generate an Exception if the return code is larger than
207.</p></td><td colspan="1" rowspan="1"
class="confluenceTd"><p>throwExceptionOnFailure=true</p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p>No</p></td><td colspan="1" rowspan="1"
class="confluenceTd"><p>true</p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>maxClientCacheSize</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p>New in 2.6, you can set a IN message header
CamelDestinationOverrideUrl to dynamically override the target destination Web
Service or REST Service defined in your routes.  The implementation caches
CXF clients or ClientFactoryBean in CxfProvider and CxfRsProvider.  This
option allows you to configure the maximum size of the cache.</p></td><td
colspan="1" rowspan="1"
class="confluenceTd"><p>maxClientCacheSize=5</p></td><td colspan="1"
rowspan="1"
class="confluenceTd"><p>No</p></td><td colspan="1" rowspan="1"
class="confluenceTd"><p>10</p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>setDefaultBus</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p>New in 2.9.0. <strong>deprecated</strong>
use defaultBus option from Camel 2.16 onwards. Will set the default bus when
CXF endpoint create a bus by itself</p></td><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>setDefaultBus=true</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p>No</p></td><td colspan="1" rowspan="1"
class="confluenceTd"><p><em>false</em></p></td></tr><tr><td colspan="1"
rowspan="1" class="confluenceTd"><code>defaultBus</code></td><td colspan="1"
rowspan="1" class="confluenceTd"><strong>Camel 2.16:</strong> <span>Will set
the default bus when CXF endpoint create a bus by itself</span></td><td
colspan="1" rowspan="1"
class="confluenceTd"><code>defaultBus=true</code></td><td colspan="1"
rowspan="1" c
lass="confluenceTd">No</td><td colspan="1" rowspan="1"
class="confluenceTd"><em>false</em></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>bus</code></p></td><td colspan="1" rowspan="1"
class="confluenceTd"><p>New in 2.9.0. A default bus created by CXF Bus Factory.
Use <code>#</code> notation to reference a bus object from the registry. The
referenced object must be an instance of
<code>org.apache.cxf.Bus</code>.</p></td><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>bus=#busName</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p>No</p></td><td colspan="1" rowspan="1"
class="confluenceTd"><p><em>None</em></p></td></tr><tr><td colspan="1"
rowspan="1" class="confluenceTd"><p><code>bindingStyle</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p><strong>As of 2.11</strong>.
Sets how requests and responses will be mapped to/from Camel. Two values are
possible:</p><ul class="alternate"><li><code>SimpleConsumer</code> =>
see the <a shape="rect"
href="#CXFRS-ConsumingaRESTRequest-SimpleBindingStyle">Consuming a REST Request
with the Simple Binding Style</a> below.</li><li><code>Default</code> => the
default style. For consumers this passes on a <code>MessageContentsList</code>
to the route, requiring low-level processing in the route.</li><li><span
style="font-family: monospace;">Custom</span> => allows you to specify a
custom binding through the <code>binding</code> option.</li></ul></td><td
colspan="1" rowspan="1"
class="confluenceTd"><p><code>bindingStyle=SimpleConsumer</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p>No</p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p><em>Default</em></p></td></tr><tr><td
colspan="1" rowspan="1"
class="confluenceTd"><p><code><span>binding</span></code></p></td><td
colspan="1" rowspan="1" class="confluenceTd">Allows you to specify a custom
<code>CxfRsBinding</code> implementation to perform low-level processing of the
raw CXF req
uest and response objects. The implementation must be bound in the Camel
registry, and you must use the hash (#) notation to refer to it.</td><td
colspan="1" rowspan="1"
class="confluenceTd"><code><span>binding=#myBinding</span></code></td><td
colspan="1" rowspan="1" class="confluenceTd">No</td><td colspan="1" rowspan="1"
class="confluenceTd"><code>DefaultCxfRsBinding</code></td></tr><tr><td
colspan="1" rowspan="1" class="confluenceTd"><p><code><span style="line-height:
1.4285715;">providers</span></code></p></td><td colspan="1" rowspan="1"
class="confluenceTd"><p><strong style="line-height: 1.4285715;">Since Camel
2.12.2</strong><span style="line-height: 1.4285715;"> set custom JAX-RS
providers list to the CxfRs endpoint.</span></p></td><td colspan="1"
rowspan="1"
class="confluenceTd"><p><code>providers=#MyProviders</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p>No</p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p><em style="line-height: 1.4285715;">No
ne</em></p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p><code><span style="line-height:
1.4285715;">schemaLocations</span></code></p></td><td colspan="1" rowspan="1"
class="confluenceTd"><p><strong style="line-height: 1.4285715;">Since Camel
2.12.2</strong><span style="line-height: 1.4285715;"> Sets the locations of the
schemas which can be used to validate the incoming XML or JAXB-driven
JSON.</span></p></td><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>schemaLocations=#MySchemaLocations</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p>No</p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p><em style="line-height:
1.4285715;">None</em></p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p><code><span style="line-height:
1.4285715;">features</span></code></p></td><td colspan="1" rowspan="1"
class="confluenceTd"><p><strong style="line-height: 1.4285715;">Since Camel
2.12.3</strong><span style="line-height: 1.428
5715;"> Set the feature list to the CxfRs endpoint.</span></p></td><td
colspan="1" rowspan="1"
class="confluenceTd"><p><code>features=#MyFeatures</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p>No</p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p><em style="line-height:
1.4285715;">None</em></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><strong style="line-height:
1.4285715;">Since Camel 2.12.4</strong><span style="line-height: 1.4285715;">
Set the properties to the CxfRs endpoint.</span></p></td><td colspan="1"
rowspan="1"
class="confluenceTd"><p><code>properties=#MyProperties</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p>No</p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p><em style="line-height:
1.4285715;">None</em></p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>inInterceptors</code></p>
</td><td colspan="1" rowspan="1" class="confluenceTd"><p><strong
style="line-height: 1.4285715;">Since Camel 2.12.4</strong><span
style="line-height: 1.4285715;"> Set the inInterceptors to the CxfRs
endpoint.</span></p></td><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>inInterceptors=#MyInterceptors</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p>No</p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p><em style="line-height:
1.4285715;">None</em></p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>outInterceptors</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p><strong style="line-height:
1.4285715;">Since Camel 2.12.4</strong><span style="line-height: 1.4285715;">
Set the outInterceptor to the CxfRs endpoint.</span></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p><code><span style="line-height:
1.4285715;">outInterceptors=#MyInterceptors</span></code></p></td><td
colspan="1" rowspan="1" class
="confluenceTd"><p><span style="line-height: 1.4285715;">No</span></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p><em style="line-height:
1.4285715;">None</em></p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p><code><span>inFaultInterceptors</span></code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p><strong style="line-height:
1.4285715;">Since Camel 2.12.4</strong><span style="line-height: 1.4285715;">
Set the inFaultInterceptors to the CxfRs endpoint.</span></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p><code><span style="line-height:
1.4285715;">inFaultInterceptors=#MyInterceptors</span></code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p><span style="line-height:
1.4285715;">No</span></p></td><td colspan="1" rowspan="1"
class="confluenceTd"><p><em style="line-height:
1.4285715;">None</em></p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>outFaultIntercetpros</code></p></td><td co
lspan="1" rowspan="1" class="confluenceTd"><p><strong style="line-height:
1.4285715;">Since Camel 2.12.4</strong><span style="line-height: 1.4285715;">
Set the outFaultInterceptors to the CxfRs endpoint.</span></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p><code><span style="line-height:
1.4285715;">outFaultInterceptors=#MyInterceptors</span></code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p><span style="line-height:
1.4285715;">No</span></p></td><td colspan="1" rowspan="1"
class="confluenceTd"><p><em style="line-height:
1.4285715;">None</em></p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>continuationTimeout</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p><span style="line-height:
1.4285715;"><strong>Since</strong> </span><strong style="line-height:
1.4285715;">Camel 2.14.0 </strong><span style="line-height:
1.4285715;">This option is used to set the CXF continuation timeout which could
be used i
n CxfConsumer by default when the CXF server is using Jetty or Servlet
transport. (Before </span><strong style="line-height: 1.4285715;">Camel
2.14.0</strong><span style="line-height: 1.4285715;">, CxfConsumer just set the
continuation timeout to be 0, which means the continuation suspend operation
never timeout.)</span></p></td><td colspan="1" rowspan="1"
class="confluenceTd"><p><code><span style="line-height:
1.4285715;">continuationTimeout=800000</span></code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p>No</p></td><td colspan="1" rowspan="1"
class="confluenceTd"><p><em style="line-height:
1.4285715;">30000</em></p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><code>ignoreDeleteMethodMessageBody</code></td><td
colspan="1" rowspan="1" class="confluenceTd"><strong>Since Camel
2.14.1</strong> This option is used to tell CxfRsProducer to ignore the message
body of the DELETE method when using HTTP API.</td><td colspan="1" rowspan="1"
class="conflu
enceTd"><code><span>ignoreDeleteMethodMessageBody=true</span></code></td><td
colspan="1" rowspan="1" class="confluenceTd">No</td><td colspan="1" rowspan="1"
class="confluenceTd"><em>false</em></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>modelRef</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p><strong>Since Camel 2.14.2</strong> This
option is used to specify the <a shape="rect"
href="http://cxf.apache.org/docs/jax-rs-advanced-features.html#JAX-RSAdvancedFeatures-RESTfulserviceswithoutannotations">model
file</a> which is useful for the resource class without
annotation.</p><p><strong>Since Camel 2.15</strong> This option can point to a
model file without specifying a service class for emulating document-only
endpoints</p></td><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>modelRef=</code><a shape="rect"
class="external-link"
href="http://classpath/org/apache/camel/component/cxf/jaxrs/CustomerServiceModel.xml"
rel="nofollow" sty
le="font-family: monospace;line-height:
1.4285715;">classpath:/CustomerServiceModel.xml</a></p></td><td colspan="1"
rowspan="1" class="confluenceTd">No</td><td colspan="1" rowspan="1"
class="confluenceTd"><em>None</em></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p class="p1"><code>performInvocation</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><strong>Since Camel 2.15</strong>
When the option is true, camel will perform the invocation of the resource
class instance and put the response object into the exchange for further
processing.</td><td colspan="1" rowspan="1" class="confluenceTd"><p
class="p1"><code>performInvocation= true</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd">No</td><td colspan="1" rowspan="1"
class="confluenceTd"><em>false</em></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><code>propagateContexts</code></td><td colspan="1"
rowspan="1" class="confluenceTd"><strong>Since Camel 2.15</strong> When the
option is true, JAXRS <a shape="rect" class="external-link"
href="https://jax-rs-spec.java.net/nonav/2.0-rev-a/apidocs/javax/ws/rs/core/UriInfo.html"
rel="nofollow">UriInfo</a>, <a shape="rect" class="external-link"
href="https://jax-rs-spec.java.net/nonav/2.0-rev-a/apidocs/javax/ws/rs/core/HttpHeaders.html"
rel="nofollow">HttpHeaders</a>, <a shape="rect" class="external-link"
href="https://jax-rs-spec.java.net/nonav/2.0-rev-a/apidocs/javax/ws/rs/core/Request.html"
rel="nofollow">Request</a> and <a shape="rect" class="external-link"
href="https://jax-rs-spec.java.net/nonav/2.0-rev-a/apidocs/javax/ws/rs/core/SecurityContext.html"
rel="nofollow">SecurityContext</a> contexts will be available to custom CXFRS
processors as typed Camel exchange properties. These contexts can be used to
analyze the current requests using JAX-RS API.</td><td colspan="1" rowspan="1"
class="confluenceTd"> </td><td colspan="1" rowspan="1"
class="confluenceTd"> </td><td colspan="1" rowspan="1" class
="confluenceTd"> </td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><code>loggingFeatureEnabled</code></td><td colspan="1"
rowspan="1" class="confluenceTd">This option enables CXF Logging Feature which
writes inbound and outbound REST messages to log.</td><td colspan="1"
rowspan="1" class="confluenceTd"> </td><td colspan="1" rowspan="1"
class="confluenceTd">No</td><td colspan="1" rowspan="1"
class="confluenceTd"><em>false</em></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><code>skipFaultLogging</code></td><td colspan="1"
rowspan="1" class="confluenceTd">This option controls whether the
<code>PhaseInterceptorChain</code> skips logging the Fault that it
catches.</td><td colspan="1" rowspan="1" class="confluenceTd"> </td><td
colspan="1" rowspan="1" class="confluenceTd">No</td><td colspan="1" rowspan="1"
class="confluenceTd"><em>false</em></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><code>loggingSizeLimit</code></td><td colspa
n="1" rowspan="1" class="confluenceTd">To limit the total size of number of
bytes the logger will output when logging feature has been enabled.</td><td
colspan="1" rowspan="1" class="confluenceTd"> </td><td colspan="1"
rowspan="1" class="confluenceTd">No</td><td colspan="1" rowspan="1"
class="confluenceTd"><code>0</code></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><code>cookieHandler</code></td><td colspan="1" rowspan="1"
class="confluenceTd">Since <strong>Camel 2.19.0</strong> Configure a cookie
handler to maintain a HTTP session</td><td colspan="1" rowspan="1"
class="confluenceTd"><code>cookieHandler=#exchangeCookieHandler</code></td><td
colspan="1" rowspan="1" class="confluenceTd">No</td><td colspan="1" rowspan="1"
class="confluenceTd"><em>None</em></td></tr></tbody></table></div><p>You can
also configure the CXF REST endpoint through the spring configuration. Since
there are lots of difference between the CXF REST client and CXF REST Server,
we provide dif
ferent configuration for them.<br clear="none"> Please check out the <a
shape="rect" class="external-link"
href="http://svn.apache.org/repos/asf/camel/trunk/components/camel-cxf/src/main/resources/schema/cxfEndpoint.xsd">schema
file</a> and <a shape="rect" class="external-link"
href="https://cwiki.apache.org/CXF20DOC/JAX-RS">CXF JAX-RS documentation</a>
for more information.</p><h3
id="CXFRS-HowtoconfiguretheRESTendpointinCamel">How to configure the REST
endpoint in Camel</h3><p>In <a shape="rect" class="external-link"
href="http://svn.apache.org/repos/asf/camel/trunk/components/camel-cxf/src/main/resources/schema/cxfEndpoint.xsd">camel-cxf
schema file</a>, there are two elements for the REST endpoint definition.
<strong>cxf:rsServer</strong> for REST consumer, <strong>cxf:rsClient</strong>
for REST producer.<br clear="none"> You can find a Camel REST service route
configuration example
here.<plain-text-body>{snippet:id=cxfRsExample|lang=xml|url=camel/trunk/components/camel-cxf/src/
test/resources/org/apache/camel/component/cxf/jaxrs/CxfRsSpringRouter.xml}</plain-text-body></p><h3
id="CXFRS-HowtooverridetheCXFproduceraddressfrommessageheader">How to override
the CXF producer address from message
header</h3><p>The <code>camel-cxfrs</code> producer supports to
override the services address by setting the message with the key of
"<span>CamelDestinationOverrideUrl".</span></p><plain-text-body> // set up the
service address from the message header to override the setting of CXF endpoint
exchange.getIn().setHeader(Exchange.DESTINATION_OVERRIDE_URL,
constant(getServiceAddress()));
-]]></script>
-</div></div><h3 id="CXFRS-ConsumingaRESTRequest-SimpleBindingStyle">Consuming
a REST Request - Simple Binding Style</h3><p><strong>Available as of Camel
2.11</strong></p><p>The <code>Default</code> binding style is rather low-level,
requiring the user to manually process the <code>MessageContentsList</code>
object coming into the route. Thus, it tightly couples the route logic with the
method signature and parameter indices of the JAX-RS operation. Somewhat
inelegant, difficult and error-prone.</p><p>In contrast, the
<code>SimpleConsumer</code> binding style performs the following mappings, in
order to <strong>make the request data more accessible</strong> to you within
the Camel Message:</p><ul><li>JAX-RS Parameters (@HeaderParam, @QueryParam,
etc.) are injected as IN message headers. The header name matches the value of
the annotation.</li><li>The request entity (POJO or other type) becomes the IN
message body. If a single entity cannot be identified in the JAX-RS method
signature
, it falls back to the original
<code>MessageContentsList</code>.</li><li>Binary <code>@Multipart</code> body
parts become IN message attachments, supporting <code>DataHandler</code>,
<code>InputStream</code>, <code>DataSource</code> and CXF's
<code>Attachment</code> class.</li><li>Non-binary <code>@Multipart</code> body
parts are mapped as IN message headers. The header name matches the Body Part
name.</li></ul><p>Additionally, the following rules apply to the
<strong>Response mapping</strong>:</p><ul><li>If the message body type is
different to <code>javax.ws.rs.core.Response</code> (user-built response), a
new <code>Response</code> is created and the message body is set as the entity
(so long it's not null). The response status code is taken from the
<code>Exchange.HTTP_RESPONSE_CODE</code> header, or defaults to 200 OK if not
present.</li><li>If the message body type is equal to
<code>javax.ws.rs.core.Response</code>, it means that the user has built a
custom response, and there
fore it is respected and it becomes the final response.</li><li>In all cases,
Camel headers permitted by custom or default <code>HeaderFilterStrategy</code>
are added to the HTTP response.</li></ul><h4
id="CXFRS-EnablingtheSimpleBindingStyle">Enabling the Simple Binding
Style</h4><p>This binding style can be activated by setting the
<code>bindingStyle</code> parameter in the consumer endpoint to value
<code>SimpleConsumer</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[
from("cxfrs:bean:rsServer?bindingStyle=SimpleConsumer")
- .to("log:TEST?showAll=true");
-]]></script>
-</div></div><h4
id="CXFRS-Examplesofrequestbindingwithdifferentmethodsignatures">Examples of
request binding with different method signatures</h4><p>Below is a list of
method signatures along with the expected result from the Simple
binding.</p><p><strong><code>public Response doAction(BusinessObject
request);</code></strong><br clear="none"> Request payload is placed in IN
message body, replacing the original
MessageContentsList.</p><p><strong><code>public Response
doAction(BusinessObject request, @HeaderParam("abcd") String abcd,
@QueryParam("defg") String defg);</code></strong><br clear="none"> Request
payload placed in IN message body, replacing the original MessageContentsList.
Both request params mapped as IN message headers with names abcd and
defg.</p><p><strong><code>public Response doAction(@HeaderParam("abcd") String
abcd, @QueryParam("defg") String defg);</code></strong><br clear="none"> Both
request params mapped as IN message headers with names abcd and defg. The origi
nal MessageContentsList is preserved, even though it only contains the 2
parameters.</p><p><strong><code>public Response
doAction(@Multipart(value="body1") BusinessObject request,
@Multipart(value="body2") BusinessObject request2);</code></strong><br
clear="none"> The first parameter is transferred as a header with name body1,
and the second one is mapped as header body2. The original MessageContentsList
is preserved as the IN message body.</p><p><strong><code>public Response
doAction(InputStream abcd);</code></strong><br clear="none"> The InputStream is
unwrapped from the MessageContentsList and preserved as the IN message
body.</p><p><strong><code>public Response doAction(DataHandler
abcd);</code></strong><br clear="none"> The DataHandler is unwrapped from the
MessageContentsList and preserved as the IN message body.</p><h4
id="CXFRS-MoreexamplesoftheSimpleBindingStyle">More examples of the Simple
Binding Style</h4><p>Given a JAX-RS resource class with this 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[ @POST @Path("/customers/{type}")
- public Response newCustomer(Customer customer,
@PathParam("type") String type, @QueryParam("active")
@DefaultValue("true") boolean active) {
+</plain-text-body><h3
id="CXFRS-ConsumingaRESTRequest-SimpleBindingStyle">Consuming a REST Request -
Simple Binding Style</h3><p><strong>Available as of Camel
2.11</strong></p><p>The <code>Default</code> binding style is rather low-level,
requiring the user to manually process the <code>MessageContentsList</code>
object coming into the route. Thus, it tightly couples the route logic with the
method signature and parameter indices of the JAX-RS operation. Somewhat
inelegant, difficult and error-prone.</p><p>In contrast, the
<code>SimpleConsumer</code> binding style performs the following mappings, in
order to <strong>make the request data more accessible</strong> to you within
the Camel Message:</p><ul><li>JAX-RS Parameters (@HeaderParam, @QueryParam,
etc.) are injected as IN message headers. The header name matches the value of
the annotation.</li><li>The request entity (POJO or other type) becomes the IN
message body. If a single entity cannot be identified in the JAX-RS method sig
nature, it falls back to the original
<code>MessageContentsList</code>.</li><li>Binary <code>@Multipart</code> body
parts become IN message attachments, supporting <code>DataHandler</code>,
<code>InputStream</code>, <code>DataSource</code> and CXF's
<code>Attachment</code> class.</li><li>Non-binary <code>@Multipart</code> body
parts are mapped as IN message headers. The header name matches the Body Part
name.</li></ul><p>Additionally, the following rules apply to the
<strong>Response mapping</strong>:</p><ul><li>If the message body type is
different to <code>javax.ws.rs.core.Response</code> (user-built response), a
new <code>Response</code> is created and the message body is set as the entity
(so long it's not null). The response status code is taken from the
<code>Exchange.HTTP_RESPONSE_CODE</code> header, or defaults to 200 OK if not
present.</li><li>If the message body type is equal to
<code>javax.ws.rs.core.Response</code>, it means that the user has built a
custom response, and
therefore it is respected and it becomes the final response.</li><li>In all
cases, Camel headers permitted by custom or default
<code>HeaderFilterStrategy</code> are added to the HTTP response.</li></ul><h4
id="CXFRS-EnablingtheSimpleBindingStyle">Enabling the Simple Binding
Style</h4><p>This binding style can be activated by setting the
<code>bindingStyle</code> parameter in the consumer endpoint to value
<code>SimpleConsumer</code>:</p><parameter
ac:name="language">java</parameter><plain-text-body>
from("cxfrs:bean:rsServer?bindingStyle=SimpleConsumer")
+ .to("log:TEST?showAll=true");
+</plain-text-body><h4
id="CXFRS-Examplesofrequestbindingwithdifferentmethodsignatures">Examples of
request binding with different method signatures</h4><p>Below is a list of
method signatures along with the expected result from the Simple
binding.</p><p><strong><code>public Response doAction(BusinessObject
request);</code></strong><br clear="none"> Request payload is placed in IN
message body, replacing the original
MessageContentsList.</p><p><strong><code>public Response
doAction(BusinessObject request, @HeaderParam("abcd") String abcd,
@QueryParam("defg") String defg);</code></strong><br clear="none"> Request
payload placed in IN message body, replacing the original MessageContentsList.
Both request params mapped as IN message headers with names abcd and
defg.</p><p><strong><code>public Response doAction(@HeaderParam("abcd") String
abcd, @QueryParam("defg") String defg);</code></strong><br clear="none"> Both
request params mapped as IN message headers with names abcd and defg. The
original MessageContentsList is preserved, even though it only contains the 2
parameters.</p><p><strong><code>public Response
doAction(@Multipart(value="body1") BusinessObject request,
@Multipart(value="body2") BusinessObject request2);</code></strong><br
clear="none"> The first parameter is transferred as a header with name body1,
and the second one is mapped as header body2. The original MessageContentsList
is preserved as the IN message body.</p><p><strong><code>public Response
doAction(InputStream abcd);</code></strong><br clear="none"> The InputStream is
unwrapped from the MessageContentsList and preserved as the IN message
body.</p><p><strong><code>public Response doAction(DataHandler
abcd);</code></strong><br clear="none"> The DataHandler is unwrapped from the
MessageContentsList and preserved as the IN message body.</p><h4
id="CXFRS-MoreexamplesoftheSimpleBindingStyle">More examples of the Simple
Binding Style</h4><p>Given a JAX-RS resource class with this method:</p><param
eter ac:name="language">java</parameter><plain-text-body> @POST
@Path("/customers/{type}")
+ public Response newCustomer(Customer customer, @PathParam("type") String
type, @QueryParam("active") @DefaultValue("true") boolean active) {
return null;
}
-]]></script>
-</div></div><p>Serviced by the following route:</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("cxfrs:bean:rsServer?bindingStyle=SimpleConsumer")
- .recipientList(simple("direct:${header.operationName}"));
+</plain-text-body><p>Serviced by the following route:</p><parameter
ac:name="language">java</parameter><plain-text-body>
from("cxfrs:bean:rsServer?bindingStyle=SimpleConsumer")
+ .recipientList(simple("direct:${header.operationName}"));
- from("direct:newCustomer")
- .log("Request: type=${header.type}, active=${header.active},
customerData=${body}");
-]]></script>
-</div></div><p>The following HTTP request with XML payload (given that the
Customer DTO is JAXB-annotated):</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[POST /customers/gold?active=true
+ from("direct:newCustomer")
+ .log("Request: type=${header.type}, active=${header.active},
customerData=${body}");
+</plain-text-body><p>The following HTTP request with XML payload (given that
the Customer DTO is JAXB-annotated):</p><parameter
ac:name="language">xml</parameter><plain-text-body>POST
/customers/gold?active=true
Payload:
<Customer>
@@ -190,135 +104,8 @@ Payload:
<country>Spain</country>
<project>Apache Camel</project>
</Customer>
-]]></script>
-</div></div><p>Will print the message:</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[Request: type=gold, active=true,
customerData=<Customer.toString() representation>
-]]></script>
-</div></div><p>For more examples on how to process requests and write
responses can be found <a shape="rect" class="external-link"
href="https://svn.apache.org/repos/asf/camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/jaxrs/simplebinding/">here</a>.</p><h3
id="CXFRS-ConsumingaRESTRequest-DefaultBindingStyle">Consuming a REST Request
- Default Binding Style</h3><p>The <a shape="rect" class="external-link"
href="https://cwiki.apache.org/CXF20DOC/JAX-RS">CXF JAXRS front end</a>
implements the <a shape="rect" class="external-link"
href="https://jsr311.java.net/" rel="nofollow">JAX-RS (JSR-311) API</a>, so we
can export the resources classes as a REST service. And we leverage the <a
shape="rect" class="external-link"
href="http://cwiki.apache.org/confluence/display/CXF20DOC/Invokers">CXF Invoker
API</a> to turn a REST request into a normal Java object method invocation.<br
clear="none"> Unlike the <a shape="rect" href="restlet.html">Camel
Restlet</a>
60;component, you don't need to specify the URI template within your endpoint,
CXF takes care of the REST request URI to resource class method mapping
according to the JSR-311 specification. All you need to do in Camel is delegate
this method request to a right processor or endpoint.</p><p>Here is an example
of a CXFRS route...</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[
-private static final String CXF_RS_ENDPOINT_URI =
- "cxfrs://http://localhost:" + CXT +
"/rest?resourceClasses=org.apache.camel.component.cxf.jaxrs.testbean.CustomerServiceResource";
-private static final String CXF_RS_ENDPOINT_URI2 =
- "cxfrs://http://localhost:" + CXT +
"/rest2?resourceClasses=org.apache.camel.component.cxf.jaxrs.testbean.CustomerService";
-private static final String CXF_RS_ENDPOINT_URI3 =
- "cxfrs://http://localhost:" + CXT + "/rest3?"
- +
"resourceClasses=org.apache.camel.component.cxf.jaxrs.testbean.CustomerServiceNoAnnotations&"
- +
"modelRef=classpath:/org/apache/camel/component/cxf/jaxrs/CustomerServiceModel.xml";
-private static final String CXF_RS_ENDPOINT_URI4 =
- "cxfrs://http://localhost:" + CXT + "/rest4?"
- +
"modelRef=classpath:/org/apache/camel/component/cxf/jaxrs/CustomerServiceDefaultHandlerModel.xml";
-private static final String CXF_RS_ENDPOINT_URI5 =
- "cxfrs://http://localhost:" + CXT + "/rest5?"
- + "propagateContexts=true&"
- +
"modelRef=classpath:/org/apache/camel/component/cxf/jaxrs/CustomerServiceDefaultHandlerModel.xml";
-protected RouteBuilder createRouteBuilder() throws Exception {
- final Processor testProcessor = new TestProcessor();
- final Processor testProcessor2 = new TestProcessor2();
- final Processor testProcessor3 = new TestProcessor3();
- return new RouteBuilder() {
- public void configure() {
- errorHandler(new NoErrorHandlerBuilder());
- from(CXF_RS_ENDPOINT_URI).process(testProcessor);
- from(CXF_RS_ENDPOINT_URI2).process(testProcessor);
- from(CXF_RS_ENDPOINT_URI3).process(testProcessor);
- from(CXF_RS_ENDPOINT_URI4).process(testProcessor2);
- from(CXF_RS_ENDPOINT_URI5).process(testProcessor3);
- }
- };
-}
-]]></script>
-</div></div>And the corresponding resource class used to configure the
endpoint...<div class="confluence-information-macro
confluence-information-macro-information"><p class="title">Note about resource
classes</p><span class="aui-icon aui-icon-small aui-iconfont-info
confluence-information-macro-icon"></span><div
class="confluence-information-macro-body"><p>By default, JAX-RS resource
classes are <strong>only </strong>used to configure JAX-RS properties. Methods
will <strong>not</strong> be executed during routing of messages to the
endpoint. Instead, it is the responsibility of the route to do all
processing.</p><p>Note that starting from Camel 2.15 it is also sufficient to
provide an interface only as opposed to a no-op service implementation class
for the default mode.</p><p>Starting from Camel 2.15, if a
<strong>performInvocation</strong> option is enabled, the service
implementation will be invoked first, the response will be set on the Camel
exchange and the route execution wi
ll continue as usual. This can be useful for</p><p>integrating the existing
JAX-RS implementations into Camel routes and for post-processing JAX-RS
Responses in custom processors.</p><p> </p></div></div><p></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[
-@Path("/customerservice/")
-public interface CustomerServiceResource {
-
- @GET
- @Path("/customers/{id}/")
- Customer getCustomer(@PathParam("id") String id);
-
- @PUT
- @Path("/customers/")
- Response updateCustomer(Customer customer);
-
- @Path("/{id}")
- @PUT()
- @Consumes({ "application/xml", "text/plain",
- "application/json" })
- @Produces({ "application/xml", "text/plain",
- "application/json" })
- Object invoke(@PathParam("id") String id,
- String payload);
-}
-]]></script>
-</div></div><h3
id="CXFRS-HowtoinvoketheRESTservicethroughcamel-cxfrsproducer">How to invoke
the REST service through camel-cxfrs producer</h3><p>The <a shape="rect"
class="external-link" href="https://cwiki.apache.org/CXF20DOC/JAX-RS">CXF JAXRS
front end</a> implements <a shape="rect" class="external-link"
href="https://cwiki.apache.org/CXF20DOC/JAX-RS+Client+API#JAX-RSClientAPI-Proxy-basedAPI">a
proxy-based client API</a>, with this API you can invoke the remote REST
service through a proxy. The <code>camel-cxfrs</code> producer is based on
this <a shape="rect" class="external-link"
href="https://cwiki.apache.org/CXF20DOC/JAX-RS+Client+API#JAX-RSClientAPI-Proxy-basedAPI">proxy
API</a>.<br clear="none"> You just need to specify the operation name in the
message header and prepare the parameter in the message body, the
<span>camel-cxfrs</span> producer will generate right REST request for
you.</p><p>Here is an example:</p><div class="code panel pdl" style="border-widt
h: 1px;"><div class="codeContent panelContent pdl">
-<script class="brush: java; gutter: false; theme: Default"
type="syntaxhighlighter"><![CDATA[
-Exchange exchange = template.send("direct://proxy", new Processor() {
- public void process(Exchange exchange) throws Exception {
- exchange.setPattern(ExchangePattern.InOut);
- Message inMessage = exchange.getIn();
- setupDestinationURL(inMessage);
- // set the operation name
- inMessage.setHeader(CxfConstants.OPERATION_NAME,
"getCustomer");
- // using the proxy client API
- inMessage.setHeader(CxfConstants.CAMEL_CXF_RS_USING_HTTP_API,
Boolean.FALSE);
- // set a customer header
- inMessage.setHeader("key", "value");
- // setup the accept content type
- inMessage.setHeader(Exchange.ACCEPT_CONTENT_TYPE,
"application/json");
- // set the parameters , if you just have one parameter
- // camel will put this object into an Object[] itself
- inMessage.setBody("123");
- }
-});
-
-// get the response message
-Customer response = (Customer) exchange.getOut().getBody();
-
-assertNotNull("The response should not be null ", response);
-assertEquals("Get a wrong customer id ",
String.valueOf(response.getId()), "123");
-assertEquals("Get a wrong customer name", response.getName(),
"John");
-assertEquals("Get a wrong response code", 200,
exchange.getOut().getHeader(Exchange.HTTP_RESPONSE_CODE));
-assertEquals("Get a wrong header value", "value",
exchange.getOut().getHeader("key"));
-]]></script>
-</div></div>The <a shape="rect" class="external-link"
href="https://cwiki.apache.org/CXF20DOC/JAX-RS">CXF JAXRS front end</a> also
provides <a shape="rect"
href="https://cwiki.apache.org/confluence/display/CXF20DOC/JAX-RS+Client+API#JAX-RSClientAPI-CXFWebClientAPI">a
http centric client API</a>. You can also invoke this API from
<code>camel-cxfrs</code> producer. You need to specify the <a shape="rect"
class="external-link"
href="http://camel.apache.org/maven/current/camel-core/apidocs/org/apache/camel/Exchange.html#HTTP_PATH">HTTP_PATH</a>
and the <a shape="rect" class="external-link"
href="http://camel.apache.org/maven/current/camel-core/apidocs/org/apache/camel/Exchange.html#HTTP_METHOD">HTTP_METHOD</a> and
let the producer use the http centric client API by using the URI option
<strong>httpClientAPI</strong> or by setting the message header <a shape="rect"
class="external-link"
href="http://camel.apache.org/maven/current/camel-cxf/apidocs/org/apache/came
l/component/cxf/CxfConstants.html#CAMEL_CXF_RS_USING_HTTP_API">CxfConstants.CAMEL_CXF_RS_USING_HTTP_API</a>.
You can turn the response object to the type class specified with the message
header <a shape="rect" class="external-link"
href="http://camel.apache.org/maven/current/camel-cxf/apidocs/org/apache/camel/component/cxf/CxfConstants.html#CAMEL_CXF_RS_RESPONSE_CLASS">CxfConstants.CAMEL_CXF_RS_RESPONSE_CLASS</a>.<div
class="code panel pdl" style="border-width: 1px;"><div class="codeContent
panelContent pdl">
-<script class="brush: java; gutter: false; theme: Default"
type="syntaxhighlighter"><![CDATA[
-Exchange exchange = template.send("direct://http", new Processor() {
- public void process(Exchange exchange) throws Exception {
- exchange.setPattern(ExchangePattern.InOut);
- Message inMessage = exchange.getIn();
- setupDestinationURL(inMessage);
- // using the http central client API
- inMessage.setHeader(CxfConstants.CAMEL_CXF_RS_USING_HTTP_API,
Boolean.TRUE);
- // set the Http method
- inMessage.setHeader(Exchange.HTTP_METHOD, "GET");
- // set the relative path
- inMessage.setHeader(Exchange.HTTP_PATH,
"/customerservice/customers/123");
- // Specify the response class , cxfrs will use InputStream as the
response object type
- inMessage.setHeader(CxfConstants.CAMEL_CXF_RS_RESPONSE_CLASS,
Customer.class);
- // set a customer header
- inMessage.setHeader("key", "value");
- // since we use the Get method, so we don't need to set the
message body
- inMessage.setBody(null);
- }
-});
-
-// get the response message
-Customer response = (Customer) exchange.getOut().getBody();
-
-assertNotNull("The response should not be null ", response);
-assertEquals("Get a wrong customer id ",
String.valueOf(response.getId()), "123");
-assertEquals("Get a wrong customer name", response.getName(),
"John");
-assertEquals("Get a wrong response code", 200,
exchange.getOut().getHeader(Exchange.HTTP_RESPONSE_CODE));
-assertEquals("Get a wrong header value", "value",
exchange.getOut().getHeader("key"));
-]]></script>
-</div></div>From Camel 2.1, we also support to specify the query parameters
from cxfrs URI for the CXFRS http centric client.<div class="error"><span
class="error">Error formatting macro: snippet:
java.lang.IndexOutOfBoundsException: Index: 20, Size: 20</span> </div>To
support the Dynamical routing, you can override the URI's query parameters by
using the CxfConstants.CAMEL_CXF_RS_QUERY_MAP header to set the parameter map
for it.<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[
-Map<String, String> queryMap = new LinkedHashMap<String,
String>();
-queryMap.put("q1", "new");
-queryMap.put("q2", "world");
-inMessage.setHeader(CxfConstants.CAMEL_CXF_RS_QUERY_MAP, queryMap);
-]]></script>
-</div></div></div>
+</plain-text-body><p>Will print the message:</p><parameter
ac:name="language">xml</parameter><plain-text-body>Request: type=gold,
active=true, customerData=<Customer.toString() representation>
+</plain-text-body><p>For more examples on how to process requests and write
responses can be found <a shape="rect" class="external-link"
href="https://svn.apache.org/repos/asf/camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/jaxrs/simplebinding/">here</a>.</p><h3
id="CXFRS-ConsumingaRESTRequest-DefaultBindingStyle">Consuming a REST Request
- Default Binding Style</h3><p>The <a shape="rect" class="external-link"
href="https://cwiki.apache.org/CXF20DOC/JAX-RS">CXF JAXRS front end</a>
implements the <a shape="rect" class="external-link"
href="https://jsr311.java.net/" rel="nofollow">JAX-RS (JSR-311) API</a>, so we
can export the resources classes as a REST service. And we leverage the <a
shape="rect" class="external-link"
href="http://cwiki.apache.org/confluence/display/CXF20DOC/Invokers">CXF Invoker
API</a> to turn a REST request into a normal Java object method invocation.<br
clear="none"> Unlike the <a shape="rect" href="restlet.html">Camel Restlet<
/a> component, you don't need to specify the URI template within your
endpoint, CXF takes care of the REST request URI to resource class method
mapping according to the JSR-311 specification. All you need to do in Camel is
delegate this method request to a right processor or endpoint.</p><p>Here is an
example of a CXFRS
route...<plain-text-body>{snippet:id=example|lang=java|url=camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/jaxrs/CxfRsConsumerTest.java}</plain-text-body>And
the corresponding resource class used to configure the
endpoint...</p><parameter ac:name="title">Note about resource
classes</parameter><rich-text-body><p>By default, JAX-RS resource classes are
<strong>only </strong>used to configure JAX-RS properties. Methods will
<strong>not</strong> be executed during routing of messages to the endpoint.
Instead, it is the responsibility of the route to do all processing.</p><p>Note
that starting from Camel 2.15 it is also sufficient to pro
vide an interface only as opposed to a no-op service implementation class for
the default mode.</p><p>Starting from Camel 2.15, if a
<strong>performInvocation</strong> option is enabled, the service
implementation will be invoked first, the response will be set on the Camel
exchange and the route execution will continue as usual. This can be useful
for</p><p>integrating the existing JAX-RS implementations into Camel routes and
for post-processing JAX-RS Responses in custom
processors.</p><p> </p></rich-text-body><p><plain-text-body>{snippet:id=example|lang=java|url=camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/jaxrs/testbean/CustomerServiceResource.java}</plain-text-body></p><h3
id="CXFRS-HowtoinvoketheRESTservicethroughcamel-cxfrsproducer">How to invoke
the REST service through camel-cxfrs producer</h3><p>The <a shape="rect"
class="external-link" href="https://cwiki.apache.org/CXF20DOC/JAX-RS">CXF JAXRS
front end</a> implements <a shape="re
ct" class="external-link"
href="https://cwiki.apache.org/CXF20DOC/JAX-RS+Client+API#JAX-RSClientAPI-Proxy-basedAPI">a
proxy-based client API</a>, with this API you can invoke the remote REST
service through a proxy. The <code>camel-cxfrs</code> producer is based on
this <a shape="rect" class="external-link"
href="https://cwiki.apache.org/CXF20DOC/JAX-RS+Client+API#JAX-RSClientAPI-Proxy-basedAPI">proxy
API</a>.<br clear="none"> You just need to specify the operation name in the
message header and prepare the parameter in the message body, the
<span>camel-cxfrs</span> producer will generate right REST request for
you.</p><p>Here is an
example:<plain-text-body>{snippet:id=ProxyExample|lang=java|url=camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/jaxrs/CxfRsProducerTest.java}</plain-text-body>The <a
shape="rect" class="external-link"
href="https://cwiki.apache.org/CXF20DOC/JAX-RS">CXF JAXRS front end</a> also
provides <a shape="rect" href="ht
tps://cwiki.apache.org/confluence/display/CXF20DOC/JAX-RS+Client+API#JAX-RSClientAPI-CXFWebClientAPI">a
http centric client API</a>. You can also invoke this API from
<code>camel-cxfrs</code> producer. You need to specify the <a shape="rect"
class="external-link"
href="http://camel.apache.org/maven/current/camel-core/apidocs/org/apache/camel/Exchange.html#HTTP_PATH">HTTP_PATH</a>
and the <a shape="rect" class="external-link"
href="http://camel.apache.org/maven/current/camel-core/apidocs/org/apache/camel/Exchange.html#HTTP_METHOD">HTTP_METHOD</a> and
let the producer use the http centric client API by using the URI option
<strong>httpClientAPI</strong> or by setting the message header <a shape="rect"
class="external-link"
href="http://camel.apache.org/maven/current/camel-cxf/apidocs/org/apache/camel/component/cxf/CxfConstants.html#CAMEL_CXF_RS_USING_HTTP_API">CxfConstants.CAMEL_CXF_RS_USING_HTTP_API</a>.
You can turn the response object to the type class specified
with the message header <a shape="rect" class="external-link"
href="http://camel.apache.org/maven/current/camel-cxf/apidocs/org/apache/camel/component/cxf/CxfConstants.html#CAMEL_CXF_RS_RESPONSE_CLASS">CxfConstants.CAMEL_CXF_RS_RESPONSE_CLASS</a>.<plain-text-body>{snippet:id=HttpExample|lang=java|url=camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/jaxrs/CxfRsProducerTest.java}</plain-text-body>From
Camel 2.1, we also support to specify the query parameters from cxfrs URI for
the CXFRS http centric
client.<plain-text-body>{snippet:id=QueryExample|lang=java|url=camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/jaxrs/CxfRsProducerTest.java}</plain-text-body>To
support the Dynamical routing, you can override the URI's query parameters by
using the CxfConstants.CAMEL_CXF_RS_QUERY_MAP header to set the parameter map
for
it.<plain-text-body>{snippet:id=QueryMapExample|lang=java|url=camel/trunk/components/camel-cxf/src/test/jav
a/org/apache/camel/component/cxf/jaxrs/CxfRsProducerTest.java}</plain-text-body></p></div>
</td>
<td valign="top">
<div class="navigation">