Camel Component: CXF Bean - 6.3

Talend ESB Mediation Developer Guide

EnrichVersion
6.3
EnrichProdName
Talend Data Fabric
Talend Data Services Platform
Talend ESB
Talend MDM Platform
Talend Open Studio for ESB
Talend Real-Time Big Data Platform
task
Design and Development
EnrichPlatform
Talend ESB

The cxfbean: component allows other Camel endpoints to send exchange and invoke Web service bean objects. Currently, it only supports JAX-RS and JAX-WS (new to Camel 2.1) annotated service beans.

Note : CxfBeanEndpoint is a ProcessorEndpoint so it has no consumers. It works similarly to a Bean component.

Maven users need to add the following dependency to their pom.xml to use the CXF Bean Component:

<dependency>
    <groupId>org.apache.camel</groupId>
    <artifactId>camel-cxf</artifactId>
    <!-- use the same version as your Camel core version: -->
    <version>x.x.x</version>
</dependency>

URI format

cxfbean:serviceBeanRef

where serviceBeanRef is a registry key to look up the service bean object. If serviceBeanRef references a List object, elements of the List are the service bean objects accepted by the endpoint.

Options

Name

Required

Description

bus

No

CXF bus reference specified by the # notation. The referenced object must be an instance of org.apache.cxf.Bus.

Default: Default bus created by CXF Bus Factory

Example: bus=#busName

cxfBeanBinding

No

CXF bean binding specified by the # notation. The referenced object must be an instance of org.apache.camel.component.cxf.cxfbean. CxfBeanBinding.

Default: DefaultCxfBeanBinding

Example: cxfBinding=#bindingName

headerFilterStrategy

No

Header filter strategy specified by the # notation. The referenced object must be an instance of org.apache.camel.spi.HeaderFilterStrategy.

Default: CxfHeaderFilterStrategy

Example: headerFilterStrategy=#strategyName

populateFromClass

No

Since 2.3, the wsdlLocation annotated in the POJO is ignored (by default) unless this option is set to false. Prior to 2.3, the wsdlLocation annotated in the POJO is always honored and it is not possible to ignore.

Default: true

Example: true,false

providers

No

Since 2.5, setting the providers for the CXFRS endpoint.

Default: null

Example: providers=#providerRef1,#providerRef2

setDefaultBus

No

This will set the default bus when CXF endpoint create a bus by itself.

Default: false

Example: true,false

Headers

Warning

Currently, the CXF Bean component has (only) been tested with Jetty component -- it understands headers from Jetty component without requiring conversion.

Name

Required

Description

CamelHttp-CharacterEncoding

None

Character encoding

Type:String

In/Out:In

Default: None

Example: ISO-8859-1

CamelContentType

No

Content type

Type: String

Type: String

Default: */*

Example: text/xml

CamelHttpBaseUri

Yes

The value of this header will be set in the CXF message as the Message.BASE_PATH property. It is needed by CXF JAX-RS processing. Basically, it is the scheme, host and port portion of the request URI.

Type: String

In/Out:In

Default: The Endpoint URI of the source endpoint in the Camel exchange

Example: http://localhost:9000

CamelHttpPath

Yes

Request URI's path

Type: String

In/Out: In

Default: None

Example: consumer/123

CamelHttpMethod

Yes

RESTful request verb

Type: String

In/Out:In

Default: None

Example: GET,PUT,POST,DELETE

CamelHttpResponseCode

No

HTTP response code

Type: Integer

In/Out:Out

Default: None

Example: 200

A Working Sample

This sample shows how to create a route that starts an embedded Jetty HTTP server. The route sends requests to a CXF Bean and invokes a JAX-RS annotated service.

First, create a route as follows: The from endpoint is a Jetty HTTP endpoint that is listening on port 9000. Notice that the matchOnUriPrefix option must be set to true because the RESTful request URI will not exactly match the endpoint's URI http://localhost:9000.

<route>
   <from uri="jetty:http://localhost:9000?matchOnUriPrefix=true" />
   <to uri="cxfbean:customerServiceBean" />
</route>

The to endpoint is a CXF Bean with bean name customerServiceBean . 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.

<util:list id="customerServiceBean">
   <bean class="org.apache.camel.component.cxf.testbean.CustomerService"/>
</util:list>

<bean class="org.apache.camel.wsdl_first.PersonImpl" id="jaxwsBean" />

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.

url = new URL(
   "http://localhost:9000/customerservice/orders/223/products/323");
in = url.openStream();
assertEquals("{\"Product\":{\"description\":\"product 323\",\"id\":323}}", 
   CxfUtils.getStringFromInputStream(in));