• 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

need help with document based web services

 
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all,

i am workin on a project with very stiff deadline. I need to develop a web service which takes an xml document as a String, processes it and updates the database and returns a confirmation xml document. the service needs to b document based.

following is the method signature we will b exposing:

public String SomeMethod(String request){
return Confirmdoc;
}

i have gone thru some documents but i am a little confused as to how i shud send the XML document and how i shud recieve it and parse it and then validate it and update the database. there is very little help available online for Document based web services..most material i went thru just give a threotical overview..but no real case has been shown.

i am using Apache Tomcat and Apache Axis1.3.

the xml will be validated against a schema which will be avaialble at both ends.

I am new to Web services and any help will b greatly appreciated.

following are the things i need to know.:

1. how i'll pass the xml document to the service... using which apis
2. how i'll recieve the doc as a string and how will i generate the original XML doc frm it and validate it against the schema.


Thanx.
 
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
>>1. how i'll pass the xml document to the service... using which apis
From the client, create a SOAPEnvelope and using Axis classes send it to the target end point using the api from axis library.
http://ws.apache.org/axis/.

2. how i'll recieve the doc as a string and how will i generate the original XML doc frm it and validate it against the schema.
>> I have seen and implemented the document based axis webserivices like this.

public Document SomeMethod(Document doc){
return Confirmdoc;
}

For converting XML string to java objects to store the info in DB, here is a nice one:
http://xstream.codehaus.org/
 
Bartender
Posts: 2968
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Mathur Neni:
I have seen and implemented the document based axis webserivices like this.

public Document SomeMethod(Document doc){
return Confirmdoc;
}



That is not the recommended practice. See:

Designing Web Services with the J2EE 1.4 Platform
3.7.1 Exchanging XML Documents
[ February 23, 2006: Message edited by: Peer Reynders ]
 
Peer Reynders
Bartender
Posts: 2968
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Not sure if this will help you; its probably at a higher-level than what you are looking for:
Patterns and Strategies for Building Document-Based Web Services
 
Mohit Goyal
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all

Thanks a lot for your support ..i already went throughthe documents you ppl listed in your replies..n eways i really appreciate all the help...

I have successfully deployed the service and it is working fine. As a next step i need to parse the XML document recieved as String and validate it against the schema and then update the database.

I am really confused as to which parser I should go for SAX or DOm.. i also came across JDOM and DOM4J. can you guide me on this as i m new to this whole thing.

Thanks
Mohit
SCJP1.4(98%)
 
Peer Reynders
Bartender
Posts: 2968
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You missed some options
StAX and JAXB (JAXB 1.0)

On a high level:

SAX - An event-based push parser.
Pros:
  • Fast, small memory footprint.
  • Good if you are only interested in part of the document.
  • Standard in JDK 1.5.

  • Cons:
  • Not as easy to use, as all the events are forced through an single event handler and you have to devise some way of tracking the parsing state of the document yourself so you know "where you are in the document" when you process the next event.
  • Has no XML output facilities.


  • StAX (JSR 173) - A stream-based pull parser (An introduction to StAX)
    Pros:
  • Fast, small memory footprint.
  • Some find it easier to use as you can "process the next token" in different spots of your logic - in effect your position within the logic can help to track the current state of your document parsing.
  • Also provides a facility to write XML output.
  • May become standard with the next Enterprise Edition as it is heavily used in the JWSDP 2.0.

  • Cons:
  • Neither part of the current standard edition or the enterprise edition.


  • DOM
    Pros:
  • Easier to use that SAX
  • Allows modification of the XML Document
  • Can write the XML document
  • Best used when you are manipulating the XML document rather than creating a Java Object model mapping.
  • Standard in JDK 1.5.

  • Cons:
  • Memory hog as the entire XML document DOM representation is loaded into memory.
  • The DOM API doesn't feel like "Java" - you are constantly reminded that you are manipulating the DOM representation of an XML document (with all its quirks) rather than a Java Object model (with gave rise to JDOM).
  • Not ideal if you are building an equivalent Java Object model as you have to discover the document by traversing the entire document with the DOM API.


  • JDOM
    Pros:
  • Feels more like Java than DOM.

  • Cons:
  • Will probably never be part of the standard edition or enterprise edition.


  • JAXB - not really a parser but a binding framework. If you have an XML Schema the binding compiler will generated a Java content-tree for you. The binding customizations allow you to influence how that Java content tree look. Then the generated classes can unmarshal the XML document to the Java content-tree and marshal the Java-content tree to an XML document. Does validation as well/ Java Architecture for XML Binding
    Pros:
  • Use when you are dealing with a static XML schema and you usually have to parse the whole document and make extensive modifications to it and prefer to it in the Java paradigm.
  • Some implementations may use less memory than DOM.
  • May become standard with the next Enterprise Edition as it is heavily used in the JWSDP 2.0.

  • Cons:
  • Neither part of the current standard edition or the enterprise edition.



  • Elliotte Rusty Harold: Processing XML with Java
    reply
      Bookmark Topic Watch Topic
    • New Topic