commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From carlos1.riv...@ps.ge.com
Subject RE: How to send a serializable object as the request body
Date Thu, 16 Oct 2003 20:36:33 GMT
Great, thanks a lot.  Now we have anothor problem with the API.  We
currently have the capability to cancel a connection in progress by doing
the following:

	 	if ( logonConnection != null )
            {
                logonConnection.close(); // this is an URLConnection object
            }

            if (logonInputStream != null)
            {
                logonInputStream.close();
            }

            if (logonOutputStream != null)
            {
                logonOutputStream.close();
            }

it would be very nice if the API had the capability of retriving the current
HttpConnection object from HttpClient object (the one given by the
MultiThreadedHttpConnectionManager) or the connection that will be used to
execute the PostMethod...

-----Original Message-----
From: Michael Becke [mailto:becke@u.washington.edu]
Sent: Wednesday, October 15, 2003 11:31 PM
To: Jakarta Commons Users List
Subject: Re: How to send a serializable object as the request body


Sure, it would look something like the following:

         HttpClient client = new HttpClient();
         PostMethod post = new PostMethod(url);

         // buffer object to byte array
         ByteArrayOutputStream bos = new ByteArrayOutputStream();
         ObjectOutputStream oos = new ObjectOutputStream(bos);
         oos.writeObject(object);

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

         try {
             client.executeMethod(post);
             ObjectInputStream in = new 
ObjectInputStream(post.getResponseBodyAsStream());
             Object result = in.readObject();
         } finally {
             post.releaseConnection();
         }


Mike


On Wednesday, October 15, 2003, at 11:02 PM, carlos1.rivera@ps.ge.com 
wrote:

>
> We are in the process of replacing the URLConnection class with 
> HttpClient.
> Currently we send serialized objects to a servlet with something 
> similar to
> the following code snippet:
>
> 	URL url = URL(hostURL.getProtocol(),
>                                  hostURL.getHost(),
>                                  hostURL.getPort(),
>                                  "/servlet/TestServlet");
> 	URLConnection httpURLConnection = url.openConnection();
> 	out = new
> ObjectOutputStream(httpURLConnection.getRequestOutputStream());
>
> 	out.writeObject(serializedObject);
>
>            out.flush();
> 	out.close()
>
> 	-------------------------- (Meanwhile in the server)
>
> 	The servlet reads the serializedObject from the InputStream of the
> HttpServletRequest parameter and sends the response in the
> 	HttpServletResponse
>
> 	---------------------------(Back in the client)
> 	
> 	  in = new ObjectInputStream(
> httpURLConnection.getResponseInputStream() );
> 	 result = in.readObject();
> 	in.close();
>
> I have tried to accomplish the same technique with HttpClient, but I 
> have
> been unsuccessful.  Is this possible with this library?
>
> Thank You
> Carlos R.
>  	
>
>
> Carlos Javier Rivera Vazquez
> Staff Engineer
> GE Power Systems
> Network Reliability Services
> __________________________________________________
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-user-help@jakarta.apache.org
>


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

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


Mime
View raw message