Hi,
I'm converting an existing SAAJ client into a Spring-WS client. I got the following error when the template tries to check for the fault:
org.springframework.ws.soap.saaj.SaajSoapEnvelopeE xception: Could not access envelope: org.xml.sax.SAXParseException: Premature end of file.; nested exception is javax.xml.soap.SOAPException: org.xml.sax.SAXParseException: Premature end of file.
It appears that the messages are created lazily from the stream, but the stream is closed before that happens. I was able to work around the problem by forcing the message to be read in the readResponse method (using hasFault() in this case, there may be a better way):
HttpUrlConnectionMessageSender webServiceMessageSender = new HttpUrlConnectionMessageSender() {
protected void readResponse(HttpURLConnection connection, MessageContext messageContext) throws IOException {
if (connection.getResponseCode() == HttpURLConnection.HTTP_NO_CONTENT || connection.getContentLength() == 0) {
return;
}
TransportInputStream tis = null;
try {
tis = new HttpUrlConnectionTransportInputStream(connection);
messageContext.readResponse(tis);
/* workaround problem with lazy read - force message to be read before stream is closed */
messageContext.getResponse().hasFault();
}
finally {
if (tis != null) {
tis.close();
}
}
}
};
I'm using Java 1.4, Spring 1.0 M3, and my SAAJ implementation is Axis 1.4. I suspect the behaviour may not be evident for other SAAJ implementations.
I've shown the HttpUrlConnectionMessageSender here but same problem and workaround applies for the commons http client one.
Regards,
Brad.


Reply With Quote
