Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The recommended/standard way to achieve what you're trying to achieve is with a <a href="http://jax-ws.java.net/articles/handlers_introduction.html" rel="nofollow">SOAPMessage Handler</a>. They're analogous to java web application filters (which in theory could also work here) as they are used to implement the <a href="http://www.javaworld.com/javaworld/jw-08-2004/jw-0816-chain.html" rel="nofollow">Chain of Responsibility pattern</a>. For example, in your case, you can have this :</p> <pre><code>import java.util.Set; import java.util.logging.Level; import java.util.logging.Logger; import javax.xml.namespace.QName; import javax.xml.soap.SOAPBody; import javax.xml.soap.SOAPEnvelope; import javax.xml.soap.SOAPException; import javax.xml.ws.handler.MessageContext; import javax.xml.ws.handler.soap.SOAPHandler; import javax.xml.ws.handler.soap.SOAPMessageContext; public class SOAPBodyHandler implements SOAPHandler&lt;SOAPMessageContext&gt; { static final String DESIRED_NS_PREFIX = "customns"; static final String DESIRED_NS_URI = "http://test/"; static final String UNWANTED_NS_PREFIX = "ns"; @Override public Set&lt;QName&gt; getHeaders() { //do nothing return null; } @Override public boolean handleMessage(SOAPMessageContext context) { if ((boolean) context.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY)) { //Check here that the message being intercepted is an outbound message from your service, otherwise ignore. try { SOAPEnvelope msg = context.getMessage().getSOAPPart().getEnvelope(); //get the SOAP Message envelope SOAPBody body = msg.getBody(); body.removeNamespaceDeclaration(UNWANTED_NS_PREFIX); body.addNamespaceDeclaration(DESIRED_NS_PREFIX, DESIRED_NS_URI); } catch (SOAPException ex) { Logger.getLogger(SOAPBodyHandler.class.getName()).log(Level.SEVERE, null, ex); } } return true; //indicates to the context to proceed with (normal)message processing } @Override public boolean handleFault(SOAPMessageContext context) { //do nothing return null; } @Override public void close(MessageContext context) { //do nothing } </code></pre> <p>}</p> <p>On your Service Implementation Bean class declaration, add</p> <pre><code> @HandlerChain(file = "handler-chain.xml") </code></pre> <p>The annotation above is a reference to the configuration file that actually allows your handler to kick-in. The config file will look something like this</p> <pre><code> &lt;?xml version="1.0" encoding="UTF-8" standalone="yes"?&gt; &lt;javaee:handler-chains xmlns:javaee="http://java.sun.com/xml/ns/javaee" xmlns:xsd="http://www.w3.org/2001/XMLSchema"&gt; &lt;javaee:handler-chain&gt; &lt;javaee:handler&gt; &lt;javaee:handler-class&gt;your.handler.FQN.here&lt;/javaee:handler-class&gt; &lt;/javaee:handler&gt; &lt;/javaee:handler-chain&gt; &lt;/javaee:handler-chains&gt; </code></pre> <p>Try this at home. This specific code has NOT been tested</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. This table or related slice is empty.
    1. VO
      singulars
      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