Uploaded image for project: 'Spring Web Services'
  1. Spring Web Services
  2. SWS-359

Using Axiom with payload caching off sometimes creates empty soap bodies

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 1.5.2
    • Fix Version/s: 1.5.3
    • Component/s: Core
    • Labels:
      None

      Description

      It appears that if you're using Castor to marshal your responses, and you're using Axiom without payload caching, that the SOAP response comes back with an empty Soap Body. I did not try this with other Marshalling technologies like JAXB, etc, so I'm not sure if it is restricted to Castor only or not.

      It looks like NonCachingPayload.DelegatingStreamWriter.writeEndDocument() never gets called at least when marshalling with Castor. Castor by default does not fire an endDocument SAX event (or close or flush for that matter). But if you call setMarshalAsDocument(true) on a castor marshaller it does call endDocument().

      I just now worked around this with Castor by creating a simple subclass of CastorMarshaller like this below:
      public class MyCastorMarshaller extends CastorMarshaller {
      protected void customizeMarshaller(Marshaller marshaller)

      { super.customizeMarshaller(marshaller); marshaller.setMarshalAsDocument(true); }

      }

      See this forum thread for additional details: http://forum.springframework.org/showthread.php?p=181732&posted=1#post181732

        Activity

        jim Jim Cummings created issue -
        Hide
        arjen.poutsma Arjen Poutsma added a comment -

        I could expose that property on the CastorMarshaller, so you can configure it in Spring config.

        I'm open for nicer solutions, though.

        Show
        arjen.poutsma Arjen Poutsma added a comment - I could expose that property on the CastorMarshaller, so you can configure it in Spring config. I'm open for nicer solutions, though.
        arjen.poutsma Arjen Poutsma made changes -
        Field Original Value New Value
        Fix Version/s 1.5.3 [ 10982 ]
        Hide
        chrisborrill Chris Borrill added a comment -

        I am using org.springframework.ws.soap.axiom.AxiomSoapMessageFactory and org.springframework.oxm.jibx.JibxMarshaller. If I set the payloadCaching property of the AxiomSoapMessageFactory to false the SOAP body is empty, but if I set payloadCaching to true (the default) everthing works correctly.

        Show
        chrisborrill Chris Borrill added a comment - I am using org.springframework.ws.soap.axiom.AxiomSoapMessageFactory and org.springframework.oxm.jibx.JibxMarshaller. If I set the payloadCaching property of the AxiomSoapMessageFactory to false the SOAP body is empty, but if I set payloadCaching to true (the default) everthing works correctly.
        Hide
        jim Jim Cummings added a comment -

        I wonder if maybe NonCachingPayload.DelegatingStreamWriter could more proactively detect the end of the payload element by watching the writeStartElement(), writeEndElement() and writeEmptyElement() events so that it would not need the writeEndDocument() to get called. It would probably need to support the possibility of nested elements in the payload having the same name as the root payload element, but it might could be done with a counter of starts vs ends for the root ele name. Dunno - just a thought.

        Show
        jim Jim Cummings added a comment - I wonder if maybe NonCachingPayload.DelegatingStreamWriter could more proactively detect the end of the payload element by watching the writeStartElement(), writeEndElement() and writeEmptyElement() events so that it would not need the writeEndDocument() to get called. It would probably need to support the possibility of nested elements in the payload having the same name as the root payload element, but it might could be done with a counter of starts vs ends for the root ele name. Dunno - just a thought.
        Hide
        arjen.poutsma Arjen Poutsma added a comment -

        I had the same idea (counting elements) last night in bed. Great minds...

        Show
        arjen.poutsma Arjen Poutsma added a comment - I had the same idea (counting elements) last night in bed. Great minds...
        Hide
        jim Jim Cummings added a comment -

        Arjen - another related thing with this. I was working with a stax-based endpoint and saw similar issues with the empty body. I was able to temporarily work around that, but I noticed that when using StAX marshalling I also needed to call writeStartDocument() on my XMLStreamWriter. The DelegatingStreamWriter doesn't default the encoding to anything, and this was causing a NPE in ByteArrayDataSource.getXMLBytes() deep in axiom code during the msg.writeTo() call.

        Could you default the encoding in case writeStartDocument() isn't called either? Thanks!

        Show
        jim Jim Cummings added a comment - Arjen - another related thing with this. I was working with a stax-based endpoint and saw similar issues with the empty body. I was able to temporarily work around that, but I noticed that when using StAX marshalling I also needed to call writeStartDocument() on my XMLStreamWriter. The DelegatingStreamWriter doesn't default the encoding to anything, and this was causing a NPE in ByteArrayDataSource.getXMLBytes() deep in axiom code during the msg.writeTo() call. Could you default the encoding in case writeStartDocument() isn't called either? Thanks!
        Hide
        arjen.poutsma Arjen Poutsma added a comment -

        I will add element depth counting. I don't think counting the writeEmptyElement() events is necessary, though, because that's just elementDepth + 1 -1. Also fixed the encoding bug, now defaults to UTF-8, like all XML should.

        Could you check a recent snapshot (as of tomorrow) to check if things work now?

        Show
        arjen.poutsma Arjen Poutsma added a comment - I will add element depth counting. I don't think counting the writeEmptyElement() events is necessary, though, because that's just elementDepth + 1 -1. Also fixed the encoding bug, now defaults to UTF-8, like all XML should. Could you check a recent snapshot (as of tomorrow) to check if things work now?
        arjen.poutsma Arjen Poutsma made changes -
        Resolution Fixed [ 1 ]
        Status Open [ 1 ] Resolved [ 5 ]
        Hide
        arjen.poutsma Arjen Poutsma added a comment -

        Closing issues in 1.5.3

        Show
        arjen.poutsma Arjen Poutsma added a comment - Closing issues in 1.5.3
        arjen.poutsma Arjen Poutsma made changes -
        Status Resolved [ 5 ] Closed [ 6 ]
        Hide
        chrisborrill Chris Borrill added a comment -

        Make sure you have no active interceptors if payload caching is set to false, since these will consume the message, as described here:

        http://static.springframework.org/spring-ws/sites/1.5/apidocs/org/springframework/ws/soap/axiom/AxiomSoapMessageFactory.html

        Good luck,
        Chris

        Show
        chrisborrill Chris Borrill added a comment - Make sure you have no active interceptors if payload caching is set to false, since these will consume the message, as described here: http://static.springframework.org/spring-ws/sites/1.5/apidocs/org/springframework/ws/soap/axiom/AxiomSoapMessageFactory.html Good luck, Chris
        Transition Time In Source Status Execution Times Last Executer Last Execution Date
        Open Open Resolved Resolved
        15d 16h 39m 1 Arjen Poutsma 06/Jun/08 2:56 AM
        Resolved Resolved Closed Closed
        45d 19h 11m 1 Arjen Poutsma 21/Jul/08 10:07 PM

          People

          • Assignee:
            arjen.poutsma Arjen Poutsma
            Reporter:
            jim Jim Cummings
          • Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: