hc-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Nick Jarvis" <jarvisnicho...@hotmail.com>
Subject Re: HTTP Version Not Supported Error
Date Fri, 15 Oct 2004 17:41:04 GMT
Hi Roland,

I don't understand why I am not able to synchronize the post method 
considering that I am simply subclassing the PostMethod.  What I have done 
is simply copy the EntityEnclosingMethod's writeRequestBody function in my 
new class first to see if it would work similarly like the post method does. 
  This will not work for me and returns the HTTP Version Not Supported 
function when the connection manager is done blocking after the max 
connections per host is reached.  So to reiterate, if my max connections per 
host for my MultiThreadedHttpConnectionManager is set to 2, and the max 
total connections is default at 20, and I am trying to upload say 6 files at 
the same time.  The first two will work succesfully blocking the rest of the 
threads.  When one becomes available, the third file is giving me the server 
error of HTTP Version Not Supported.  The fourth file will upload correctly 
when the thread is unblocked.  Then the fifth will return the same HTTP 
Verson Not Supported error and the sixth will work.  Here is the code for my 
subclass.  Below this class is how I would be using it in a thread run() 

public class UploadMethod extends PostMethod {

    protected boolean writeRequestBody(HttpState state, HttpConnection conn)
        throws IOException, HttpException {

        if (!super.hasRequestContent()) {
            return true;

        int contentLength = super.getRequestContentLength();

        InputStream instream = null;
        if (this.requestStream != null) {
            instream = super.getRequestBodyAsStream();

        if (instream == null) {
            return true;

        OutputStream outstream = conn.getRequestOutputStream();

        if (contentLength >= 0) {
            // don't need a watcher here - we're reading from something 
            // not server-side.
            instream = new ContentLengthInputStream(instream, 

        byte[] tmp = new byte[4096];
        int total = 0;
        int i = 0;
        while ((i = instream.read(tmp)) >= 0) {
            outstream.write(tmp, 0, i);
            total += i;

        if ((contentLength > 0) && (total < contentLength)) {
            throw new IOException("Unexpected end of input stream after "
                + total + " bytes (expected " + contentLength + " bytes)");

        return true;

This is how I would be using this class in a thread:

File file = new File(filePath);

UploadMethod method = new UploadMethod(ServletAddress);


method.setRequestHeader("Content-type", "application/octet-stream");

method.setRequestBodyAsStream(new FileInputStream(file));

int status = client.execute(method);

Thanks agiain,


>From: Roland Weber <ROLWEBER@de.ibm.com>
>Reply-To: "Commons HttpClient Project" 
>To: "Commons HttpClient Project" 
>Subject: Re: HTTP Version Not Supported Error
>Date: Fri, 15 Oct 2004 09:19:23 +0200
>Hello Nick,
>by implementing ...methods.multipart.PartSource, you can supply your
>own InputStream. Using HttpMethod.getResponseBodyAsStream(),
>you have direct access to the input stream of the response. What more
>control do you need?
>The problem you report suggests that your version of the post method
>somehow fails to synchronize the connection usage. But that is hard to
>diagnose if you don't send the modified source.
>   Roland
>"Nick Jarvis" <jarvisnicholas@hotmail.com>
>14.10.2004 20:13
>Please respond to
>"Commons HttpClient Project"
>HTTP Version Not Supported Error
>I am currently using HttpClient 2.0.2 and trying to create a multi
>file upload.  I have restrictions on the project I can use , therefore I
>using HttpClient MultiThreadedHttpConnectionManager that is connecting to
>the same host and I am using HttpClient PostMethod for the upload.  I am
>trying to use the PostMethod as a subclass and overide the
>function to have more control over the upload.  However, I am getting and
>error reading: 'HTTP Version Not Supported' from the status text for the
>third thread (for the third file that I am trying to upload after the
>previoius two are complete).  The response from the server is not pretty
>either.  I even tried copying the same exact source from the PostMetho
>into a new class but I am still getting this error when running the
>I am noticing that the MultiThreadedHttpConnectionManager defaults to 2
>connections per host, and the manager seems to be blocking my third thread
>until one of the other two complete.  Once one thread is complete and
>unblocks the next thread, I am unable to upload the next file due to this
>server error.  If I increase the connections per host variable, the upload
>after the connections per host limit is returning this message.    If I
>use the PostMethod or MultipartPostMethod, the uploads work fine, but I
>more control over the input stream and the upload.  Could someone please
>advise.  Thank you for your time,
>Nick Jarvis
>Express yourself instantly with MSN Messenger! Download today - it's FREE!
>To unsubscribe, e-mail:
>For additional commands, e-mail:

Get ready for school! Find articles, homework help and more in the Back to 
School Guide! http://special.msn.com/network/04backtoschool.armx

To unsubscribe, e-mail: commons-httpclient-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-httpclient-dev-help@jakarta.apache.org

View raw message