CXF Bean — allows other Apache CXF endpoints to send exchanges and invoke Web service bean objects
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 |
---|---|
|
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 |
---|---|
If |
Table 4, “CXF Bean options” lists the options for a CXF Bean endpoint. None of these options are required.
Table 4. CXF Bean options
Name | Descriptione | Default |
---|---|---|
bus
|
CXF bus reference specified by the The referenced object must be an instance of
For example: | Default bus created by CXF Bus Factory |
cxfBeanBinding
|
CXF bean binding specified by the For example: |
DefaultCxfBeanBinding
|
headerFilterStrategy
|
Header filter strategy specified by the For example:
|
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:
|
null
|
setDefaultBus
| Sets the default bus when the CXF endpoint creates a bus by itself. |
false
|
Table 5, “CXF Bean headers” lists the headers used by a CXF Bean endpoint.
Table 5. CXF Bean headers
Name | Type | Description |
---|---|---|
CamelHttpCharacterEncoding
|
String
|
Character encoding; for example:
Applies to In message headers only. (Prior to v2.0-m2, was named
|
CamelContentType
|
String
|
Content type; for example: Defaults to Applies to In message headers only. (Prior to v2.0-m2, was named
|
CamelHttpBaseUri |
String
|
The value of this header is set in the CXF message as the
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
|
CamelHttpPath
|
String
|
Request URI's path; for example:
This is a required option. Applies to In message headers only. (Prior to v2.0-m2, was named
|
CamelHttpMethod
|
String
|
RESTful request verb; for example: This is a required option. Applies to In message headers only. (Prior 2.0-m2, was named
|
CamelHttpResponseCode
|
Integer
|
HTTP response code; for example: Applies to Out message headers only. |
![]() | Note |
---|---|
Currently, CXF Bean component has (only) been tested with Jetty HTTP component it can understand headers from Jetty HTTP component without requiring conversion. |
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));