Web services. DOM parsing and SOAP.
Summary. ● Exercise: SAX-Based checkInvoice(), ● push parsing, ● event-based parsing, ● traversal order is depth-first. ● Intro to SOAP.
Today's agenda. ● Practical exercise: DOM parsing (p ) ● SOAP revisited ● Practical exercise: calling the web service googleSearch.
XML Document Character Stream Parser Serializer Standardized XML APIs Basic XML processing architecture. (deserializer) Application.
Document Interface: key methods. ● createElement(tagName:String):Element ● createDocumentFragment():Fragment ● createTextNode(data:String):Textdata:String):Text ● createAttribute(name:String):Attr ● getElementsByTagname(tagname:String):No deList
Todays exercise: DOM parsing. (Document Object Model, W3C) ONE-STEP parsing model. Most popular, and widely used parser model. Builds the parse tree first before parsing. ● Easy to program with, but ● takes up a lot of memory, ● takes time to instantiate the parse tree.
DOM parsing. ● Building a DOM parse tree. ● Navigating and manipulating the DOM tree. Two important packages: ● org.w3c.dom ● javax.xml.parsers
: ● Java API for XML Web Services (JAX-WS) ● Java Architecture for XML Binding (JAXB) ● Java API for XML Messaging (JAXM) ● >>> Java API for XML Processing (JAXP) ● Java API for XML Registries (JAXR) ● Java API for XML-based RPC (JAX-RPC) ● SOAP with attachments API for Java (SAAJ) ● Java API for XML WS addressing (JAX-WSA) ● XML Web Services Security (XWSS)
Building the DOM parse tree.
The DOM parsing architecture. ob W3C DOM Document Builder Instance. XML Data DocumentBuilder Factory get build read
Package to build DOM tree: ● javax.xml.parsers ● Specifies DocumentBuilder classes, and DocumentBuilderFact ory classes.
Navigate and manipulate DOM parse tree.
Key DOM interfaces (Fig.2.9) Interface NodeList Interface CharacterData Interface Text Interface Node Interface Document Interface NamedNodeMap Interface Element Interface Attr
Document Interface: key methods. ● createElement(tagName:String):Element ● createDocumentFragment():DocumentFragm ent ● createTextNode(data:String):Textdata:String):Text ● createAttribute(name:String):Attr ● getElementsByTagname(tagname:String):No deList
Document Interface: key methods. ● createElement(tagName:String):Element ● createDocumentFragment():Fragment ● createTextNode(data:String):Textdata:String):Text ● createAttribute(name:String):Attr ● getElementsByTagname(tagname:String):No deList
Document Interface: key methods. ● createElement(tagName:String):Element ● createDocumentFragment():Fragment ● createTextNode(data:String):Textdata:String):Text ● createAttribute(name:String):Attr ● getElementsByTagname(tagname:String):No deList
Key DOM interfaces. Interface NodeList Interface CharacterData Interface Text Interface Node Interface Document Interface NamedNodeMap Interface Element Interface Attr
Node (root) Interface: key methods. ● + getNodeName():String ● + getNodeValue():String ● + setNodeValue(nodeValue:String):void ● +getNodeType():short ● +getParentNode():Node ● +getChildNodes():NodeList ● +getAttributes():NamedNodeMap
Key DOM interfaces. Interface NodeList Interface CharacterData Interface Text Interface Node Interface Document Interface NamedNodeMap Interface Element Interface Attr
Element Interface: key methods. ● +getTagName():String ● +getAttribute(name:String):String ● +setAttribute(name:String,value:String):void ● +hasAttribute(name:String):boolean
Key DOM interfaces. Interface NodeList Interface CharacterData Interface Text Interface Node Interface Document Interface NamedNodeMap Interface Element Interface Attr
Attribute Interface: key methods. ● +getName():String ● +getValue():String ● +setValue(value:String):void
Key DOM interfaces. Interface NodeList Interface CharacterData Interface Text Interface Node Interface Document Interface NamedNodeMap Interface Element Interface Attr
DOM has a name-space aware version: API version of most key interfaces: ● getAttributeNS(String nsURI,String localName) Example ● “ (ns URI) ● “item”, “tax”,.. etc. (local name, w.o. prefix)
Requires the parser become name space aware. ● After: DocumentBuilderFactory factory= DocumentBuilderFactory.newInstance(); ● insert: factory.SetNamespaceAware(true);
Today's DOM exercise. ● Use DOM for invoice checker: repeat last weeks exercise using a DOM parser instead ( Down load files: InvoiceChecker.java, InvoiceCheckerDOM.java with ftp://evarose.net) ● Transform InvoiceCheckerDOM.java to read an invoice xml document which uses name spaces. (Download skatextownInvoiceNS.xml with ftp://evarose.net)
Java API Specifications To help you in developing Java programs: ● Go to: Then click on API Specifications Then click on J2SE
DOM-based Invoice Checker imports: package com.skatestown.invoice; import java.io.InputStream; import org.w3c.dom.Node; import org.w3c.dom.NodeList; import org.w3c.dom.Element; import org.w3c.dom.CharacterData; import javax.xml.parsers.DocumentBuilder; importjavax.xml.parsers.DocumentBuilderFactory
SOAP The Simple Access Object Protocol.
Service requester Service provider soap messages application object (client) SOAP-based middleware application object (service provider) SOAP-based middleware stub skeleton
Structure and content of a SOAP message All SOAP messages are XML documents, containing the elements: 1. Required envelope element, 2. Optional header element, 3. Required body element, 4. Optional fault element.
SOAP namespaces ● The 4 principal elements are declared in the default namespace for the SOAP envelope: ● The default namespace for SOAP encoding and data types:
Important syntax rules ● Soap messages must be encoded using XML, ● Soap messages must use the SOAP envelope namespace, ● SOAP messages must use the SOAP encoding namespace, ● SOAP messages must not contain XML processing instructions.
SOAP envelope SOAP header SOAP body SOAP MESSAGE header block
SOAP request. <soap:Envelope xmlns:soap=" soap:encodingStyle= " IBM
SOAP response <soap:Envelope xmlns:soap=" soap:encodingStyle=" encoding"> 34.5
Calling the googleSearch web service. ● download axis 2 (soap library), either from ftp://evarose.net or ● unpack the axis 2 zip-archive ● current directory must be samples\ googleSearch\ ● run the Run.bat script ● enter 1) axis 2) marist ● what is the effect?
See you next week for: ● The Web Service Description Language (WSDL). ● Assignment 1.