JAX-WS namespace in attribute, not prefix

1k views Asked by At

is possible in JAX-WS to generate xmlns attributes instead of prefixes?

Example: Object A from package myns.a contains some objects B1, B2 from package myns.b. Generated SOAP message:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:a="urn:myns/a" xmlns:b="urn:myns/b">
   <soapenv:Header/>
   <soapenv:Body>
      <a:A1>
         <b:B1>123456</b:B1>
         <b:B2>abc</b:B2>  
      </a:A1>
   </soapenv:Body>
</soapenv:Envelope>

However, i need to generate it this way (so prefix b should be removed and all objects from package myns.b should have xmlns attribute):

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:a="urn:myns/a">
   <soapenv:Header/>
   <soapenv:Body>
      <a:A1>
            <B1 xmlns="urn:myns/b">123456</B1>
            <B2 xmlns="urn:myns/b">abc</B2>
      </a:A1>
   </soapenv:Body>
</soapenv:Envelope>

Is there a simple way, how to handle this? For example on package-info.java level?

1

There are 1 answers

0
mrq On

I solved this using custom SOAPHandler and removing prefixes from element in urn:myns/b namespace.

Simplified snippet:

@Override
public boolean handleMessage(SOAPMessageContext context) {

  SOAPBody body = context.getMessage().getSOAPPart().getEnvelope().getBody();

  //do recursivelly, this is just example
  Iterator iter = body.getChildElements();
  while (iter.hasNext()) {
    Object object = iter.next();

    if (object instanceof SOAPElement) {
      SOAPElement element = (SOAPElement) object;

      if("urn:myns/b".equals(element.getNamespaceURI())){
         element.setPrefix("");
      }       
   }
}