Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

XML over HTTP?

 
Joshua Lam
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What is the best way to send XML over HTTP? ie do we send it as a name/value pair? (ie the value being the whole XML doc?)
Thanks.
--
Josh
 
Tony Alicea
Desperado
Sheriff
Posts: 3226
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't understand the question but I think theres a MIME type text/xml. I don't see why it has to be treated differently. For example, a GET is a GET is a GET.
Or maybe I don't understand the question...
 
Joshua Lam
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry to be vague. Ok, let me try again:
What is the best way for a Java client use HTTP to POST an XML document to a Java http servlet? Should the Java client send the XML document as a whole document or as a name/value pair?
If it is sent as a name value/pair eg 'xmldoc=<the xml doc>' then the http servlet can retrieve the document by using getParameter("xmldoc") which return the content xml document.
Is this an efficient way? What are other ways? Are there XML/Http libraries out there that does this?
--
Josh
 
Edward Man
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
One of the popular free XML parsers is IBM's XML for Java (XML4J). It supports both DOM and SAX. You can use it with servlet. You can get it here. http://www.alphaworks.ibm.com/formula/xml
My suggestion is to send the XML document (with DTD perhaps?) to the servlet and let the servlet parse the XML document and retrieve the data.
 
Frank Carver
Sheriff
Posts: 6920
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It depends if you intend to send any other data along with the XML. If your client/browser also needs to send cookies, hidden form fields, etc. etc. then you may need to use the name=value method. This is a "safe" approach, but can be considerably less efficient than sending "raw" XML over the HTML stream.
Using name=value in a GET request is risky because some servers, proxies, firewalls etc. might restrict or truncate the length of a GET request, so it's inappropriate for flexible data format like XML.
Using name=value in a POST request incurs the penalty of URL-escaping the data at the client and unescaping it at the server, even though XML has its own processes for that.
The most efficient method is to send the XML as the only data over the stream and have a custom servlet to read the input. You may also want to use some form of "content-length" to simplify reading the data at the server end.
Conceptually XML should be an alternative HTML request format, understood by servers and clients so you could say something like
<form action=/myapp/servlet/something method=XML>
blah ...
</form>
but until that becomes popular, you have to roll your own.
 
Swapan Mazumdar
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

I need to implement xml over http to send request as xml to a payment gateway i.e https://www.payment.server/pay.asp and process the response coming as xml back to the client.

Does Apache XML-RPC is an answer to this?
Please share any other java implementation technologies suitable for this requirement and tried and tested.

best rgrds
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic