views:

35

answers:

2

I have working code using the spring-ws library to respond to soap requests. I moved this code to a different project (I'm merging projects) and now it is failing. I would like to figure out the reason for the failure.

The symptom I get is this: when the HTTP request arrives, spring begins handling the call. Then I get the following exception:

org.springframework.ws.soap.saaj.SaajSoapEnvelopeException: Could not access envelope: java.io.IOException: Stream closed; nested exception is javax.xml.soap.SOAPException: java.io.IOException: Stream closed
    at org.springframework.ws.soap.saaj.SaajSoapMessage.getEnvelope(SaajSoapMessage.java:109)
        <<more lines that don't matter>>
Caused by: java.io.IOException: Stream closed
    at java.io.PushbackInputStream.ensureOpen(PushbackInputStream.java:57)
    at java.io.PushbackInputStream.read(PushbackInputStream.java:116)
    at org.apache.xerces.impl.XMLEntityManager$RewindableInputStream.read(Unknown Source)
    at org.apache.xerces.impl.XMLEntityManager.setupCurrentEntity(Unknown Source)
    at org.apache.xerces.impl.XMLVersionDetector.determineDocVersion(Unknown Source)
    at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
    at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
    at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
    at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source)
    at org.apache.xerces.jaxp.SAXParserImpl$JAXPSAXParser.parse(Unknown Source)
    at org.apache.xerces.jaxp.SAXParserImpl.parse(Unknown Source)
    at org.apache.axis.encoding.DeserializationContext.parse(DeserializationContext.java:227)
    at org.apache.axis.SOAPPart.getAsSOAPEnvelope(SOAPPart.java:696)
    ... 30 more

Examining it in a debugger, it appears that spring successfully handles HTTP headers, but then when it begins to process the contents of the SOAP message itself, it chokes when reading the very first character of the body. Some googling for the error message suggests that the problem is that a PushbackInputStream which is apparently used for reading from the socket is read twice or perhaps has close() called and then is read afterward.

It is happening inside of spring-ws, not my code, and since it worked fine before I moved the code to a new project it must have something to do with versions of spring, or something it uses like axis or xerces. But I can't find any differences in versions of these! Has anyone encountered this error before? Or do you have any suggestions of approaches I could take in troubleshooting this?

+1  A: 

My guess would be that something is reading the stream before your attempting to read the body of the message. This is the typical situation.

If something else is reading the stream it could be consuming the entire stream and calling flush() and close() which would cause the situation your in.

Have you put a sniffer on either end and observed that the soap message actually contains a body? This is less likely imo since the stream is actually closed and throwing a null pointer or anything.

Knife-Action-Jesus
I agree that something is probably reading it beforehand, and it sort of has to be some part of Spring-ws: either spring itself, or xalan or saaj... one of these pieces. Thanks for the suggestion about checking whether the body is empty: I doubt it (since I didn't change anything about the client end) but it's easy enough to check and therefore worth doing.
mcherm
A: 

Final Resolution:

It turns out that the problem was NOT on the server at all. Instead, there was something wrong with the tool I was using to send the requests (SoapUI). Many thanks to Knife-Action-Jesus for suggesting I look into it.

mcherm