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.
Request payload is placed in IN message body, replacing the originalMessageContentsList
. public Response doAction(BusinessObject request, @HeaderParam("abcd") String abcd, @QueryParam("defg") String defg);
Request payload placed in IN message body, replacing the originalMessageContentsList
. 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 originalMessageContentsList
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 originalMessageContentsList
handed over from CXF. public Response doAction(InputStream abcd);
The InputStream is unwrapped from theMessageContentsList
and preserved as the IN message body. public Response doAction(DataHandler abcd);
The DataHandler is unwrapped from theMessageContentsList
and preserved as the IN message body.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static class
SimpleCxfRsBinding.MethodSpec
-
Constructor Summary
Constructors Constructor Description SimpleCxfRsBinding()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description 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 exchangevoid
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, bindCamelMessageToRequestEntity, bindCamelMessageToRequestEntity, bindResponseHeadersToCamelHeaders, bindResponseToCamelBody, copyOperationResourceInfoStack, copyProtocolHeader, getHeaderFilterStrategy, setCharsetWithContentType, setHeaderFilterStrategy
-
-
-
-
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 interfaceCxfRsBinding
- Overrides:
populateExchangeFromCxfRsRequest
in classDefaultCxfRsBinding
- Parameters:
cxfExchange
- cxf exchange objectcamelExchange
- camel exchange objectmethod
- the method which is need for the camel componentparamArray
- 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 interfaceCxfRsBinding
- Overrides:
populateCxfRsResponseFromExchange
in classDefaultCxfRsBinding
- Parameters:
camelExchange
- camel exchange objectcxfExchange
- 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-RSResponse
object, which gives the user a better control on the response behaviour. If the message body is already an instance ofResponse
, 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. TheDefaultCxfRsBinding
doesn't filter the response headers according to theHeaderFilterStrategy
, 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
-
-
-