commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Sanjeev Tripathi" <sanjeev.tripa...@parago.com>
Subject [httpclient]- How to send and recieve Serialized Object using Http Client
Date Mon, 07 Feb 2005 21:11:42 GMT

Is there Any way I can retrieve object that I set in servlet using
request.setAttruibute("name", object);

And vise versa can I send from Client Side to servlet similar way as we
send 
Other string parameter as follows

PostMethod authpost = new PostMethod("/argo/XmzServlet");
NameValuePair action   = new NameValuePair("action", "login");
NameValuePair url      = new NameValuePair("url", "argo/index.html");
NameValuePair userid   = new NameValuePair("LOGIN_NAME", "login");
NameValuePair password = new NameValuePair("LOGIN_PASSWORD", "passwd");
NameValuePair thickClient = new NameValuePair("ThickClient",
"ThickClient");
authpost.setRequestBody(
          new NameValuePair[] {action, url, userid,
password,thickClient});

thanks.






-----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


Mime
View raw message