Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Found a solution <a href="http://mail-archives.apache.org/mod_mbox/cxf-users/201202.mbox/%3C4F44C735.3040109@gmail.com%3E" rel="nofollow">here</a>, but that doesn't seem to work.</p> <p>Came up with this solution which works for me: create an interceptor which checks for the MessageID header and adds it to the message if it doesn't exist:</p> <pre><code>package my.package; import org.apache.cxf.binding.soap.SoapHeader; import org.apache.cxf.headers.Header; import org.apache.cxf.message.Message; import org.apache.cxf.phase.AbstractPhaseInterceptor; import org.apache.cxf.phase.Phase; import org.w3c.dom.Element; import javax.xml.namespace.QName; import java.util.ArrayList; import java.util.List; import java.util.UUID; public class HeaderInterceptor extends AbstractPhaseInterceptor&lt;Message&gt; { private static final String SOAP_HEADER_KEY = "org.apache.cxf.headers.Header.list"; private static final String NAMESPACE_URI = "http://www.w3.org/2005/08/addressing"; private static final String QUALIFIED_NAME = "wsa:MessageID"; private static final String LOCAL_NAME = "MessageID"; public HeaderInterceptor() { // phases: http://cxf.apache.org/docs/interceptors.html // 'pre protocol' seems to be the best moment to check the header, if we do it earlier the headers don't exist in the message object so we can't re-use the 'owner document' // if we do it later the unmarshalMAPs method (in MAPCodec.java) will already have processed the headers and will not process our added header super(Phase.PRE_PROTOCOL); } @Override public void handleMessage(Message message) throws Fault { ArrayList&lt;SoapHeader&gt; headers = (ArrayList&lt;SoapHeader&gt;) message.get(SOAP_HEADER_KEY); // if the header doesn't exist and we have at least one header to access 'owner document' we can create and add our own MessageID header if(!messageIdHeaderExists(headers) &amp;&amp; headers.size() &gt; 0) { Element existingHeaderElement = (Element) headers.get(0).getObject(); // use the existing header element to create our own MessageID header with random UUID Element element = existingHeaderElement.getOwnerDocument().createElementNS(NAMESPACE_URI, QUALIFIED_NAME); element.appendChild(existingHeaderElement.getOwnerDocument().createTextNode("uuid:" + UUID.randomUUID().toString())); QName qname = new QName(NAMESPACE_URI, LOCAL_NAME); SoapHeader header = new SoapHeader(qname, element); // by default a SoapHeader is created with 'direction out' header.setDirection(Header.Direction.DIRECTION_IN); headers.add(header); } } /** * Checks if the MessageID header exists in the list of headers. * * @param headers list of headers * @return true if the MessageID header exists, false if not */ private Boolean messageIdHeaderExists(ArrayList&lt;SoapHeader&gt; headers) { for(SoapHeader header:headers) { if(header.getName().getLocalPart().equalsIgnoreCase(LOCAL_NAME)) { return true; } } return false; } } </code></pre> <p>Define the interceptor in your Spring context:</p> <pre><code>&lt;bean id="headerInterceptor" class="my.package.HeaderInterceptor" /&gt; &lt;jaxws:endpoint implementor="#service" address="/ws"&gt; &lt;jaxws:inInterceptors&gt; &lt;ref bean="headerInterceptor" /&gt; &lt;/jaxws:inInterceptors&gt; &lt;/jaxws:endpoint&gt; </code></pre> <p>Tested with CXF version 2.6.1. More info on interceptors: <a href="http://cxf.apache.org/docs/interceptors.html" rel="nofollow">http://cxf.apache.org/docs/interceptors.html</a></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload