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
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:
Request payload is placed in IN message body, replacing the original
Request payload placed in IN message body, replacing the original
Both request params mapped as IN message headers with names abcd and defg. The original
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
The InputStream is unwrapped from the
The DataHandler is unwrapped from the
- 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
MessageContentsListis 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
MessageContentsListis preserved as the message body.
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
Nested Classes -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected voidBinds the message body.protected voidbindHeadersFromSubresourceLocators(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 voidbindParameters(org.apache.camel.Message in, Object[] paramArray, String[] paramNames, int numberParameters) Binds JAX-RS parameter types (@HeaderParam, @QueryParam, @MatrixParam, etc.) to the exchange.protected ObjectbuildResponse(org.apache.camel.Exchange camelExchange, Object base) Builds the response for the client.filterCamelHeadersForResponseHeaders(Map<String, Object> headers, org.apache.camel.Exchange camelExchange) Filters the response headers that will be sent back to the client.populateCxfRsResponseFromExchange(org.apache.camel.Exchange camelExchange, org.apache.cxf.message.Exchange cxfExchange) Populate the CxfRsResponse object from the camel exchangevoidpopulateExchangeFromCxfRsRequest(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
-
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:CxfRsBindingPopulate the camel exchange from the CxfRsRequest, the exchange will be consumed by the processor which the CxfRsConsumer attached.- Specified by:
populateExchangeFromCxfRsRequestin interfaceCxfRsBinding- Overrides:
populateExchangeFromCxfRsRequestin 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:CxfRsBindingPopulate the CxfRsResponse object from the camel exchange- Specified by:
populateCxfRsResponseFromExchangein interfaceCxfRsBinding- Overrides:
populateCxfRsResponseFromExchangein 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
Builds the response for the client. Always returns a JAX-RSResponseobject, 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. TheDefaultCxfRsBindingdoesn'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
Binds the message body.- Parameters:
in-paramArray-singleBodyIndex-
-