Question

I am using Apache Commons HttpClient 3.1, and I found that HttpURLConnection from Sun drops the 100 Continues from the stream.

So therefore I don't seem able to get the 100 Continue as they are apparently dropped by Sun's code.

I am unable to move forward to HttpClient 4.0 as that would require many changes to already existing code so the solution has to either be 3.1 or something that doesn't conflict.

Any ideas?

Thanks

Was it helpful?

Solution

I found the solution!

Over-ride processStatusLine and check for status of 100.

Remember that the first 100 is expected (server telling me I can continue with the POST), and in my case I can safely ignore that one. This way I get all the information that my server is responding with.

public class Counting100PostMethod extends PostMethod {
Logger log = Logger.getLogger(Counting100PostMethod.class);
boolean first100 = true;

public Counting100PostMethod() {
    super();
}

public Counting100PostMethod(String s) {
    super(s);
}

@Override
protected void processStatusLine(HttpState httpState, HttpConnection httpConnection) {
    super.processStatusLine(httpState, httpConnection);
    int status = getStatusCode();
    if (status == 100) {
        if (first100) {
            first100 = false;
        } else {
            // can now increment counter
            log.debug("Increment counter");
        }
    }
}

OTHER TIPS

It seems like this behavior is expected and was rejected by this issue: http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4396798.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top