Announcement Announcement Module
Collapse
No announcement yet.
WebServiceTemplate suppressed empty xmlns-Attribut (xmlns="") in SOAP-Message Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • WebServiceTemplate suppressed empty xmlns-Attribut (xmlns="") in SOAP-Message

    Hello,

    I have a xml-message with a default namespace on top of the message and
    an empty xmlns-Attribut some elements deeper in the structure

    e.g.
    <root xmlns="http://service.mycompany.org/">
    <node1>
    <node2 xmlns="">
    <node3>hello World</node3>
    </node2>
    </node1>
    </root>


    When I generate a SOAP-message with WebServiceTemplate the
    empty xmlns="" at node2 is suppressed.

    e.g.
    <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
    <SOAP-ENV:Header/><SOAP-ENV:Body>
    <root xmlns="http://service.mycompany.org/">
    <node1>
    <node2>
    <node3>hello World</node3>
    </node2>
    </node1>
    </root>
    </SOAP-ENV:Body>
    </SOAP-ENV:Envelope>


    Can anybody give me a hint what to do to get the empty xmlns in
    the SOAP-message?

    Thanks Olaf

    below is my testcase

    import java.io.ByteArrayOutputStream;
    import java.io.StringReader;
    import java.io.StringWriter;
    import java.io.IOException;

    import javax.xml.transform.stream.StreamResult;
    import javax.xml.transform.stream.StreamSource;

    import org.springframework.ws.client.core.WebServiceTempl ate;
    import org.springframework.ws.client.core.WebServiceMessa geCallback;
    import org.springframework.ws.WebServiceMessage;
    import org.springframework.ws.soap.SoapMessage;


    public class Test {

    /**
    * @param args
    */
    public static void main(String[] args) {
    String message =
    "<root xmlns=\"http://service.mycompany.org/\">\n"+
    "<node1>\n"+
    "<node2 xmlns=\"\">\n"+
    "<node3>hello World</node3>\n"+
    "</node2>\n"+
    "</node1>\n"+
    "</root>";

    StreamSource source = new StreamSource(new StringReader(message));

    StringWriter strwout = new StringWriter();
    StreamResult result = new StreamResult(strwout);
    WebServiceTemplate webServiceTemplate = new WebServiceTemplate();

    System.out.println("The original xml\n"+message);

    webServiceTemplate.sendSourceAndReceiveToResult("h ttp://localhost:8080/myservice"
    ,source
    ,new WebServiceMessageCallback() {
    public void doWithMessage(WebServiceMessage message) {
    try {
    ByteArrayOutputStream baout = new ByteArrayOutputStream();
    ((SoapMessage)message).writeTo(baout);
    System.out.println("The SOAP-message\n"+new String(baout.toByteArray()));
    } catch(IOException ex) {
    ex.printStackTrace();
    }
    }
    }
    ,result);
    }
    }

  • #2
    Spring-WS has very little influence on how the SOAP envelope is created. You could try:

    Code:
    <root xmlns:tns="http://service.mycompany.org/">
    <tns:node1>
    <node2>
    <node3>hello World</node3>
    </node2>
    </tns:node1>
    </tns:root>

    Comment

    Working...
    X