views:

68

answers:

2

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

A: 

It seems like this behavior is expected and was rejected by this issue: http://bugs.sun.com/bugdatabase/view%5Fbug.do?bug%5Fid=4396798.

Superfilin
Yes, but isn't there something else I can use that isn't written poorly by Sun? That bug doesn't quite match up to mine, there is a forum message http://forums.sun.com/thread.jspa?threadID=450453 which says "You can't. If you check the j2se source code you will notice that sun.net.www.http.HttpClient just drops the '100 Continue' and waits for the actual response that follows."So I'm hoping there's a non-Sun solution somewhere...
Richard
+1  A: 

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");
        }
    }
}
Richard