org.apache.camel.component.cxf.jaxrs
Class SimpleCxfRsBinding

java.lang.Object
  extended by org.apache.camel.component.cxf.jaxrs.DefaultCxfRsBinding
      extended by org.apache.camel.component.cxf.jaxrs.SimpleCxfRsBinding
All Implemented Interfaces:
CxfRsBinding, org.apache.camel.spi.HeaderFilterStrategyAware

public class SimpleCxfRsBinding
extends DefaultCxfRsBinding

A CXF RS Binding which maps method parameters as Camel IN headers and the payload as the IN message body. It replaces the default behaviour of creating a MessageContentsList, which requires the route to process the contents low-level.

The mapping from CXF to Camel is performed as follows:

For example, the following JAX-RS method signatures are supported, with the specified outcomes:

public Response doAction(BusinessObject request);
Request payload is placed in IN message body, replacing the original MessageContentsList.

public Response doAction(BusinessObject request, @HeaderParam("abcd") String abcd, @QueryParam("defg") String defg);
Request payload placed in IN message body, replacing the original MessageContentsList. Both request params mapped as IN message headers with names abcd and defg.

public Response doAction(@HeaderParam("abcd") String abcd, @QueryParam("defg") String defg);
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.

public Response doAction(@Multipart(value="body1", type="application/json") BusinessObject request, @Multipart(value="image", type="image/jpeg") DataHandler image);
The first parameter is transferred as a POJO in a header named body1, while the second parameter gets injected as an attachment with name image. The MIME type is observed by the CXF stack. The IN message body is the original MessageContentsList handed over from CXF.

public Response doAction(InputStream abcd);
The InputStream is unwrapped from the MessageContentsList and preserved as the IN message body.

public Response doAction(DataHandler abcd);
The DataHandler is unwrapped from the MessageContentsList and preserved as the IN message body.


Nested Class Summary
protected static class SimpleCxfRsBinding.MethodSpec
           
 
Field Summary
 
Fields inherited from class org.apache.camel.component.cxf.jaxrs.DefaultCxfRsBinding
camelToCxfHeaderMap, cxfToCamelHeaderMap
 
Constructor Summary
SimpleCxfRsBinding()
           
 
Method Summary
protected  void bindBody(org.apache.camel.Message in, Object[] paramArray, int singleBodyIndex)
          Binds the message body.
protected  void bindHeadersFromSubresourceLocators(org.apache.cxf.message.Exchange cxfExchange, org.apache.camel.Exchange camelExchange)
          Transfers path parameters from the full path (including ancestor subresource locators) into Camel IN Message Headers.
protected  void bindParameters(org.apache.camel.Message in, Object[] paramArray, String[] paramNames, int numberParameters)
          Binds JAX-RS parameter types (@HeaderParam, @QueryParam, @MatrixParam, etc.) to the exchange.
protected  Object buildResponse(org.apache.camel.Exchange camelExchange, Object base)
          Builds the response for the client.
protected  Map<String,String> filterCamelHeadersForResponseHeaders(Map<String,Object> headers, org.apache.camel.Exchange camelExchange)
          Filters the response headers that will be sent back to the client.
 Object populateCxfRsResponseFromExchange(org.apache.camel.Exchange camelExchange, org.apache.cxf.message.Exchange cxfExchange)
          Populate the CxfRsResponse object from the camel exchange
 void populateExchangeFromCxfRsRequest(org.apache.cxf.message.Exchange cxfExchange, org.apache.camel.Exchange camelExchange, Method method, Object[] paramArray)
          Populate the camel exchange from the CxfRsRequest, the exchange will be consumed by the processor which the CxfRsConsumer attached.
 
Methods inherited from class org.apache.camel.component.cxf.jaxrs.DefaultCxfRsBinding
bindCamelHeadersToRequestHeaders, bindCamelMessageBodyToRequestBody, bindResponseHeadersToCamelHeaders, bindResponseToCamelBody, copyMessageHeader, copyOperationResourceInfoStack, copyProtocolHeader, getCamelToCxfHeaderMap, getCxfToCamelHeaderMap, getHeaderFilterStrategy, setCamelToCxfHeaderMap, setCxfToCamelHeaderMap, setHeaderFilterStrategy
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SimpleCxfRsBinding

public SimpleCxfRsBinding()
Method Detail

populateExchangeFromCxfRsRequest

public void populateExchangeFromCxfRsRequest(org.apache.cxf.message.Exchange cxfExchange,
                                             org.apache.camel.Exchange camelExchange,
                                             Method method,
                                             Object[] paramArray)
Description copied from interface: CxfRsBinding
Populate the camel exchange from the CxfRsRequest, the exchange will be consumed by the processor which the CxfRsConsumer attached.

Specified by:
populateExchangeFromCxfRsRequest in interface CxfRsBinding
Overrides:
populateExchangeFromCxfRsRequest in class DefaultCxfRsBinding
Parameters:
cxfExchange - cxf exchange object
camelExchange - camel exchange object
method - the method which is need for the camel component
paramArray - the parameter list for the method invocation

populateCxfRsResponseFromExchange

public Object populateCxfRsResponseFromExchange(org.apache.camel.Exchange camelExchange,
                                                org.apache.cxf.message.Exchange cxfExchange)
                                         throws Exception
Description copied from interface: CxfRsBinding
Populate the CxfRsResponse object from the camel exchange

Specified by:
populateCxfRsResponseFromExchange in interface CxfRsBinding
Overrides:
populateCxfRsResponseFromExchange in class DefaultCxfRsBinding
Parameters:
camelExchange - camel exchange object
cxfExchange - cxf exchange object
Returns:
the response object
Throws:
Exception - can be thrown if error in the binding process

buildResponse

protected Object buildResponse(org.apache.camel.Exchange camelExchange,
                               Object base)
Builds the response for the client.

Always returns a JAX-RS Response object, which gives the user a better control on the response behaviour. If the message body is already an instance of Response, we reuse it and just inject the relevant HTTP headers.

Parameters:
camelExchange -
base -
Returns:

filterCamelHeadersForResponseHeaders

protected Map<String,String> filterCamelHeadersForResponseHeaders(Map<String,Object> headers,
                                                                  org.apache.camel.Exchange camelExchange)
Filters the response headers that will be sent back to the client.

The DefaultCxfRsBinding doesn't filter the response headers according to the HeaderFilterStrategy, so we handle this task in this binding.

Parameters:
headers -
camelExchange -
Returns:

bindHeadersFromSubresourceLocators

protected void bindHeadersFromSubresourceLocators(org.apache.cxf.message.Exchange cxfExchange,
                                                  org.apache.camel.Exchange camelExchange)
Transfers path parameters from the full path (including ancestor subresource locators) into Camel IN Message Headers.


bindParameters

protected void bindParameters(org.apache.camel.Message in,
                              Object[] paramArray,
                              String[] paramNames,
                              int numberParameters)
Binds JAX-RS parameter types (@HeaderParam, @QueryParam, @MatrixParam, etc.) to the exchange.

Parameters:
in -
paramArray -
paramNames -
numberParameters -

bindBody

protected void bindBody(org.apache.camel.Message in,
                        Object[] paramArray,
                        int singleBodyIndex)
Binds the message body.

Parameters:
in -
paramArray -
singleBodyIndex -


Apache Camel