Return-Path: Delivered-To: apmail-hc-httpclient-users-archive@www.apache.org Received: (qmail 21120 invoked from network); 18 Nov 2008 20:54:58 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 18 Nov 2008 20:54:58 -0000 Received: (qmail 36652 invoked by uid 500); 18 Nov 2008 20:55:06 -0000 Delivered-To: apmail-hc-httpclient-users-archive@hc.apache.org Received: (qmail 36629 invoked by uid 500); 18 Nov 2008 20:55:06 -0000 Mailing-List: contact httpclient-users-help@hc.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: "HttpClient User Discussion" Delivered-To: mailing list httpclient-users@hc.apache.org Received: (qmail 36618 invoked by uid 99); 18 Nov 2008 20:55:06 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 18 Nov 2008 12:55:06 -0800 X-ASF-Spam-Status: No, hits=-0.0 required=10.0 tests=SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: domain of simon.wilkinson@gmail.com designates 74.125.46.155 as permitted sender) Received: from [74.125.46.155] (HELO yw-out-1718.google.com) (74.125.46.155) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 18 Nov 2008 20:53:44 +0000 Received: by yw-out-1718.google.com with SMTP id 6so2224488ywa.88 for ; Tue, 18 Nov 2008 12:54:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:message-id:date:from:to :subject:in-reply-to:mime-version:content-type :content-transfer-encoding:content-disposition:references; bh=Jy0CP6Tv+MMsBT0DyFyTSm8OSAK2k9on3z0mj9xOHVo=; b=vAwxBOR+m6ohDfw9ErnkSNk5QmAVW7vWakbW5MlApRLVqqGW9Msn0JoaXviy1tETlB nwG7GAXVXpo+sgk1/cVYQwm5x9W199tB5bnOvgolopcfo8mFXRwEwXWeMhuRfCyBvCRC CqfJcoLeIbdnHj2vfSAsB7rdeZZo91DBB+b0M= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:to:subject:in-reply-to:mime-version :content-type:content-transfer-encoding:content-disposition :references; b=VS75j1cbboLdQPeIvZyDwWmVJwT5R4a5rnYfAl1YklTaa+7T/xHqGzN8pOhuzpohE1 T+SU4mX7Ljqpc2c3G94YMGTl/bAST8dRzAybhRPW7EP/zzNgrTW6Lb22zP01ehY3vBtS ojzz2JLPelquiaQgzngb0+uPyqkL6ZhKDEaYE= Received: by 10.142.177.5 with SMTP id z5mr131327wfe.40.1227041658006; Tue, 18 Nov 2008 12:54:18 -0800 (PST) Received: by 10.142.232.19 with HTTP; Tue, 18 Nov 2008 12:54:17 -0800 (PST) Message-ID: <529247150811181254u7aa8f992hf58982f834d9285d@mail.gmail.com> Date: Tue, 18 Nov 2008 15:54:17 -0500 From: "Simon Wilkinson" To: "HttpClient User Discussion" Subject: Re: Unexpected failure: HTTP/1.1 400 Bad Request at the end of every PUT using Expect-Continue = true In-Reply-To: <1227015170.8955.24.camel@ubuntu> MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline References: <529247150811171107r1c940c42o73393bc1a78b3b0a@mail.gmail.com> <1227015170.8955.24.camel@ubuntu> X-Virus-Checked: Checked by ClamAV on apache.org 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 : > 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