Connecting Tech Pros Worldwide Help | Site Map

how is java object ent over http post in xml ??

Newbie
 
Join Date: Aug 2009
Posts: 8
#1: Aug 26 '09
Hi,
I'm trying to 'POST' http request to my local server... upto now i have had success sending only 'text' string in the message body.
I now would like to try out sending java objects. And I understand, xml is the best wy to go about it...
I have learnt that using xsd (xml schema defination) one can instantiate xml file and then post it to the server...
I would like to know how I can use xsd to instantiate xml ...
I have used a sample xml to generate xsd, using visual studio xsd.exe...
hsriat's Avatar
Expert
 
Join Date: Jan 2008
Location: Bath, UK
Posts: 1,609
#2: Aug 31 '09

re: how is java object ent over http post in xml ??


I can think of a simple solution. And that is make methods in all classes something like toString, toXML which return XML like
Expand|Select|Wrap|Line Numbers
  1. <object class="className">
  2.     <variable name="" value="" />
  3. </object>
And then finally pack the all object XMLs in a root tag before transferring it.
hsriat's Avatar
Expert
 
Join Date: Jan 2008
Location: Bath, UK
Posts: 1,609
#3: Aug 31 '09

re: how is java object ent over http post in xml ??


Wait... if you are using HTTP POST, then there's no need to converting it to XML.
Just convert all the objects into MAPs (or SETs of MAPs) and then convert these MAPs or SETs to URI encoded string.
You can though convert it to XML on the receiving end.
JosAH's Avatar
Expert
 
Join Date: Mar 2007
Posts: 10,611
#4: Aug 31 '09

re: how is java object ent over http post in xml ??


... also read about the XMLEncoder and the XMLDecoder classes.

kind regards,

Jos
Reply