Class SimpleCxfRsBinding

java.lang.Object
org.apache.camel.component.cxf.jaxrs.DefaultCxfRsBinding
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:

  • JAX-RS Parameter types (@QueryParam, @HeaderParam, @CookieParam, @FormParam, @PathParam, @MatrixParam) are all transferred as IN message headers.
  • If a request entity is clearly identified (for example, because it's the only parameter without an annotation), it's set as the IN message body. Otherwise, the original MessageContentsList is preserved as the message body.
  • If Multipart is in use, binary parts are mapped as Camel IN message attachments, while any others are mapped as IN message headers for convenience. These classes are considered binary: Attachment, DataHandler, DataSource, InputStream. Additionally, the original MessageContentsList is preserved as the message body.
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.

  • Constructor Details

    • SimpleCxfRsBinding

      public SimpleCxfRsBinding()
  • Method Details

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

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