hc-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Roland Weber <ROLWE...@de.ibm.com>
Subject Re: HTTP Version Not Supported Error
Date Mon, 18 Oct 2004 15:00:30 GMT
Hi Nick,

I didn't try this out, but here are a few suggestions:

a) HttpClient already implements chunked encoding in
both directions. Have a look at the classes, maybe you
can use them on the server side as well.

b) Don't call setContentLength, or set it to -1 in a
FilePart object. This should work fine with HTTP/1.1
and chunked encoding, but also with HTTP/1.0 and
no chunked encoding. Since the server does not know
the content length in advance, it has to read until the
end of the stream in no-chunks mode. Connection
re-use is impossible, but after transferring more than
2 gigs I doubt you'll notice the performance impact
of opening a new connection :-)
It might be a violation of HTTP to POST data without
a valid content length, but since you're controlling
the server as well, that shouldn't bother you much.

hope that helps,
  Roland





"Nick Jarvis" <jarvisnicholas@hotmail.com> 
18.10.2004 16:06
Please respond to
"Commons HttpClient Project"


To
commons-httpclient-dev@jakarta.apache.org
cc

Subject
Re: HTTP Version Not Supported Error






Roland,
Thanks, I am writing my own server doGet and doPost methods using 
HttpServlet, but for some reason the servlet must be defaulting to 
HTTP/1.0. 
  Therefore I changed my subclass code with the setHttp11 method and the 
connections seem to be closing after each upload and is not giving me the 
problem.  One of the main reasons why I wanted control for the upload was 
to 
figure out a way to upload files larger than 2 gigs.  I understand that 
chunked encoding is a possibility, but I am writing my own server code and 

would rather not implement this on the server side.  Is there a way I can 
upload files larger than 2 gigs using HttpClient?  I am also writing file 
download code and I simply open up a stream in the doGet method and write 
out the bytes to the stream from the server.  On the client side it is 
easy 
to get the stream and read in all the bytes, and I am able to download 
very 
large files.  I want to be able to do this uploading files, but the set 
content length function only allows 2 gigs.  Is there a limit on the 
stream 
to only be 2 gigs?  How could I upload files larger than 2 gigs besides 
using chunked encoding?  Thanks for your help,

Nick

>From: Roland Weber <ROLWEBER@de.ibm.com>
>Reply-To: "Commons HttpClient Project" 
><commons-httpclient-dev@jakarta.apache.org>
>To: "Commons HttpClient Project" 
><commons-httpclient-dev@jakarta.apache.org>
>Subject: Re: HTTP Version Not Supported Error
>Date: Mon, 18 Oct 2004 08:48:37 +0200
>
>Hello Nick,
>
>this description sounds more like a problem with connection re-use
>than connection management. You can try to send "connection: close"
>headers with each POST request, so the HTTP client does not try
>to re-use connections. If that doesn't help, try to force HTTP client
>back to the HTTP/1.0 protocol, which disables connection re-use
>completely.
>I agree with Oleg's guess that it is a server problem. The server
>probably indicates HTTP/1.1 support, but does not implement
>connection re-use for POSt requests. So when HTTP client relies
>on this feature, the server fails.
>
>cheers,
>   Roland
>
>
>
>
>
>"Nick Jarvis" <jarvisnicholas@hotmail.com>
>15.10.2004 19:41
>Please respond to
>"Commons HttpClient Project"
>
>
>To
>commons-httpclient-dev@jakarta.apache.org
>cc
>
>Subject
>Re: HTTP Version Not Supported Error
>
>
>
>
>
>
>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()
>function.
>
>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
>local,
>             // not server-side.
>             instream = new ContentLengthInputStream(instream,
>contentLength);
>         }
>
>         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.setRequestConentLength(file.length);
>
>method.setRequestHeader("Content-type", "application/octet-stream");
>
>method.setRequestBodyAsStream(new FileInputStream(file));
>
>int status = client.execute(method);
>
>
>
>Thanks agiain,
>
>Nick
>
>
> >From: Roland Weber <ROLWEBER@de.ibm.com>
> >Reply-To: "Commons HttpClient Project"
> ><commons-httpclient-dev@jakarta.apache.org>
> >To: "Commons HttpClient Project"
> ><commons-httpclient-dev@jakarta.apache.org>
> >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.
> >
> >cheers,
> >   Roland
> >
> >
> >
> >
> >
> >"Nick Jarvis" <jarvisnicholas@hotmail.com>
> >14.10.2004 20:13
> >Please respond to
> >"Commons HttpClient Project"
> >
> >
> >To
> >commons-httpclient-dev@jakarta.apache.org
> >cc
> >
> >Subject
> >HTTP Version Not Supported Error
> >
> >
> >
> >
> >
> >
> >I am currently using HttpClient 2.0.2 and trying to create a multi
> >threaded
> >file upload.  I have restrictions on the project I can use , therefore 
I
> >am
> >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
> >WriteRequestBody
> >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
> >class
> >into a new class but I am still getting this error when running the
> >method.
> >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
> >just
> >use the PostMethod or MultipartPostMethod, the uploads work fine, but I
> >need
> >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!
> >
> >hthttp://messenger.msn.click-url.com/go/onm00200471ave/direct/01/
> >
> >
> >---------------------------------------------------------------------
> >To unsubscribe, e-mail:
> >commons-httpclient-dev-unsubscribe@jakarta.apache.org
> >For additional commands, e-mail:
> >commons-httpclient-dev-help@jakarta.apache.org
> >
> >
>
>_________________________________________________________________
>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
>
>

_________________________________________________________________
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



Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message