Results 1 to 4 of 4

Thread: Spring-WS: Odd XML in SOAP envelope

Hybrid View

  1. #1
    Join Date
    Aug 2004
    Posts
    1,070

    Default 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()) ;
    if(logger.isDebugEnabled())
    logger.debug("Unmarshalled payload request to [" + requestObject + "]");
    Object responseObject = invokeInternal(requestObject);

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

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

    System.out.println("****************************** ****");
    response.writeTo(System.out);
    }
    }

    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="http://www.habuma.com/poker/schemas">
    <tns:handName xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:type="java:java.lang.String">FLUSH</tns:handName>
    </tns:EvaluateHandResponse>

    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="http://schemas.xmlsoap.org/soap/envelope/"
    xmlns:xsd="http://www.w3.org/2001/XMLSchema"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <soapenv:Body>
    <tns: xmlns:tns="http://www.habuma.com/poker/schemas">
    <tns: xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:type="java:java.lang.String"
    xmlns:tns="handName">FLUSH</tns:>
    </tns:>
    </soapenv:Body>
    </soapenv:Envelope>

    Notice that the body XML is completely messed up. First off, the elements only have a "tns" namespace...no 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. #2
    Join Date
    Jul 2005
    Location
    Rotterdam, the Netherlands
    Posts
    1,562

    Default

    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:

    Code:
    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,
    Arjen Poutsma

    Spring Web Services Dev Lead
    Please read the FAQ

  3. #3
    Join Date
    Aug 2004
    Posts
    1,070

    Default Spring-WS: Odd XML in SOAP envelope

    Quote 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...

    Code:
    java.lang.IllegalArgumentException: DOMResult does not contain Node
            at org.springframework.util.Assert.notNull(Assert.java:113)
            at org.springframework.oxm.AbstractMarshaller.marshalDomResult(AbstractMarshaller.java:203)
            at org.springframework.oxm.AbstractMarshaller.marshal(AbstractMarshaller.java:100)
            at com.habuma.poker.webservice.EvaluateHandEndpoint.invokeInternal(EvaluateHandEndpoint.java:25)
            at com.habuma.poker.webservice.MyMarshallingEndpoint.invoke(MyMarshallingEndpoint.java:35)
    ... { cut for brevity's sake }
    Then I changed the way I create the DOMResult to:

    Code:
                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. #4
    Join Date
    Jul 2005
    Location
    Rotterdam, the Netherlands
    Posts
    1,562

    Default

    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.

    Thanks,
    Arjen Poutsma

    Spring Web Services Dev Lead
    Please read the FAQ

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •