• Post Reply Bookmark Topic Watch Topic
  • New Topic

RESTful client or HTTP client with DOM

 
Nick Sher
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I use apache HTTP client to read the xml from a RESTful service and then parse it using DOM, SAX or JAXB. I don't have all schema files to generate java objects. SAX is used in few places. DOM is used mostly to read/write xml, but its is difficult to maintain as I have to write a parser for every document that is read. Is this a correct way to consume REST service? Do I really need to move to Jersey or Restlet in this case?
 
Sam Yim
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm no expert but I've recently used Jersey and it has made parsing on the Client end much easier.
 
Dan Drillich
Ranch Hand
Posts: 1183
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Nick,

These days, we shouldn't use any Java API for XML Processing (JAXP) in cases such as yours. The real solution is JAXB, but you need to have the XML schemas that describe the requests.

Regards,
Dan
 
Ivan Krizsan
Ranch Hand
Posts: 2198
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi!
Have you taken a look at XStream http://xstream.codehaus.org/ ?
You do not need XML schemas to marshall and unmarshall, however it will use class instance field names as element names in the generated XML, so if your XML changes, you still need to modify the code.
Best wishes!
 
Jim Akmer
Ranch Hand
Posts: 104
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
@Dan: Why avoid JAXP?
 
Nick Sher
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is Java 6 a requirement for Jersey? I cannot run it with Java5.
 
Sam Yim
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Nick Sher wrote:Is Java 6 a requirement for Jersey? I cannot run it with Java5.


works with Java 5
 
Dan Drillich
Ranch Hand
Posts: 1183
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jim Akmer wrote:@Dan: Why avoid JAXP?


If the web service request and response format is known, why should we parse manually the requests and responses? Let's automate it and simplify the web service code. Btw, I'm a bit fascinated by JAXB.

Regards,
Dan
 
Lester Burnham
Rancher
Posts: 1337
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It should be noted that REST services need not necessarily return XML. If it's more convenient for some reason, JSON would be an alternative (especially if there's a chance that the service is consumed by a web browser).
 
Ivan Krizsan
Ranch Hand
Posts: 2198
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi!
Not really new stuff, but:
Just wrote a small program that "manually" parses XML using Groovy and the XmlSlurper class (http://groovy.codehaus.org/Reading+XML+using+Groovy%27s+XmlSlurper).
A refreshing experience, I must say!
Cannot vouch for the efficiency concerning memory usage and speed, though - haven't had time to look more closely into that part.
Best wishes!
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!