Win a copy of Head First Android this week in the Android forum!
  • 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:
  • Tim Cooke
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Jesse Silverman
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Al Hobbs
  • salvin francis

RESTful client or HTTP client with DOM

 
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 1183
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 2198
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!
 
Ranch Hand
Posts: 104
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
@Dan: Why avoid JAXP?
 
Nick Sher
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Rancher
Posts: 1337
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!
 
reply
    Bookmark Topic Watch Topic
  • New Topic