chaitu chaitu
asked on
can i send the java value object from url to one url
can I send the java value object from url to one url.can any body some links or examples?
i need to send this object from one context to another context that are deployed in different servers.
i need to send this object from one context to another context that are deployed in different servers.
ASKER
// Construct data
String data = URLEncoder.encode("name", "UTF-8") + "=" + URLEncoder.encode(roger, "UTF-8");
data += "&" + URLEncoder.encode("dob", "UTF-8") + "=" + URLEncoder.encode(05/20/11 , "UTF-8");
do we need to send like key-value pairs like above..
String data = URLEncoder.encode("name", "UTF-8") + "=" + URLEncoder.encode(roger, "UTF-8");
data += "&" + URLEncoder.encode("dob", "UTF-8") + "=" + URLEncoder.encode(05/20/11
do we need to send like key-value pairs like above..
serialize the object somehow and POST it to the other server
> do we need to send like key-value pairs like above..
thats a GET request and you can do that also, sending the properties required to recreate object at other end
thats a GET request and you can do that also, sending the properties required to recreate object at other end
>>do we need to send like key-value pairs like above..
You don't need to, but you could, e.g.
You don't need to, but you could, e.g.
data += "&" + URLEncoder.encode("object", "UTF-8") + "=" + URLEncoder.encode(base64EncodedObjectString, "UTF-8");
ASKER
// Construct data using post
String data = URLEncoder.encode("key1", "UTF-8") + "=" + URLEncoder.encode("value1" , "UTF-8");
data += "&" + URLEncoder.encode("key2", "UTF-8") + "=" + URLEncoder.encode("value2" , "UTF-8");
// Construct data using get
String queryString = "param1=" +
URLEncoder.encode(param1Va lue, "UTF-8");
queryString += "¶m2=" +
URLEncoder.encode(param2Va lue, "UTF-8");
Difference i found between get and post is in post also u use URLEncoder.encode for key value.am i right?
objects,
few days back i asked you about sending object from context(http://localhost:8080/dept) to another context(http://localhost:8080/emp) if both are deployed in the same server.
at that time you said you cannot send object if both are deployed in the same server,need to send only request parameters like apending parameters to query string.
for that requirement also can't we use this solution?
String data = URLEncoder.encode("key1", "UTF-8") + "=" + URLEncoder.encode("value1"
data += "&" + URLEncoder.encode("key2", "UTF-8") + "=" + URLEncoder.encode("value2"
// Construct data using get
String queryString = "param1=" +
URLEncoder.encode(param1Va
queryString += "¶m2=" +
URLEncoder.encode(param2Va
Difference i found between get and post is in post also u use URLEncoder.encode for key value.am i right?
objects,
few days back i asked you about sending object from context(http://localhost:8080/dept) to another context(http://localhost:8080/emp) if both are deployed in the same server.
at that time you said you cannot send object if both are deployed in the same server,need to send only request parameters like apending parameters to query string.
for that requirement also can't we use this solution?
ASKER
"data += "&" + URLEncoder.encode("object" , "UTF-8") + "=" + URLEncoder.encode(base64En codedObjec tString, "UTF-8"); "
how this base64EncodedObjectString will be contructed??
how this base64EncodedObjectString will be contructed??
> for that requirement also can't we use this solution?
yes, thats what I was suggesting in the other q :)
> how this base64EncodedObjectString will be contructed??
not a good idea, better to serialize your object (eg. as xml, or json) and use a POST request
yes, thats what I was suggesting in the other q :)
> how this base64EncodedObjectString will be contructed??
not a good idea, better to serialize your object (eg. as xml, or json) and use a POST request
You can also use sun.misc.BASE64Encoder in the JDK, but it's deprecated
ASKER
object,
just for my confirmation we can use this solution for that requirement as well.
just for my confirmation we can use this solution for that requirement as well.
The easiest way is to use a servlet at the receiving end - then you can use ObjectInputStream directly
> just for my confirmation we can use this solution for that requirement as well.
yes
yes
ASKER
let me try with XML and use a POST request ..
You can bundle the object and send it as a JSON object too
ASKER
jinujinesh:
can you post some pseudo code on send it as a JSON object too ??
can you post some pseudo code on send it as a JSON object too ??
As i mentioned earlier its the same as snding xml. You just need to serialize your object (as json) and pass the json data in your POST request
ASKER
in this case also do i need to use URLConnection ??
can you provide on how serialize your object (as json) ??
can you provide on how serialize your object (as json) ??
you can use URLConnection to send POST request
have a look at flexjon for serialization
http://flexjson.sourceforge.net/
have a look at flexjon for serialization
http://flexjson.sourceforge.net/
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I have written ClientServlet to send the data from client to server.
Whenever it connects this url(http://localhost:8080/DEPT/server) i have called one filter at the server side where it will read the response and put it in an
object and set in request scope.object is printing in fine in filter.
apart from pushing the data need to redirect to the application page by calling spring action class.so i mentioned that url in ClientServlet.
but in the spring action class object is coming as null from request object.
Whenever it connects this url(http://localhost:8080/DEPT/server) i have called one filter at the server side where it will read the response and put it in an
object and set in request scope.object is printing in fine in filter.
apart from pushing the data need to redirect to the application page by calling spring action class.so i mentioned that url in ClientServlet.
but in the spring action class object is coming as null from request object.
ClientServlet
*************
public void doPost(HttpServletRequest request, HttpServletResponse response)
{
HttpCon con=null;
String xmldata=null;
try {
System.out.println(".......ClientLoginAction..in AppContext.........");
String strURL = "http://localhost:8080/DEPT/server";
String paramName[]={"userName","password"};
String paramVal[]={"admin","admin"};
String datas=HttpCon.httpPost(strURL, paramName, paramVal);
System.out.println("datas...."+datas);
System.out.println("strURL..."+strURL);
response.sendRedirect("http://localhost:8080/DEPT/app?_flowId=app-flow").forward(request, response);
} catch (Exception e) {
System.out.println("Getting Exception" + e);
}
Filter
**************
public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain)
throws IOException, ServletException, NoSuchFlowExecutionException {
HttpServletRequest request = (HttpServletRequest) servletRequest;
Bean bean new Bean();
//reading response that client sent
Enumeration enumeration = request.getParameterNames();
while (enumeration.hasMoreElements()) {
String parameterName = (String) enumeration.nextElement();
if(parameterName.equals("firstname")
bean.setFirstName(request.getParameter(parameterName));
if(parameterName.equals("LastName")
bean.setLastName(request.getParameter(parameterName));
}
//put the object in request scope
System.out.println(bean+"******************request**** server context*********"+request);
request.setAttribute("bean", bean);
}
//Spring web flow action class
*********************************
public class DeptAction
{
public Event initialize(RequestContext context) {
if (context != null) {
ServletExternalContext servletContext = (ServletExternalContext) context.getExternalContext();
if (servletContext != null) {
request = servletContext.getRequest();
response = servletContext.getResponse();
}
}
Bean bean = (Bean)request.getAttribute("bean");
System.out.println(bean+"******************request**** server context*********"+request);
}
}
ASKER
this solution looks easy compared to the solutions offered by experts.
http://www.exampledepot.com/egs/java.net/Post.html