• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

XML over HTTP?

 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Desperado
Posts: 3226
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Sheriff
Posts: 7001
6
Eclipse IDE Python C++ Debian Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
reply
    Bookmark Topic Watch Topic
  • New Topic