Return-Path: Mailing-List: contact commons-httpclient-dev-help@jakarta.apache.org; run by ezmlm Delivered-To: mailing list commons-httpclient-dev@jakarta.apache.org Received: (qmail 30534 invoked from network); 29 Jan 2003 12:34:51 -0000 Received: from unknown (HELO mta1.adelphia.net) (64.8.50.175) by daedalus.apache.org with SMTP; 29 Jan 2003 12:34:51 -0000 Received: from KYA ([68.71.53.6]) by mta1.adelphia.net (InterMail vM.5.01.05.25 201-253-122-126-125-20021216) with SMTP id <20030129123524.XLCG7272.mta1.adelphia.net@KYA>; Wed, 29 Jan 2003 07:35:24 -0500 Message-ID: <030f01c2c792$cd38a770$6700000a@KYA> From: "Chris Smith" To: "Commons HttpClient Project" , References: <0AC2D75550100F4DBDB025D4D0561188770411@BIGCOW.intraephox.ephox.com> <3E377B63.5070602@sun.com> Subject: Re: Put -method blocks Date: Wed, 29 Jan 2003 05:34:43 -0700 MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 6.00.2720.3000 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2600.0000 X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N Maneesh, This looks suspiciously like the same problem I had... that the proxy is not returning the 100 response that HttpClient desires. The HTTP RFC strongly suggests that clients don't wait forever for this response, but HttpClient does wait, at least until it times out (in my case, IIRC, that took about 10 minutes) and fails claiming an invalid response. My solution was: package com.mindiq.mindiqweb.devlite.upload; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.File; import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.net.URL; import org.apache.commons.httpclient.ChunkedOutputStream; import org.apache.commons.httpclient.HttpConnection; import org.apache.commons.httpclient.HttpException; import org.apache.commons.httpclient.HttpState; import org.apache.commons.httpclient.methods.PutMethod; public class SimplePutMethod extends PutMethod { private File file = null; private byte[] data = null; private URL url = null; public SimplePutMethod() { super(); } public SimplePutMethod(String path) { super(path); } public void setRequestBody(byte[] arg0) { super.setRequestBody(arg0); this.data = arg0; } public void setRequestBody(File arg0) throws IOException { super.setRequestBody(arg0); this.file = arg0; } public void setRequestBody(InputStream arg0) throws IOException { byte[] buffer = new byte[4096]; ByteArrayOutputStream os = new ByteArrayOutputStream(); int nb = 0; while (true) { nb = arg0.read(buffer); if (nb == -1) { break; } os.write(buffer, 0, nb); } setRequestBody(os.toByteArray()); } public void setRequestBody(String arg0) { super.setRequestBody(arg0); } public void setRequestBody(URL arg0) throws IOException { super.setRequestBody(arg0); this.url = arg0; } protected void addRequestHeaders(HttpState arg0, HttpConnection arg1) throws IOException, HttpException { super.addRequestHeaders(arg0, arg1); /* * Don't expect a 100-continue. This has the side-effect of * clobbering other expectations, which is suitable for our * purposes. */ if (getRequestHeader("expect") != null) { removeRequestHeader("expect"); } } protected boolean writeRequestBody(HttpState state, HttpConnection conn) throws IOException, HttpException { OutputStream out = conn.getRequestOutputStream(); if (isHttp11() && (null == getRequestHeader("Content-Length"))) { out = new ChunkedOutputStream(out); } InputStream inputStream = null; if (file != null && file.exists()) { inputStream = new FileInputStream(file); } else if (url != null) { inputStream = url.openConnection().getInputStream(); } else if (data != null) { inputStream = new ByteArrayInputStream(data); } else { return true; } byte[] buffer = new byte[4096]; int nb = 0; while (true) { nb = inputStream.read(buffer); if (nb == -1) { break; } out.write(buffer, 0, nb); } out.flush(); return true; } } -- www.designacourse.com The Easiest Way to Train Anyone... Anywhere. Chris Smith - Lead Software Developer/Technical Trainer MindIQ Corporation