title: Soap envelope namespace prefix in Java web service
body: <p>I am trying to change prefix for soap envelope in response of web-service from
  S="http://schemas.xmlsoap.org/soap/envelope/"
  to 
  soap="http://schemas.xmlsoap.org/soap/envelope/":</p>
  
  <p>so here's how the response looks like now:</p>
  
  <pre><code>&lt;S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/"&gt;
     &lt;S:Body&gt;
        &lt;n:soaprequestResponse xmlns:n="http://tempuri.org/soaprequest"&gt;
           &lt;n:soaprequestResult/&gt;
        &lt;/n:soaprequestResponse&gt;
     &lt;/S:Body&gt;
  &lt;/S:Envelope&gt;
  </code></pre>
  
  <p>and here's how it must look like:</p>
  
  <pre><code>&lt;soap:Envelope xmlns:soap:="http://schemas.xmlsoap.org/soap/envelope/"&gt;
     &lt;soap:Body&gt;
        &lt;n:soaprequestResponse xmlns:n="http://tempuri.org/soaprequest"&gt;
           &lt;n:soaprequestResult/&gt;
        &lt;/n:soaprequestResponse&gt;
     &lt;/soap:Body&gt;
  &lt;/soap:Envelope&gt;
  </code></pre>
  
  <p>How can this be attained?</p>
  
  <p>EDIT:</p>
  
  <p>I added soap handler class and the problem starts when I'm trying to get envelope:</p>
  
  <pre><code>package org.tempuri.soaprequest;
  
  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 SoapHandler implements SOAPHandler&lt;SOAPMessageContext&gt; {
  
      @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(); //just trying to get envelope
              } catch (SOAPException ex) {
                  ex.printStackTrace();
              }
  
          return true; //indicates to the context to proceed with (normal)message processing
      }
  
      @Override
      public boolean handleFault(SOAPMessageContext context) {
            //do nothing
         return true;
      }
  
      @Override
      public void close(MessageContext context) {
            //do nothing
  
      }
  }
  </code></pre>
  
  <p>SoapUI throws:</p>
  
  <pre><code>&lt;S:Fault xmlns:ns4="http://www.w3.org/2003/05/soap-envelope"&gt;
      &lt;faultcode&gt;S:Server&lt;/faultcode&gt;
          &lt;faultstring&gt;JVMVRFY012 stack shapeinconsistent;class=com/sun/xml/messaging/saaj/soap/SOAPDocumentImpl, method=createDocumentFragment()Lorg/w3c/dom/DocumentFragment;, pc=5
      &lt;/faultstring&gt;
  &lt;/S:Fault&gt;
  </code></pre>
  
  <p>Tomcat log has no errors.</p>
  
  <p>It doesn't occur without custom soap handler.</p>
  
  <p>Perhaps the reason is in the way I implemented web method. It creates a new thread with an object that processes request and then returns empty response, thus releasing client from waiting for request processing is over:</p>
  
  <pre><code>@WebResult(name="soaprequestResult", targetNamespace="http://tempuri.org/soaprequest")
  public SoaprequestResponse.SoaprequestResult soaprequest(@WebParam(name="streams", targetNamespace="http://tempuri.org/soaprequest") SoaprequestStreams streams) {
      try {
          new Thread(new MyProcess(streams)).start();
          return new SoaprequestResponse().getSoaprequestResult();
      } catch(Exception e) {
          StringWriter sw = new StringWriter();
          PrintWriter pw = new PrintWriter(sw);
          e.printStackTrace(pw);
          String stackTrace = sw.toString();
          return new SoaprequestResponse().getSoaprequestResult();
      }
  }
  </code></pre>
  
  <p>and MyProcess is class where request processing really is and stmt.executeUpdate is executed.</p>