hc-httpclient-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Simon Wilkinson" <simon.wilkin...@gmail.com>
Subject Re: Unexpected failure: HTTP/1.1 400 Bad Request at the end of every PUT using Expect-Continue = true
Date Tue, 18 Nov 2008 20:54:17 GMT
When I try that, I still get the "Unexpected failure: HTTP/1.1 400 Bad
Request" line at the end of every file.  I have also discocvered that
the files are all corrupted when they are transferred.  They are extra
random characters on an extra line at the top of each file, and there
are characters missing from the bottom of every file.  I assume the
missing characters at the bottom have to do with the file length not
being correct because of the extra characters at the top, but I can't
seem to figure out where those are coming from.  I create a new
HttpClient and a new PutMethod for every file I am trying to transfer.
 I also have "httpPut.releaseConnection();"  in a finally block, and
have also tried adding "httpPut.abort();" in order to ensure the
connection is released and flushed.

Has anybody had any issues like this, or have any suggestions as to
what is going on?  I'm wondering if the HTTP 400 error is a result of
trying to write the last few bytes after the actual file length number
of bytes have already been written, and the server rejecting it?

Thanks,

Simon

2008/11/18 Oleg Kalnichevski <olegk@apache.org>:
> On Mon, 2008-11-17 at 14:07 -0500, Simon Wilkinson wrote:
>> Hi,
>>
>> I have the following code to set up a Put method:
>>
>>        HttpClient client = new HttpClient();
>>
>>         PutMethod httpPut = new PutMethod(httpUrl);
>>         File file = new File(localFilePath);
>>
>>         httpPut.getParams().setParameter(HttpMethodParams.RETRY_HANDLER,
>>                   new DefaultHttpMethodRetryHandler(5, false));
>>
>>         httpPut.setRequestEntity(new InputStreamRequestEntity(new
>> FileInputStream(file)));
>>         httpPut.getParams().setBooleanParameter(HttpMethodParams.USE_EXPECT_CONTINUE,
>> true);
>>
>>         httpPut.setContentChunked(true);
>>         httpPut.setRequestHeader("Content-Type",
>> "application/octet-stream"); //$NON-NLS-1$ //$NON-NLS-2$
>>         httpPut.setRequestHeader("Connection", "keep-alive");
>> //$NON-NLS-1$//$NON-NLS-2$
>>         httpPut.setRequestHeader("Content-Length", ""+file.length());
>> //$NON-NLS-1$ //$NON-NLS-2$
>>
>>         try {
>>               client.executeMethod(httpPut);
>>
>>               if (httpPut.getStatusCode() == HttpStatus.SC_OK) {
>>                   System.out.println(httpPut.getResponseBodyAsString());
>>               } else {
>>                   System.out.println("Unexpected failure: " +
>> httpPut.getStatusLine().toString()); //$NON-NLS-1$
>>               }
>>           }catch(Exception e) {
>>               throw new Exception(e);
>>           } finally {
>>               httpPut.releaseConnection();
>>           }
>>
>> After every file is uploaded (successfully) I get the following line:
>>
>>       Unexpected failure: HTTP/1.1 400 Bad Request
>>
>> Here is the ouput with the header wire + context logging enabled for a
>> successful upload with the error at the end:
>>
>> 2008/11/17 14:07:21:924 EST [DEBUG] DefaultHttpParams - Set parameter
>> http.method.retry-handler =
>> org.apache.commons.httpclient.DefaultHttpMethodRetryHandler@774e1f2b
>> 2008/11/17 14:07:21:940 EST [DEBUG] DefaultHttpParams - Set parameter
>> http.protocol.expect-continue = true
>> 2008/11/17 14:07:21:940 EST [DEBUG] HttpConnection - Open connection
>> to virtvc5:443
>> 2008/11/17 14:07:21:940 EST [DEBUG] header - >> "PUT
>> /folder/4ed084dc-3b8f-4b66-a4f9-3bbc49adfd07/DummyWindows.vmx?dcPath=a/b/virtDC5&dsName=storage1
>> HTTP/1.1[\r][\n]"
>> 2008/11/17 14:07:21:940 EST [DEBUG] HttpMethodBase - Adding Host request header
>> 2008/11/17 14:07:21:940 EST [DEBUG] header - >> "Cookie:
>> vmware_soap_session="16E6FFB7-0FA9-4C85-BBEC-4F58AACD3996"[\r][\n]"
>> 2008/11/17 14:07:21:940 EST [DEBUG] header - >> "Content-Type:
>> application/octet-stream[\r][\n]"
>> 2008/11/17 14:07:21:940 EST [DEBUG] header - >> "Connection: keep-alive[\r][\n]"
>> 2008/11/17 14:07:21:940 EST [DEBUG] header - >> "Content-Length: 1693[\r][\n]"
>> 2008/11/17 14:07:21:940 EST [DEBUG] header - >> "User-Agent: Jakarta
>> Commons-HttpClient/3.0-rc2[\r][\n]"
>> 2008/11/17 14:07:21:940 EST [DEBUG] header - >> "Host: virtvc5[\r][\n]"
>> 2008/11/17 14:07:21:940 EST [DEBUG] header - >> "Expect: 100-continue[\r][\n]"
>> 2008/11/17 14:07:21:940 EST [DEBUG] header - >> "[\r][\n]"
>> 2008/11/17 14:07:24:940 EST [INFO] HttpMethodBase - 100 (continue)
>> read timeout. Resume sending the request
>> 2008/11/17 14:07:24:940 EST [DEBUG] EntityEnclosingMethod - Request body sent
>> 2008/11/17 14:07:24:940 EST [DEBUG] header - << "HTTP/1.1 400 Bad
>> Request[\r][\n]"
>> 2008/11/17 14:07:24:940 EST [DEBUG] header - << "Date: Mon, 17 Nov
>> 2008 19:03:58 GMT[\r][\n]"
>> 2008/11/17 14:07:24:940 EST [DEBUG] header - << "Connection: close[\r][\n]"
>> 2008/11/17 14:07:24:940 EST [DEBUG] header - << "Content-Type:
>> text/html[\r][\n]"
>> 2008/11/17 14:07:24:940 EST [DEBUG] header - << "Content-Length: 50[\r][\n]"
>> Unexpected failure: HTTP/1.1 400 Bad Request
>> 2008/11/17 14:07:24:940 EST [DEBUG] HttpMethodBase - Should close
>> connection in response to directive: close
>> 2008/11/17 14:07:24:940 EST [DEBUG] HttpConnection - Releasing
>> connection back to connection manager.
>>
>> Has anybody seen this before, or have any ideas where the unexpected
>> failure is coming from, as the functionality seems to be working?
>>
>> Thanks,
>>
>> Simon
>>
>
> I suppose the server does not support the 'expect-continue' handshaking.
> Try disabling it.
>
> Oleg
>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
>> For additional commands, e-mail: httpclient-users-help@hc.apache.org
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
> For additional commands, e-mail: httpclient-users-help@hc.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
For additional commands, e-mail: httpclient-users-help@hc.apache.org


Mime
View raw message