Announcement Announcement Module
No announcement yet.
Spring-WS: Odd XML in SOAP envelope Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Spring-WS: Odd XML in SOAP envelope

    I've rattled my brain on this one for almost a week and finally decided to see if someone else could help me out...

    Basically, I have written a simple web-service using Spring-WS and a Castor marshaller. I've made a small tweak to AbstractMarshallingPayloadEndpoint so that I can see what my response is being marshalled to. The new invoke() method looks like this:

    public final void invoke(MessageContext messageContext)
    throws Exception
    WebServiceMessage request = messageContext.getRequest();
    Object requestObject = unmarshaller.unmarshal(request.getPayloadSource()) ;
    logger.debug("Unmarshalled payload request to [" + requestObject + "]");
    Object responseObject = invokeInternal(requestObject);

    marshaller.marshal(responseObject, new StreamResult(System.out));

    if(responseObject != null)
    logger.debug("Marshalling [" + responseObject + "] to response payload");
    WebServiceMessage response = messageContext.getResponse();
    marshaller.marshal(responseObject, response.getPayloadResult());

    System.out.println("****************************** ****");

    The first thing I do is use the marshaller to marshal the message to System.out. The result of that looks like this (edited for readability's sake):

    <?xml version="1.0" encoding="UTF-8"?>
    <tns:EvaluateHandResponse xmlns:tns="">
    <tns:handName xmlns:xsi=""

    And this is exactly what I expected.

    Then, I let the object be marshalled into the WebServiceMessage's response payload message and use the writeTo() method to send the message to System.out. I get this result (again, formatted for readability):

    <soapenv:Envelope xmlns:soapenv=""
    <tns: xmlns:tns="">
    <tns: xmlns:xsi=""

    Notice that the body XML is completely messed up. First off, the elements only have a "tns" element name. Then, the xmlns:tns on the inner element is set to what should be the element's name.

    I've dug around in the Spring-WS source code, ran things through a debugger, and lost my patience plenty over this one. My current line of thinking is that somehow the SAAJ implementation is screwing up the message...but I've tried by Axis' SAAJ and the Sun SAAJ implementation that comes with Spring-WS and the result is the same.

    Again, keep in mind that the marshaller seems to be working perfectly. The message gets hosed somewhere between the marshaller and the WebServiceMessage's payload result.

    Anybody run into this before? Anyone have any clues? Is it something I'm doing wrong?

  • #2
    Have tried marshalling to a DOM document? Basically, it could be a bug in the DOM code of Castor. Basically, you could write something like:

    DOMResult domResult = new DOMResult();
    marshaller.marshal(responseObject, domResult);
    And then inspect the dom node contained in the domResult with a debugger. Or you could transform it to System.out again, using a Transformer.

    Let me know how that works,


    • #3
      Spring-WS: Odd XML in SOAP envelope

      Originally posted by poutsma
      Have tried marshalling to a DOM document? Basically, it could be a bug in the DOM code of Castor.
      I tried to marshal to a DOMResult as you suggested and got the following exception...

      java.lang.IllegalArgumentException: DOMResult does not contain Node
              at org.springframework.util.Assert.notNull(
              at org.springframework.oxm.AbstractMarshaller.marshalDomResult(
              at org.springframework.oxm.AbstractMarshaller.marshal(
      ... { cut for brevity's sake }
      Then I changed the way I create the DOMResult to:

                  Document document = new CoreDocumentImpl();
                  DOMResult domResult = new DOMResult(document);
      This got me past the exception. Then I walked the DOM...everything appears to be in place in the DOM...which leads me to believe that it marshalled correctly. But the result I got back on the client was the bogus XML I showed in the original forum post. (I confirmed this by using tcpmon to intercept the response.)

      I then tried to walk the DOM of the payload result's node and it gave me nothing. It was as if there were no elements in the result.

      Again, from all appearances, Castor is marshalling the object correctly...marshalling to a StreamResult or a DOMResult that I create backs this up. But it doesn't seem to work when marshalling to the payload result.

      Any more clues?


      • #4
        I think I'm out of ideas :-(. I did some testing of my own, but I can't reproduce this.

        Could you please create an issue here? Please attach the project you have, because I can't seem to reproduce the bug.