Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

CXF's LoggingOutInterceptor outputs outbound message that goes on the wire to logging system (Java Util Logging). Since the LoggingOutInterceptor is in PRE_STREAM phase (but PRE_STREAM phase is removed in MESSAGE mode), you have to configure LoggingOutInterceptor to be run during the WRITE phase. The following is an example.

Wiki Markup
{snippet:id=enableLoggingOutInterceptor|lang=xml|url=camel/trunk/components/camel-cxf/src/test/resources/org/apache/camel/component/cxf/LoggingInterceptorInMessageModeTest-context.xml}

Description of relayHeaders option

...

  • POJO and PAYLOAD modes are supported. In POJO mode, only out-of-band message headers are available for filtering as the in-band headers have been processed and removed from header list by CXF. The in-band headers are incorporated into the MessageContentList in POJO mode. The camel-cxf component does make any attempt to remove the in-band headers from the MessageContentList. If filtering of in-band headers is required, please use PAYLOAD mode or plug in a (pretty straightforward) CXF interceptor/JAXWS Handler to the CXF endpoint.
  • The Message Header Relay mechanism has been merged into CxfHeaderFilterStrategy. The relayHeaders option, its semantics, and default value remain the same, but it is a property of CxfHeaderFilterStrategy.
    Here is an example of configuring it.

    Wiki Markup
    {snippet:id=dropAllMessageHeadersStrategy|lang=xml|url=camel/trunk/components/camel-cxf/src/test/resources/org/apache/camel/component/cxf/soap/headers/CxfMessageHeadersRelayTest-context.xml}
    Then, your endpoint can reference the CxfHeaderFilterStrategy.
    Wiki Markup
    {snippet:id=noRelayRoute|lang=xml|url=camel/trunk/components/camel-cxf/src/test/resources/org/apache/camel/component/cxf/soap/headers/CxfMessageHeadersRelayTest-context.xml}

  • The MessageHeadersRelay interface has changed slightly and has been renamed to MessageHeaderFilter. It is a property of CxfHeaderFilterStrategy. Here is an example of configuring user defined Message Header Filters:

    Wiki Markup
    {snippet:id=customMessageFilterStrategy|lang=xml|url=camel/trunk/components/camel-cxf/src/test/resources/org/apache/camel/component/cxf/soap/headers/CxfMessageHeadersRelayTest-context.xml}

  • Other than relayHeaders, there are new properties that can be configured in CxfHeaderFilterStrategy.

    Name

    Required

    Description

    relayHeaders

    No

    All message headers will be processed by Message Header Filters

    Type: boolean
    Default: true

    relayAllMessageHeaders

    No

    All message headers will be propagated (without processing by Message Header Filters)

    Type: boolean
    Default: false

    allowFilterNamespaceClash

    No

    If two filters overlap in activation namespace, the property control how it should be handled. If the value is true, last one wins. If the value is false, it will throw an exception

    Type: boolean
    Default: false

    Configure the CXF endpoints with Spring

    You can configure the CXF endpoint with the Spring configuration file shown below, and you can also embed the endpoint into the camelContext tags. When you are invoking the service endpoint, you can set the operationName and operationNamespace headers to explicitly state which operation you are calling.

    Code Block
    xml
    xml
    <beans xmlns="http://www.springframework.org/schema/beans"
            xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
            xmlns:cxf="http://camel.apache.org/schema/cxf"
            xsi:schemaLocation="
            http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
            http://camel.apache.org/schema/cxf http://camel.apache.org/schema/cxf/camel-cxf.xsd
            http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd">
         <cxf:cxfEndpoint id="routerEndpoint" address="http://localhost:9003/CamelContext/RouterPort"
         		serviceClass="org.apache.hello_world_soap_http.GreeterImpl"/>
         <cxf:cxfEndpoint id="serviceEndpoint" address="http://localhost:9000/SoapContext/SoapPort"
         		wsdlURL="testutils/hello_world.wsdl"
         		serviceClass="org.apache.hello_world_soap_http.Greeter"
         		endpointName="s:SoapPort"
         		serviceName="s:SOAPService"
         	xmlns:s="http://apache.org/hello_world_soap_http" />
         <camelContext id="camel" xmlns="http://camel.apache.org/schema/spring">
           <route>
             <from uri="cxf:bean:routerEndpoint" />
             <to uri="cxf:bean:serviceEndpoint" />
           </route>
        </camelContext>
      </beans>
    

    Be sure to include the JAX-WS schemaLocation attribute specified on the root beans element. This allows CXF to validate the file and is required. Also note the namespace declarations at the end of the <cxf:cxfEndpoint/> tag--these are required because the combined {namespace}localName syntax is presently not supported for this tag's attribute values.

    The cxf:cxfEndpoint element supports many additional attributes:

    Name

    Value

    PortName

    The endpoint name this service is implementing, it maps to the wsdl:port@name. In the format of ns:PORT_NAME where ns is a namespace prefix valid at this scope.

    serviceName

    The service name this service is implementing, it maps to the wsdl:service@name. In the format of ns:SERVICE_NAME where ns is a namespace prefix valid at this scope.

    wsdlURL

    The location of the WSDL. Can be on the classpath, file system, or be hosted remotely.

    bindingId

    The bindingId for the service model to use.

    address

    The service publish address.

    bus

    The bus name that will be used in the JAX-WS endpoint.

    serviceClass

    The class name of the SEI (Service Endpoint Interface) class which could have JSR181 annotation or not.

    It also supports many child elements:

    Name

    Value

    cxf:inInterceptors

    The incoming interceptors for this endpoint. A list of <bean> or <ref>.

    cxf:inFaultInterceptors

    The incoming fault interceptors for this endpoint. A list of <bean> or <ref>.

    cxf:outInterceptors

    The outgoing interceptors for this endpoint. A list of <bean> or <ref>.

    cxf:outFaultInterceptors

    The outgoing fault interceptors for this endpoint. A list of <bean> or <ref>.

    cxf:properties

    A properties map which should be supplied to the JAX-WS endpoint. See below.

    cxf:handlers

    A JAX-WS handler list which should be supplied to the JAX-WS endpoint. See below.

    cxf:dataBinding

    You can specify the which DataBinding will be use in the endpoint. This can be supplied using the Spring <bean class="MyDataBinding"/> syntax.

    cxf:binding

    You can specify the BindingFactory for this endpoint to use. This can be supplied using the Spring <bean class="MyBindingFactory"/> syntax.

    cxf:features

    The features that hold the interceptors for this endpoint. A list of {{<bean>}}s or {{<ref>}}s

    cxf:schemaLocations

    The schema locations for endpoint to use. A list of {{<schemaLocation>}}s

    cxf:serviceFactory

    The service factory for this endpoint to use. This can be supplied using the Spring <bean class="MyServiceFactory"/> syntax

    Div
     

...

To resolved this issue, you just need to tell StaxOutInterceptor to write the XML start document for you.

Wiki Markup
{snippet:id=example|lang=xml|url=camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/WriteXmlDeclarationInterceptor.java}
You can add a customer interceptor like this and configure it into you camel-cxf endpont
Wiki Markup
{snippet:id=example|lang=xml|url=camel/trunk/components/camel-cxf/src/test/resources/org/apache/camel/component/cxf/GreeterEndpointsRouterContext.xml}
Or adding a message header for it like this if you are using Camel 2.4.

...

The camel-cxf endpoint consumer POJO data format is based on the cxf invoker, so the message header has a property with the name of CxfConstants.OPERATION_NAME and the message body is a list of the SEI method parameters.

Wiki Markup
{snippet:id=personProcessor|lang=java|url=camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/wsdl_first/PersonProcessor.java}

How to prepare the message for the camel-cxf endpoint in POJO data format

...

If you want to get the object array from the message body, you can get the body using message.getbody(Object[].class), as follows:

Wiki Markup
{snippet:id=sending|lang=java|url=camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/CxfProducerRouterTest.java}

How to deal with the message for a camel-cxf endpoint in PAYLOAD data format

PAYLOAD means that you process the payload message from the SOAP envelope. You can use the Header.HEADER_LIST as the key to set or get the SOAP headers and use the List<Element> to set or get SOAP body elements.
Message.getBody() will return an org.apache.camel.component.cxf.CxfPayload object, which has getters for SOAP message headers and Body elements. This change enables decoupling the native CXF message from the Camel message.

Wiki Markup
{snippet:id=payload|lang=java|url=camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/CxfConsumerPayloadTest.java}

How to get and set SOAP headers in POJO mode

...

The following example illustrate how to get/set SOAP headers. Suppose we have a route that forwards from one Camel-cxf endpoint to another. That is, SOAP Client -> Camel -> CXF service. We can attach two processors to obtain/insert SOAP headers at (1) before request goes out to the CXF service and (2) before response comes back to the SOAP Client. Processor (1) and (2) in this example are InsertRequestOutHeaderProcessor and InsertResponseOutHeaderProcessor. Our route looks like this:

Wiki Markup
{snippet:id=processSoapHeaderRoute|lang=xml|url=camel/trunk/components/camel-cxf/src/test/resources/org/apache/camel/component/cxf/soap/headers/CxfMessageHeadersRelayTest-context.xml}
SOAP headers are propagated to and from Camel Message headers. The Camel message header name is "org.apache.cxf.headers.Header.list" which is a constant defined in CXF (org.apache.cxf.headers.Header.HEADER_LIST). The header value is a List of CXF SoapHeader objects (org.apache.cxf.binding.soap.SoapHeader). The following snippet is the InsertResponseOutHeaderProcessor (that insert a new SOAP header in the response message). The way to access SOAP headers in both InsertResponseOutHeaderProcessor and InsertRequestOutHeaderProcessor are actually the same. The only difference between the two processors is setting the direction of the inserted SOAP header.
Wiki Markup
{snippet:id=InsertResponseOutHeaderProcessor|lang=java|url=camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/soap/headers/CxfMessageHeadersRelayTest.java}

How to get and set SOAP headers in PAYLOAD mode

...

Once you obtain a CxfPayload object, you can invoke the CxfPayload.getHeaders() method that returns a List of DOM Elements (SOAP headers).

Wiki Markup
{snippet:id=payload|lang=java|url=camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/CxfPayLoadSoapHeaderTest.java}
Since Camel 2.16.0, you can also use the same way as described in sub-chapter "How to get and set SOAP headers in POJO mode" to set or get the SOAP headers. 

SOAP headers are not available in MESSAGE mode

...

If you are using a camel-cxf endpoint to consume the SOAP request, you may need to throw the SOAP Fault from the camel context.
Basically, you can use the throwFault DSL to do that; it works for POJO, PAYLOAD and MESSAGE data format.
You can define the soap fault like this

Wiki Markup
{snippet:id=FaultDefine|lang=java|url=camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/CxfCustomizedExceptionTest.java}
Then throw it as you like
Wiki Markup
{snippet:id=ThrowFault|lang=java|url=camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/CxfCustomizedExceptionTest.java}
If your CXF endpoint is working in the MESSAGE data format, you could set the the SOAP Fault message in the message body and set the response code in the message header.
Wiki Markup
{snippet:id=MessageStreamFault|lang=java|url=camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/CxfMessageStreamExceptionTest.java}
Same for using POJO data format. You can set the SOAPFault on the out body and also indicate it's a fault by calling Message.setFault(true):
Wiki Markup
{snippet:id=onException|lang=java|url=camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/CxfMessageStreamExceptionTest.java}

How to propagate a camel-cxf endpoint's request and response context

...

To enable MTOM, set the CXF endpoint property "mtom-enabled" to true. (I believe you can only do it with Spring.)

Wiki Markup
{snippet:id=enableMtom|lang=xml|url=camel/trunk/components/camel-cxf/src/test/resources/org/apache/camel/component/cxf/mtom/CxfMtomRouterPayloadModeTest-context.xml}
You can produce a Camel message with attachment to send to a CXF endpoint in Payload mode.
Wiki Markup
{snippet:id=producer|lang=java|url=camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/mtom/CxfMtomProducerPayloadModeTest.java}
You can also consume a Camel message received from a CXF endpoint in Payload mode.
Wiki Markup
{snippet:id=consumer|lang=java|url=camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/mtom/CxfMtomConsumerPayloadModeTest.java}
Message Mode: Attachments are not supported as it does not process the message at all.

...