hc-httpclient-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Michael Becke <be...@u.washington.edu>
Subject Re: writing serialized objects to servlets
Date Tue, 07 Dec 2004 03:09:45 GMT
Hi Gregg,

> In the httpclient package, the only way to access an OutputStream that 
> I
> have found is in the class HttpConnection. But I am unable to figure 
> out how
> to create an HttpConnection with the path to my servlet. It only seems 
> to
> have constructors for setting host, port, protocol, etc, but not the 
> path to
> the actual servlet ("/myservlet"). Is there a way to create an
> HttpConnection with a path beyond the host?

In HttpClient 2.0 there is no built-in way to direcly write to the 
output stream.  You can accomplish what you are looking for by writing 
the object to a byte array and then using that for the post method.  
Something like:

ByteArrayOutputStream bos = new ByteArrayOutputStream();
ObjectOutputStream out = new ObjectOutputStream(bos);
out.writeObject(anObject);

PostMethod post = new PostMethod();
post.setRequestBody(new ByteArrayInputStream(bos.toByteArray()));


In HttpClient 3.0 things are much cleaner.  You can write directly to 
the output stream by implementing a RequestEntity and setting it on the 
PostMethod.

> Basically, I'm new to this package, and I would like to know if it 
> will help
> me accomplish what the code snippet above accomplishes (only without 
> so many
> failures). Also, will it help with my timeout problem? Any advice at 
> all is
> much appreciated.

Please have a look at the tutorial 
<http://jakarta.apache.org/commons/httpclient/3.0/tutorial.html> for 
more examples of how to use HttpClient.

You can set a variety of timeouts in HttpClient 3.0.  The Preferences 
Architecture documentation 
<http://jakarta.apache.org/commons/httpclient/3.0/preference-api.html> 
discusses the various timeout settings.

Mike


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


Mime
View raw message