Presentation is loading. Please wait.

Presentation is loading. Please wait.

Web services. DOM parsing and SOAP.. Summary. ● Exercise: SAX-Based checkInvoice(), ● push parsing, ● event-based parsing, ● traversal order is depth-first.

Similar presentations


Presentation on theme: "Web services. DOM parsing and SOAP.. Summary. ● Exercise: SAX-Based checkInvoice(), ● push parsing, ● event-based parsing, ● traversal order is depth-first."— Presentation transcript:

1 Web services. DOM parsing and SOAP.

2 Summary. ● Exercise: SAX-Based checkInvoice(), ● push parsing, ● event-based parsing, ● traversal order is depth-first. ● Intro to SOAP.

3 Today's agenda. ● Practical exercise: DOM parsing (p.91 - 96) ● SOAP revisited ● Practical exercise: calling the web service googleSearch.

4 XML Document Character Stream Parser Serializer Standardized XML APIs Basic XML processing architecture. (deserializer) Application.

5 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

6 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.

7 DOM parsing. ● Building a DOM parse tree. ● Navigating and manipulating the DOM tree. Two important packages: ● org.w3c.dom ● javax.xml.parsers

8 http://java.sun.com/webserviceshttp://java.sun.com/webservices : ● 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)

9 Building the DOM parse tree.

10 The DOM parsing architecture. ob W3C DOM Document Builder Instance. XML Data DocumentBuilder Factory get build read

11 Package to build DOM tree: ● javax.xml.parsers ● Specifies DocumentBuilder classes, and DocumentBuilderFact ory classes.

12 Navigate and manipulate DOM parse tree.

13 Key DOM interfaces (Fig.2.9) Interface NodeList Interface CharacterData Interface Text Interface Node Interface Document Interface NamedNodeMap Interface Element Interface Attr

14 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

15 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

16 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

17 Key DOM interfaces. Interface NodeList Interface CharacterData Interface Text Interface Node Interface Document Interface NamedNodeMap Interface Element Interface Attr

18 Node (root) Interface: key methods. ● + getNodeName():String ● + getNodeValue():String ● + setNodeValue(nodeValue:String):void ● +getNodeType():short ● +getParentNode():Node ● +getChildNodes():NodeList ● +getAttributes():NamedNodeMap

19 Key DOM interfaces. Interface NodeList Interface CharacterData Interface Text Interface Node Interface Document Interface NamedNodeMap Interface Element Interface Attr

20 Element Interface: key methods. ● +getTagName():String ● +getAttribute(name:String):String ● +setAttribute(name:String,value:String):void ● +hasAttribute(name:String):boolean

21 Key DOM interfaces. Interface NodeList Interface CharacterData Interface Text Interface Node Interface Document Interface NamedNodeMap Interface Element Interface Attr

22 Attribute Interface: key methods. ● +getName():String ● +getValue():String ● +setValue(value:String):void

23 Key DOM interfaces. Interface NodeList Interface CharacterData Interface Text Interface Node Interface Document Interface NamedNodeMap Interface Element Interface Attr

24 DOM has a name-space aware version: API version of most key interfaces: ● getAttributeNS(String nsURI,String localName) Example ● “http://skatestown.com/ns/invoice” (ns URI)http://skatestown.com/ns/invoice ● “item”, “tax”,.. etc. (local name, w.o. prefix)

25 Requires the parser become name space aware. ● After: DocumentBuilderFactory factory= DocumentBuilderFactory.newInstance(); ● insert: factory.SetNamespaceAware(true);

26 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)

27 Java API Specifications To help you in developing Java programs: ● Go to: http://java.sun.com/j2se Then click on API Specifications Then click on J2SE

28 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

29 SOAP The Simple Access Object Protocol.

30 Service requester Service provider soap messages application object (client) SOAP-based middleware application object (service provider) SOAP-based middleware stub skeleton

31 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.

32 SOAP namespaces ● The 4 principal elements are declared in the default namespace for the SOAP envelope: http://www.w3.org/2001/12/soap-envelope http://www.w3.org/2001/12/soap-envelope ● The default namespace for SOAP encoding and data types: http://www.w3.org/2001/12/soap-encoding http://www.w3.org/2001/12/soap-encoding

33 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.

34 SOAP envelope SOAP header SOAP body SOAP MESSAGE header block

35 SOAP request. <soap:Envelope xmlns:soap="http://www.w3.org/2001/12/soap-envelope" soap:encodingStyle= "http://www.w3.org/2001/12/soap-encoding"> IBM

36 SOAP response <soap:Envelope xmlns:soap="http://www.w3.org/2001/12/soap-envelope" soap:encodingStyle="http://www.w3.org/2001/12/soap- encoding"> 34.5

37 Calling the googleSearch web service. ● download axis 2 (soap library), either from ftp://evarose.net or http://ws.apache.orgftp://evarose.nethttp://ws.apache.org ● 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?

38 See you next week for: ● The Web Service Description Language (WSDL). ● Assignment 1.


Download ppt "Web services. DOM parsing and SOAP.. Summary. ● Exercise: SAX-Based checkInvoice(), ● push parsing, ● event-based parsing, ● traversal order is depth-first."

Similar presentations


Ads by Google