You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by Sanjeev Tripathi <sa...@parago.com> on 2005/02/07 22:40:11 UTC

[httpclient]RE: Spam: RE: Http Client- How to send and recieve Serialized Object using Http Client

Can you please send me link for base 64 encode/decode examples in java.

-----Original Message-----
From: Sharples, Colin [mailto:Colin.sharples@contact-energy.co.nz] 
Sent: Monday, February 07, 2005 2:57 PM
To: Jakarta Commons Developers List
Subject: Spam: RE: Http Client- How to send and recieve Serialized
Object using Http Client

Assuming it's not just because of the typo in the content type (should
be "application/octet-stream"), you could try base 64 encoding the
object output stream, and then you can just use text/plain content type.
On the other end you base 64 decode the response body before passing it
to the object input stream. There are plenty of examples of how to do
base 64 encode/decode on the web.

Colin Sharples
IBM Advisory IT Specialist
Email: sharples@nz.ibm.com


> -----Original Message-----
> From: Sanjeev Tripathi [mailto:sanjeev.tripathi@parago.com]
> Sent: Tuesday, 8 February 2005 8:18 a.m.
> To: commons-dev@jakarta.apache.org
> Subject: Http Client- How to send and recieve Serialized Object using
> Http Client
> 
> 
> Hi,
> 
>  
> 
> I am working on thick client proxy that will connect to servlet and
> retrive and save data to database. I am using Http Client for
> communication.
> 
>  
> 
>  I am able to send string values using parameter in request 
> as follows. 
> 
>  
> 
> //************************************************************
> **********
> ****
> 
>         NameValuePair userid   = new NameValuePair("LOGIN_NAME",
> "login");
> 
>         NameValuePair password = new NameValuePair("LOGIN_PASSWORD",
> "password");
> 
>         NameValuePair thickClient = new NameValuePair("ThickClient",
> "ThickClient");
> 
>  
> 
>         authpost.setRequestBody(
> 
>           new NameValuePair[] {action, url, userid,
> password,thickClient});
> 
>  
> 
> //************************************************************
> **********
> ****
> 
>  
> 
> I am able to send xml string as parameter and able to receive it back
> from response as String.
> 
>  
> 
>  But I am getting problem in serialized user defined objects
> communication. Following is not working
> 
>  
> 
>  
> 
>  
> 
> //*************************In Servlet*****************
> 
>  
> 
> if (request.getParameter("ThickClient").equals("ThickClient"))  {
> 
>  
> 
>  
> 
>    response.setContentType("application/octel-stream");
> 
>    ObjectOutputStream oos = new
> ObjectOutputStream(response.getOutputStream());
> 
>    oos.writeObject(new 
> com.parago.communication.SubmissionVO(1,"Controll
> Servlet"));
> 
>  
> 
>    oos.flush();
> 
>    oos.close();
> 
>    return;
> 
> }
> 
>  
> 
>  
> 
>  
> 
>  
> 
> ******************** In Thick Client Proxy *************************
> 
>  
> 
>  
> 
>  
> 
>         client.executeMethod(authpost);      
> 
>  
> 
>         System.out.println("Login form post: " +
> authpost.getStatusCode());
> 
>          ObjectInputStream ois = new
> ObjectInputStream(authpost.getResponseBodyAsStream());
> 
>         SubmissionVO vo = (SubmissionVO)ois.readObject();
> 
>         System.out.println("id :" +vo.getSubmissionId() +": desc:" +
> vo.getDescription());
> 
>  
> 
>  
> 
>  
> 
> //******************Here SubmissionVO is Serialized Object***********
> 
>  
> 
> public class SubmissionVO implements java.io.Serializable{
> 
>     public SubmissionVO(int id,String desc) {
> 
>         this.submissionId = id;
> 
>         this.description = desc;
> 
>     }
> 
>     private int submissionId;
> 
>     private String description;
> 
>  
> 
>     public int getSubmissionId () {
> 
>         return submissionId;
> 
>     }
> 
>     public String getDescription() {
> 
>         return description;
> 
>     }
> 
> }
> 
> //***********************************************************
> 
>  
> 
>  
> 
>  
> 
>  
> 
> Please suggest me. How to send and receive Serialized User 
> Defined Value
> Objects in using Http Client.
> 
>  
> 
>  
> 
>  
> 
> Thanks.
> 
>  
> 
> Sanjeev Tripathi
> 
>  
> 
>  
> 
>  
> 
>  
> 
>  
> 
> 
> ______________________________________________________________________
> This email has been scanned by the MessageLabs Email Security System.
> For more information please visit http://www.messagelabs.com/email 
> ______________________________________________________________________
> 

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


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