[SWS-583] AbstractHttpSenderConnection does not immediately recognise HTTP 204 has no content-length Created: 12/Nov/09  Updated: 04/May/12  Resolved: 06/Jan/10

Status: Closed
Project: Spring Web Services
Component/s: Core
Affects Version/s: 1.5.8
Fix Version/s: 1.5.9

Type: Improvement Priority: Minor
Reporter: Adam Healey Assignee: Arjen Poutsma
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: 0d
Time Spent: 0.2h
Original Estimate: Not Specified


 Description   

The hasResponse() method in AbstractHttpSenderConnection currently only has specific logic for the HTTP 202 status code, immediately returning false. If a 204 is received without the Conent-Length header set (not mandatory as by definition a 204 has no content), the method will go straight to inferring the content-length by trying to read the input stream. The input stream will not contain any content and so it is left to the client server's keepAliveTimeout value to close the stream and cause the method to finish.

Although the correct result is returned from the method, it would be much better if there was a simple check for the 204 status to return false straight away.

This caused issues with our system as our sending method which uses the WebServiceTemplate took 20 seconds to finish even though the HTTP 204 was received within a few ms (the 20 seconds was configured on the client's server).

The first if statement in the current method could be adapted (with a new STATUS_NO_CONTENT added to the HttpTransportConstants representing 204):

 protected final boolean hasResponse() throws IOException {
        if (HttpTransportConstants.STATUS_ACCEPTED == getResponseCode()) {
            return false;
        }
        long contentLength = getResponseContentLength();
        if (contentLength < 0) {
            if (responseBuffer == null) {
                responseBuffer = FileCopyUtils.copyToByteArray(getRawResponseInputStream());
            }
            contentLength = responseBuffer.length;
        }
        return contentLength > 0;
    }



 Comments   
Comment by Arjen Poutsma [ 06/Jan/10 ]

Added formatting.

Comment by Arjen Poutsma [ 06/Jan/10 ]

Fixed. Thanks for the suggestion!

Comment by Arjen Poutsma [ 04/May/12 ]

Closing old issues

Generated at Tue Dec 12 18:07:15 UTC 2017 using JIRA 6.4.14#64029-sha1:ae256fe0fbb912241490ff1cecfb323ea0905ca5.