title: Generation of empty namespace prefix using WebServiceTemplate from Spring-ws
body: <p>We are using Spring-ws version 2.4.2.RELEASE for calling an external WebService from a WSDL.</p>
  
  <p>The method we call is:</p>
  
  <pre><code>ValidateObjectResponse response = (ValidateObjectResponse) webServiceTemplate.marshalSendAndReceive(request);
  </code></pre>
  
  <p>The SOAP request that is generated contains an empty namespace prefix:</p>
  
  <pre><code>&lt;SOAP-ENV:Envelope xmlns:SOAPENV="http://schemas.xmlsoap.org/soap/envelope/"&gt; 
      &lt;SOAP-ENV:Header/&gt;
      &lt;SOAP-ENV:Body&gt;
          &lt;ns2:validateObject xmlns:ns2="http://ws.validator.sch.gazelle.ihe.net/" xmlns=""&gt;&lt;base64ObjectToValidate&gt;Cgo8P3ht...
      &lt;/SOAP-ENV:Body&gt;
  &lt;/SOAP-ENV&gt;
  </code></pre>
  
  <p>Behind the scenes, apache axiom is used (version 1.2.13) and in the release notes I read the following (<a href="https://ws.apache.org/axiom/release-notes/1.2.13.html" rel="nofollow noreferrer">https://ws.apache.org/axiom/release-notes/1.2.13.html</a>):</p>
  
  <p><em>"In Axiom 1.2.12, the declareNamespace methods in OMElement didn’t enforce this constraint and namespace declarations violating this requirement were silently dropped during serialization. This behavior is problematic because it may result in subtle issues such as unbound namespace prefixes. In Axiom 1.2.13 these methods have been changed so that they throw an exception if an attempt is made to bind the empty namespace name to a prefix."</em></p>
  
  <p>When we call the external webservice, we get the following exception:</p>
  
  <pre><code>java.lang.IllegalArgumentException: Cannot bind a prefix to the empty namespace name
  at org.apache.axiom.om.impl.dom.ElementImpl.declareNamespace(ElementImpl.java:754)
  at org.apache.axiom.om.impl.dom.ElementImpl.declareNamespace(ElementImpl.java:778)
  at org.apache.axiom.om.impl.dom.ElementImpl.setAttributeNS(ElementImpl.java:559)
  at com.sun.xml.bind.marshaller.SAX2DOMEx.startElement(SAX2DOMEx.java:163)
  at com.sun.xml.bind.v2.runtime.output.SAXOutput.endStartTag(SAXOutput.java:124)
  at com.sun.xml.bind.v2.runtime.XMLSerializer.endAttributes(XMLSerializer.java:302)
  at com.sun.xml.bind.v2.runtime.XMLSerializer.childAsSoleContent(XMLSerializer.java:588)
  at com.sun.xml.bind.v2.runtime.ClassBeanInfoImpl.serializeRoot(ClassBeanInfoImpl.java:312)
  at com.sun.xml.bind.v2.runtime.XMLSerializer.childAsRoot(XMLSerializer.java:490)
  at com.sun.xml.bind.v2.runtime.MarshallerImpl.write(MarshallerImpl.java:328)
  at com.sun.xml.bind.v2.runtime.MarshallerImpl.marshal(MarshallerImpl.java:257)
  at org.springframework.oxm.jaxb.Jaxb2Marshaller.marshal(Jaxb2Marshaller.java:680)
  at org.springframework.ws.support.MarshallingUtils.marshal(MarshallingUtils.java:81)
  at org.springframework.ws.client.core.WebServiceTemplate$2.doWithMessage(WebServiceTemplate.java:399)
  at org.springframework.ws.client.core.WebServiceTemplate.doSendAndReceive(WebServiceTemplate.java:590)
  at org.springframework.ws.client.core.WebServiceTemplate.sendAndReceive(WebServiceTemplate.java:555)
  at org.springframework.ws.client.core.WebServiceTemplate.marshalSendAndReceive(WebServiceTemplate.java:390)
  at org.springframework.ws.client.core.WebServiceTemplate.marshalSendAndReceive(WebServiceTemplate.java:383)
  at org.springframework.ws.client.core.WebServiceTemplate.marshalSendAndReceive(WebServiceTemplate.java:373)
  </code></pre>
  
  <p>My first idea was to lower the version of axiom to 2.1.12, but this gave conflicts with other libraries.</p>
  
  <p>Is there a way to avoid the creation of an empty namespace prefix using spring-ws?</p>
  
  <p>We have a WSDL, and there, everything looks ok to me, but we cannot modify it:</p>
  
  <pre><code>&lt;?xml version='1.0' encoding='UTF-8'?&gt;
  &lt;wsdl:definitions xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:tns="http://ws.validator.sch.gazelle.ihe.net/"
                xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
                name="GazelleObjectValidatorService" targetNamespace="http://ws.validator.sch.gazelle.ihe.net/"&gt;
      &lt;wsdl:types&gt;
          &lt;xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:tns="http://ws.validator.sch.gazelle.ihe.net/"
                 attributeFormDefault="unqualified" elementFormDefault="unqualified"
                 targetNamespace="http://ws.validator.sch.gazelle.ihe.net/"&gt;
          &lt;xs:element name="about" type="tns:about"/&gt;
          &lt;xs:element name="aboutResponse" type="tns:aboutResponse"/&gt;
          &lt;xs:element name="getAllAvailableObjectTypes" type="tns:getAllAvailableObjectTypes"/&gt;
          &lt;xs:element name="getAllAvailableObjectTypesResponse" type="tns:getAllAvailableObjectTypesResponse"/&gt;
          &lt;xs:element name="getAllSchematrons" type="tns:getAllSchematrons"/&gt;
          &lt;xs:element name="getAllSchematronsResponse" type="tns:getAllSchematronsResponse"/&gt;
          &lt;xs:element name="getSchematronByName" type="tns:getSchematronByName"/&gt;
          &lt;xs:element name="getSchematronByNameResponse" type="tns:getSchematronByNameResponse"/&gt;
          &lt;xs:element name="getSchematronsForAGivenType" type="tns:getSchematronsForAGivenType"/&gt;
          &lt;xs:element name="getSchematronsForAGivenTypeResponse" type="tns:getSchematronsForAGivenTypeResponse"/&gt;
          &lt;xs:element name="validateObject" type="tns:validateObject"/&gt;
          &lt;xs:element name="validateObjectResponse" type="tns:validateObjectResponse"/&gt;
  </code></pre>
  
  <p>This is the code where we create the WebServiceTemplate:</p>
  
  <pre><code>Jaxb2Marshaller marshaller = new Jaxb2Marshaller();
  marshaller.setPackagesToScan("com.test");
  WebServiceTemplate webServiceTemplate = new WebServiceTemplate(marshaller);
  webServiceTemplate.setDefaultUri(defaultUri);
  webServiceTemplate.setMessageSender(new HttpComponentsMessageSender(httpClientBuilder.build()));
  
  ValidateObject request = new ValidateObject();
  request.setBase64ObjectToValidate(base64Object);
  request.setXmlReferencedStandard(xmlReferencedStandard);
  request.setXmlMetadata(xmlMetadata);
  ValidateObjectResponse response = (ValidateObjectResponse) 
  webServiceTemplate.marshalSendAndReceive(request);
  return response.getValidationResult();
  </code></pre>
  
  <p>The question is how I can avoid the generation of the empty namespace name:</p>
  
  <pre><code>&lt;ns2:validateObject xmlns:ns2="http://ws.validator.sch.gazelle.ihe.net/" xmlns=""&gt; 
  </code></pre>
  
  <p>so that axiom can no longer complain?</p>