hc-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Oleg Kalnichevski <o.kalnichev...@dplanet.ch>
Subject Re: Put -method blocks
Date Sat, 01 Feb 2003 12:10:43 GMT
Maneesh, Chris

We have just finished a significant revamp of PutMethod & PostMethods.
Both methods have been made to be able to handle those cases when flaky
HTTP servers and proxies  fail to send status code 100 when expected.
HttpClient should resume sending request body after 3 second timeout if
"100 continue" is not received. 

I can't say I have thoroughly tested how robust HttpClient is in handing
this kind of situations. That's why I am kindly asking you to get hold
of the most recent snapshot of HttpClient and take it for a spin in your
environment. Please apply the following system properties, so you could
keep track of what is going on

-Dorg.apache.commons.logging.Log=org.apache.commons.logging.impl.SimpleLog
-Dorg.apache.commons.logging.simplelog.log.httpclient.wire=debug 
-Dorg.apache.commons.logging.simplelog.log.org.apache.commons.httpclient=debug

If you get the following lines in the debug trace, then everything is
cool

[DEBUG] HttpConnection - -Waiting for response timeout
[DEBUG] HttpMethod - -Response not available. Send the request body 

If on the contrary problem persists, or there's anything that you find
fishy, please send me the complete debug trace for analysis

Cheers

Oleg


On Wed, 2003-01-29 at 13:34, Chris Smith wrote:
> 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
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-httpclient-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-httpclient-dev-help@jakarta.apache.org
-- 
Oleg Kalnichevski <o.kalnichevski@dplanet.ch>


Mime
View raw message