Name

CXF Bean — allows other Apache CXF endpoints to send exchanges and invoke Web service bean objects

Overview

The CXF Bean component allows other Apache Camel endpoints to send exchanges and invoke Web service bean objects. Currently it supports only JAXRS and JAXWS (new in Apache Camel 2.1) annotated service bean.

[Note]Note

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

URI format

The URI format for a CXF Bean endpoint is:

cxfbean:serviceBeanRef[?options]

Where serviceBeanRef is a registry key for looking up the service bean object.

[Note]Note

If serviceBeanRef references a List object, the elements of the List are the service bean objects accepted by the endpoint.

Options

Table 4, “CXF Bean options” lists the options for a CXF Bean endpoint. None of these options are required.

Table 4. CXF Bean options

NameDescriptioneDefault
bus

CXF bus reference specified by the \# notation.

The referenced object must be an instance of org.apache.cxf.Bus.

For example: bus=#busName

Default bus created by CXF Bus Factory
cxfBeanBinding

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

For example: cxfBinding=#bindingName

DefaultCxfBeanBinding
headerFilterStrategy

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

For example: headerFilterStrategy=#strategyName

CxfHeaderFilterStrategy
populateFromClass 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. true
providers

Since 2.5, setting the providers for the CXFRS endpoint.

For example: providers=#providerRef1,#providerRef2

null
setDefaultBus Sets the default bus when the CXF endpoint creates a bus by itself. false

Headers

Table 5, “CXF Bean headers” lists the headers used by a CXF Bean endpoint.

Table 5. CXF Bean headers

NameTypeDescription
CamelHttpCharacterEncoding String

Character encoding; for example: ISO-8859-1

Applies to In message headers only.

(Prior to v2.0-m2, was named CamelCxfBeanCharacterEncoding).

CamelContentType String

Content type; for example: text/xml

Defaults to \**/*\*

Applies to In message headers only.

(Prior to v2.0-m2, was named CamelCxfBeanContentType)

CamelHttpBaseUri

String

The value of this header is set in the CXF message as the Message.BASE_PATH property; for example: http://localhost:9000.

It is a required option and used by CXF JAX-RS processing. Basically, it is the scheme, host, and port portion of the request URI.

Defaults to the endpoint URI of the source endpoint in the Camel exchange.

Applies to In message headers only.

(Prior to v2.0-m3, was named CamelCxfBeanRequestBasePath)

CamelHttpPath String

Request URI's path; for example: consumer/123

This is a required option.

Applies to In message headers only.

(Prior to v2.0-m2, was named CamelCxfBeanRequestPath{})

CamelHttpMethod String

RESTful request verb; for example: GET, PUT, POST, DELETE

This is a required option.

Applies to In message headers only.

(Prior 2.0-m2, was named CamelCxfBeanVerb)

CamelHttpResponseCode Integer

HTTP response code; for example: 200

Applies to Out message headers only.


[Note]Note

Currently, CXF Bean component has (only) been tested with Jetty HTTP component it can understand headers from Jetty HTTP component without requiring conversion.

A Working Sample

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.

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 RESTful request URI will not match the endpoint's URI http://localhost:9000 exactly.

<route>
	<from uri="jetty:http://localhost:9000?matchOnUriPrefix=true" />
	<to uri="cxfbean:customerServiceBean" />
	<to uri="mock:endpointA" />
</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.jaxrs.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));

Related topics

Bean
Apache CXF
Apache CXF Documentation