Skip to main content
Summary How to add an XML header/preamble to the SOAP payload in Artix JAX-WS/CXF?
Article Number 13049
Environment All Supported Operating Systems Artix JAX-WS Runtime Artix 5.x
Question/Problem Description How to add an XML header/preamble to the SOAP payload in Artix JAX-WS/CXF?
How do I force an Artix request to include the standard <?xml version="1.0" encoding="..."?> preamble?
Clarifying Information
Error Message
Defect/Enhancement Number
Cause
Resolution A SOAP request sent from an Artix JAX-WS/CXF client application typically looks like:

<soap:Envelope
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"><soap:Header
/><soap:Body><pingMe xmlns="http://apache.org/hello_world_soap_http/types"
/></soap:Body></soap:Envelope>

However, in certain situations it can be desirable to include the standard XML preamble to the header as follows:

<?xml version="1.0" encoding="..."?>
<soap:Envelope
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"><soap:Header
/><soap:Body><pingMe xmlns="http://apache.org/hello_world_soap_http/types"
/></soap:Body></soap:Envelope>

There are two ways to accomplish this:

1) PROGRAMMATICALLY

Add the following code to the proxy object making the invocation:

import javax.xml.ws.BindingProvider;

...

SOAPService ss = new SOAPService(wsdlURL, SERVICE_NAME);
Greeter port = ss.getSoapPort();
((BindingProvider)port).getRequestContext().put("org.apache.cxf.stax.force-start-document", Boolean.TRUE);

2) VIA CONFIGURATION

In order to accomplish the same via configuration, all you need to do is add this to your client configuration scope:

<jaxws:client name="{YOUR_NAMESPACE}YOUR_PORTNAME" createdFromAPI="true">
  <jaxws:properties>
    ...
    <entry key="org.apache.cxf.stax.force-start-document">
      <bean class="java.lang.Boolean">
        <constructor-arg value="true"/>
      </bean>
    </entry>
  </jaxws:properties>
</jaxws:client>

 

Workaround
Notes
Attachment
Created date: 06 September 2011
Last Modified: 13 February 2013
Last Published: 23 June 2012
First Published date: 09 September 2011

#Orbix
#KnowledgeDocs