Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Maven users will need to add the following dependency to their pom.xml for this component:

Code Block
xml
xml

<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>

URI format

Code Block
languagejava

cxfrs://address?options

Where address represents the CXF endpoint's address

Code Block
languagejava

cxfrs:bean:rsEndpoint

Where rsEndpoint represents the spring bean's name which presents the CXFRS client or server

For either style above, you can append options to the URI as follows:

Code Block
languagejava

cxfrs:bean:cxfEndpoint?resourceClasses=org.apache.camel.rs.Example

Options

Wiki Markup
{div:class=confluenceTableSmall}
|| Name || Description || Example || Required? || default value ||
| {{resourceClasses}} | The resource classes which you want to export as REST service. Multiple classes can be separated by comma. | {{resourceClasses=org.apache.camel.rs.Example1,}}
{{org.apache.camel.rs.Exchange2}} | No | _None_ |
| {{resourceClass}} | *Deprecated*: Use {{resourceClasses}} The resource class which you want to export as REST service. | {{resourceClass =org.apache.camel.rs.Example1}} | No | _None_ |
| {{httpClientAPI}} | *new to Camel 2.1* If it is true, the CxfRsProducer will use the HttpClientAPI to invoke the service \\
If it is false, the CxfRsProducer will use the ProxyClientAPI to invoke the service | httpClientAPI=true | No | _true_ |
| synchronous | New in 2.5, this option will let CxfRsConsumer 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. | synchronous=true | No | false |
| throwExceptionOnFailure | 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. | throwExceptionOnFailure=true | No | true |
| {{maxClientCacheSize}} | 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.&nbsp; The implementation caches CXF clients or ClientFactoryBean in CxfProvider and CxfRsProvider.&nbsp; This option allows you to configure the maximum size of the cache. \\ | maxClientCacheSize=5 | No \\ | 10 |
| {{setDefaultBus}} | New in 2.9.0. Will set the default bus when CXF endpoint create a bus by itself | {{setDefaultBus=true}} | No | {{false}} |
| {{bus}} | New in 2.9.0. A default bus created by CXF Bus Factory. Use {{\#}} notation to reference a bus object from the registry. The referenced object must be an instance of {{org.apache.cxf.Bus}}. | {{bus=#busName}} | No | _None_ |
| {{bindingStyle}} | *As of 2.11*. Sets how requests and responses will be mapped to/from Camel. Two values are possible: 
- {{SimpleConsumer}} => see the [Consuming a REST Request with the Simple Binding Style|#Consuming a REST Request - Simple Binding Style] below.
- {{Default}} => the default style. For consumers this passes on a {{MessageContentsList}} to the route, requiring low-level processing in the route. | {{bindingStyle=SimpleConsumer}} | No | _Default_ |
| {{providers}}| *Since Camel 2.12.2* Add custom JAX-RS providers to the list of providers. | No | _None_ |
| {{schemaLocations}} | *Since Camel 2.12.2* Sets the locations of the schemas which can be used to validate the incoming XML or JAXB-driven JSON. | NO | _None_ |
{div}

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.
Please check out the schema file and CXF REST user guide for more information.

...

This binding style can be activated by setting the bindingStyle parameter in the consumer endpoint to value SimpleConsumer:

Code Block
languagejava

  from("cxfrs:bean:rsServer?bindingStyle=SimpleConsumer")
    .to("log:TEST?showAll=true");

...

Given a JAX-RS resource class with this method:

Code Block
languagejava

    @POST @Path("/customers/{type}")
    public Response newCustomer(Customer customer, @PathParam("type") String type, @QueryParam("active") @DefaultValue("true") boolean active) {
        return null;
    }

Serviced by the following route:

Code Block
languagejava

    from("cxfrs:bean:rsServer?bindingStyle=SimpleConsumer")
        .recipientList(simple("direct:${header.operationName}"));

    from("direct:newCustomer")
        .log("Request: type=${header.type}, active=${header.active}, customerData=${body}");

The following HTTP request with XML payload (given that the Customer DTO is JAXB-annotated):

Code Block
languagexml

POST /customers/gold?active=true

Payload:
<Customer>
  <fullName>Raul Kripalani</fullName>
  <country>Spain</country>
  <project>Apache Camel</project>
</Customer>

Will print the message:

Code Block
languagexml

Request: type=gold, active=true, customerData=<Customer.toString() representation>

...

From Camel 2.1, we also support to specify the query parameters from cxfrs URI for the CXFRS http centric client.

Wiki Markup
{snippet:id=QueryExample|lang=java|url=camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/jaxrs/CxfRsProducerTest.java}

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.

...