title: How can I add namespace declarations in a SOAPEnvelope
body: <p>In my soap application, I'm using apache cxf.</p>
  
  <p>Here's my code which will submit data to the server.</p>
  
  <pre><code>import org.apache.cxf.Bus;
  import org.apache.cxf.BusFactory;
  import org.apache.cxf.bus.spring.SpringBusFactory;
  import org.apache.cxf.endpoint.Client;
  import org.apache.cxf.frontend.ClientProxy;
  import org.apache.cxf.interceptor.LoggingInInterceptor;
  import org.apache.cxf.interceptor.LoggingOutInterceptor;
  import org.apache.cxf.ws.security.wss4j.DefaultCryptoCoverageChecker;
  import org.apache.cxf.ws.security.wss4j.WSS4JInInterceptor;
  import org.apache.cxf.ws.security.wss4j.WSS4JOutInterceptor;
  
  SpringBusFactory bf = new SpringBusFactory();
  URL              busFile = Submission.class.getResource(WSSEC_XML);    
  File             f = new File(busFile.getPath());
  
  Bus              bus = bf.createBus(busFile.toString());
  BusFactory.setDefaultBus(bus);
  BusFactory.setThreadDefaultBus(bus);
  
  DefaultCryptoCoverageChecker coverageChecker = new DefaultCryptoCoverageChecker();
  
  coverageChecker.setSignBody(true);
  coverageChecker.setSignTimestamp(true);
  coverageChecker.setEncryptBody(true);
  coverageChecker.setSignAddressingHeaders(true);
  
  MyClaimservice  service = new MyClaimservice();
  Myclaims        port = service.getMyClaimsSoap11();
  BindingProvider provider = (BindingProvider) port;
  provider.getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, ENDPOINT_ADDRESS);
  provider.getRequestContext().put(BindingProvider.SOAPACTION_URI_PROPERTY, SOAP_ACTION);
  
  Client client = ClientProxy.getClient(port);
  
  client.getOutInterceptors().add(new LoggingOutInterceptor());
  client.getInInterceptors().add(new LoggingInInterceptor());
  client.getInInterceptors().add(new WSS4JInInterceptor(getInProps()));
  client.getOutInterceptors().add(new WSS4JOutInterceptor(getOutProps()));
  client.getInInterceptors().add(coverageChecker);
  
  SubmissionResponse response = port.submission(request);
  </code></pre>
  
  <p>My request data is formed like this.</p>
  
  <pre><code>&lt;soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"&gt;
      ....
      ....
      ....
  &lt;/soap:Envelope&gt;
  </code></pre>
  
  <p>I need to add additional namespace to <code>&lt;soap:Envelope&gt;</code>. My expected data should be like this,</p>
  
  <pre><code>&lt;soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:prefix1="url1" xmlns:prefix2="url2" xmlns:prefix3:"url3"&gt;
      ....
      ....
      ....
  &lt;/soap:Envelope&gt;
  </code></pre>
  
  <p>I tried adding those prefixes and namespace urls to <code>DefaultCryptoCoverageChecker</code> using Map and XpathExpressions. But seems like it does not made any changes to my request data.</p>
  
  <pre><code>Map&lt;String, String&gt; prefixes = new HashMap&lt;String, String&gt;();
  
  prefixes.put("prefix1", "url1");
  prefixes.put("prefix2", "url2");
  prefixes.put("prefix3", "url3");
  prefixes.put("prefix4", "url4");
  prefixes.put("prefix5", "url5");
  
  List&lt;XPathExpression&gt; xpaths = Arrays.asList(
          new XPathExpression("//prefix1:Envelope", CoverageType.SIGNED),
          new XPathExpression("//prefix2:Envelope", CoverageType.SIGNED),
          new XPathExpression("//prefix3:Envelope", CoverageType.SIGNED),
          new XPathExpression("//prefix4:Envelope", CoverageType.SIGNED),
          new XPathExpression("//prefix5:Envelope", CoverageType.SIGNED));
  
  DefaultCryptoCoverageChecker coverageChecker = new DefaultCryptoCoverageChecker();
  
  coverageChecker.addPrefixes(prefixes);
  coverageChecker.addXPaths(xpaths);
  
  coverageChecker.setSignBody(true);
  coverageChecker.setSignTimestamp(true);
  coverageChecker.setEncryptBody(true);
  coverageChecker.setSignAddressingHeaders(true);
  </code></pre>
  
  <p>Any help would be greatly appreciated.</p>
  
  <p><strong>Update 2:</strong></p>
  
  <p>I've tried Apache cxf's transformation feature.</p>
  
  <pre><code>Map&lt;String, String&gt; outTransformMap = Collections.singletonMap("{http://schemas.xmlsoap.org/soap/envelope/}Envelope", "Envelope");
  TransformOutInterceptor transformOutInterceptor = new TransformOutInterceptor();
  transformOutInterceptor.setOutTransformElements(outTransformMap);
  client.getOutInterceptors().add(transformOutInterceptor);
  </code></pre>
  
  <p>According to <a href="http://cxf.apache.org/docs/transformationfeature.html#TransformationFeature-JAX-WS" rel="nofollow">http://cxf.apache.org/docs/transformationfeature.html#TransformationFeature-JAX-WS</a>, above code will remove that specific namespace from <code>Envelope</code> node. And I can also confirm it by seeing the <code>xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/</code> is being removed from <code>&lt;soap:Envelope&gt;</code></p>
  
  <p>I tried the reverse of <code>transformOutInterceptor.setOutTransformElements(outTransformMap);</code> by replacing it with <code>transformOutInterceptor.setOutAppendElements(outTransformMap);</code>, where the <code>outTransformMap</code> will now contains <code>Collections.singletonMap("{url1 (which I need to add)}Envelope", "Envelope");</code>. But it's not appending it as a new Namespace to <code>Envelope</code>. What am I doing wrong here.. Is it really difficult to add additional namespace to <code>&lt;soap:Envelope&gt;</code> other than the default namesapce.</p>