Language and Page Formatting Options
Chapter 39. Filtering SOAP Message Headers
The Camel CXF component supports a flexible header filtering mechanism, which enables you to process SOAP headers, applying different filters according to the header's XML namespace.
39.1. Basic Configuration
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
CxfHeaderFilterStrategyclass. Basic configuration of the
CxfHeaderFilterStrategyclass involves setting one or more of the following options:
The semantics of the
relayHeadersoption can be summarized as follows:
|In-band headers||Out-of-band headers|
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:
- (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.
- In this mode, both in-band and out-of-band headers are available for filtering.
- Not 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 the section called “SoapMessageHeaderFilter”.
Overriding the default filter
You can override the default
CxfHeaderFilterStrategyinstance by defining a new
CxfHeaderFilterStrategybean and associating it with a CXF endpoint.
Sample relayHeaders configuration
The following example shows how you can use the
relayHeadersoption to create a
CxfHeaderFilterStrategybean that blocks all message headers. The CXF endpoints in the route use the
headerFilterStrategyoption to install the filter strategy in the endpoint, where the
headerFilterStrategysetting has the syntax,
<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>
relayAllMessageHeadersoption 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
Sample relayAllMessageHeaders configuration
The following example shows how to configure CXF endpoints to propagate all SOAP message headers. The
propagateAllMessagesfilter strategy sets both
<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>