When more than one CXF endpoint appears in a route, you need to decide whether or not to allow headers to propagate between the endpoints. By default, the headers are relayed back and forth between the endpoints, but in many cases it might be necessary to filter the headers or to block them altogether. You can control header propagation by applying filters to producer endpoints.
Header filtering is controlled by the CxfHeaderFilterStrategy class. Basic
configuration of the CxfHeaderFilterStrategy class involves setting one or more
of the following options:
The semantics of the relayHeaders option can be summarized as
follows:
| In-band headers | Out-of-band headers | |
relayHeaders=true, dataFormat=PAYLOAD | Filter | Filter |
relayHeaders=true, dataFormat=POJO | Relay all | Filter |
relayHeaders=false | Block | Block |
An in-band header is a header that is explicitly defined as part of the WSDL binding contract for an endpoint.
An out-of-band header is a header that is serialized over the wire, but is not explicitly part of the WSDL binding contract. In particular, the SOAP binding permits out-of-band headers, because the SOAP specification does not require headers to be defined in the WSDL contract.
The CXF endpoint's payload format affects the filter behavior as follows:
POJO(Default) Only out-of-band headers are available for filtering, because the in-band headers have already been processed and removed from the list by CXF. The in-band headers are incorporated into the
MessageContentListin POJO mode. If you require access to headers in POJO mode, you have the option of implementing a custom CXF interceptor or JAX-WS handler.PAYLOADIn this mode, both in-band and out-of-band headers are available for filtering.
MESSAGENot applicable. (In this mode, the message remains in a raw format and the headers are not processed at all.)
The default filter is of type, SoapMessageHeaderFilter, which removes only
the SOAP headers that the SOAP specification expects an intermediate Web service to consume.
For more details, see SoapMessageHeaderFilter.
You can override the default CxfHeaderFilterStrategy instance by defining a
new CxfHeaderFilterStrategy bean and associating it with a CXF endpoint.
The following example shows how you can use the relayHeaders option to
create a CxfHeaderFilterStrategy bean that blocks all message headers. The CXF
endpoints in the route use the headerFilterStrategy option to install the
filter strategy in the endpoint, where the headerFilterStrategy setting has the
syntax, headerFilterStrategy=#.BeanID
<beans ...> ... <bean id="dropAllMessageHeadersStrategy" class="org.apache.camel.component.cxf.common.header.CxfHeaderFilterStrategy"> <!-- Set relayHeaders to false to drop all SOAP headers --> <property name="relayHeaders" value="false"/> </bean> <camelContext id="camel" xmlns="http://camel.apache.org/schema/spring"> <route> <from uri="cxf:bean:routerNoRelayEndpoint?headerFilterStrategy=#dropAllMessageHeadersStrategy"/> <to uri="cxf:bean:serviceNoRelayEndpoint?headerFilterStrategy=#dropAllMessageHeadersStrategy"/> </route> </camelContext> ... </beans>
The relayAllMessageHeaders option is used to propagate
all SOAP headers, without applying any filtering (any installed
filters would be bypassed). In order to enable this feature, you must set
both
relayHeaders and relayAllMessageHeaders to
true.
The following example shows how to configure CXF endpoints to propagate
all SOAP message headers. The propagateAllMessages
filter strategy sets both relayHeaders and relayAllMessageHeaders
to true.
<beans ...> ... <bean id="propagateAllMessages" class="org.apache.camel.component.cxf.common.header.CxfHeaderFilterStrategy"> <!-- Set both properties to true to propagate *all* SOAP headers --> <property name="relayHeaders" value="true"/> <property name="relayAllMessageHeaders" value="true"/> </bean> <camelContext id="camel" xmlns="http://camel.apache.org/schema/spring"> <route> <from uri="cxf:bean:routerNoRelayEndpoint?headerFilterStrategy=#propagateAllMessages"/> <to uri="cxf:bean:serviceNoRelayEndpoint?headerFilterStrategy=#propagateAllMessages"/> </route> </camelContext> ... </beans>








