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 20:17:58 UTC
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