Page 1 of 2 12 LastLast
Results 1 to 10 of 11

Thread: Stream closed before response read with WebServiceTemplate + Axis SAAJ Soap Messages

  1. #1
    Join Date
    Jun 2005
    Location
    Australia
    Posts
    16

    Default Stream closed before response read with WebServiceTemplate + Axis SAAJ Soap Messages

    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.

  2. #2
    Join Date
    Jul 2005
    Location
    Rotterdam, the Netherlands
    Posts
    1,562

    Default

    Looks like a bug. Can you file a JIRA issue please?

    Thanks for spotting this! The client-side support is pretty fresh, and I didn't have the opportunity to try it out on all servers.
    Arjen Poutsma

    Spring Web Services Dev Lead
    Please read the FAQ

  3. #3
    Join Date
    Jun 2005
    Location
    Australia
    Posts
    16

    Default

    Sure thing - http://opensource.atlassian.com/proj.../browse/SWS-86.

    I like the client side support - my spring-ws client code is less creepy than the saaj client code it replaced.

    Some other thoughts/questions about the client side support:

    Is the WebServiceMessageCallback the correct place to set a SOAPAction?

    I've found I have to downcast to SoapMessage often and even SaajSoapMessage occassionally (so I could call setSaajMessage to replace the entire message in a WebServiceMessageCallback). Is this something you would expect? I think this is partly because I'm doing things with headers so getPayloadSource() and getPayloadResult() often aren't enough.

    Should WebServiceGatewaySupport expose the template via the WebServiceOperations interface instead of the template class?

    It wasn't immediately obvious to me from the javadoc how a FaultResolver was supposed to do its work (throw a runtime exception - demonstrated by SimpleFaultResolver).

  4. #4
    Join Date
    Jul 2005
    Location
    Rotterdam, the Netherlands
    Posts
    1,562

    Default

    Quote Originally Posted by BradHarvey View Post
    Thanks!

    Quote Originally Posted by BradHarvey View Post
    Is the WebServiceMessageCallback the correct place to set a SOAPAction?
    Yes, it is. I should create a convenience implementation of the callback for this purpose.

    Quote Originally Posted by BradHarvey View Post
    I've found I have to downcast to SoapMessage often and even SaajSoapMessage occassionally (so I could call setSaajMessage to replace the entire message in a WebServiceMessageCallback). Is this something you would expect? I think this is partly because I'm doing things with headers so getPayloadSource() and getPayloadResult() often aren't enough.
    yes, that's what I would expect. Most people are only interested in the source of the message. I also plan to add functionality similar to the EndpointInterceptors.

    Quote Originally Posted by BradHarvey View Post
    Should WebServiceGatewaySupport expose the template via the WebServiceOperations interface instead of the template class?
    The gateway support class is modelled after JmsGatewaySupport, which also exposes a template. I basically copied the design.

    Quote Originally Posted by BradHarvey View Post
    It wasn't immediately obvious to me from the javadoc how a FaultResolver was supposed to do its work (throw a runtime exception - demonstrated by SimpleFaultResolver).
    Yeah, I though about the runtime vs checked exception thing too, but since all of Spring's templates only throw runtime exceptions, I followed that lead. The only exception to the rule is the IOException, which I kept around.
    Last edited by Arjen Poutsma; Feb 1st, 2007 at 05:08 PM. Reason: Fixed url
    Arjen Poutsma

    Spring Web Services Dev Lead
    Please read the FAQ

  5. #5
    Join Date
    Jun 2005
    Location
    Australia
    Posts
    16

    Default

    All sounds good, thanks for the feedback. Client interceptors would be nifty, especially if they could receive context from the caller (eg, a user/pass so the interceptor can add a security header).

    Cheers,
    Brad.

  6. #6
    Join Date
    Jul 2005
    Location
    Rotterdam, the Netherlands
    Posts
    1,562

    Default

    The issue is now fixed. Unfortunately, I had to change the interface of WebServiceTemplate in order to do so. Methods which return a Source could not be sustained, because the inputstream underlying the Source could already be closed. Instead, there is a SourceExtractor interface, which allows you to read from the source.

    It works similar to JdbcTemplate, and its ResultSetExtractor.
    Arjen Poutsma

    Spring Web Services Dev Lead
    Please read the FAQ

  7. #7
    Join Date
    Jun 2005
    Location
    Australia
    Posts
    16

    Default

    Great. I've had a quick look and it looks good, but I haven't had a chance to update and use it yet.

  8. #8

    Default

    Hmmm I think I just came accross the same issue.

  9. #9
    Join Date
    Jul 2005
    Location
    Rotterdam, the Netherlands
    Posts
    1,562

    Default

    This is solved in the snapshots.
    Arjen Poutsma

    Spring Web Services Dev Lead
    Please read the FAQ

  10. #10

    Default

    Ok. Any idea when M4 will be bundled up as a release?
    Last edited by decrypt; Apr 4th, 2007 at 04:18 PM. Reason: It wasn't important

Posting Permissions

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