1 / 44

J2EE Technologies: Web Services I

J2EE Technologies: Web Services I. Benny Rochwerger Research Staff Member. Agenda. Web Services: What is it about XML Primer Simple Object Access Protocol – SOAP Describing Web Services – WSDL Discovering Web Services – UDDI Web Services in the Marketplace What is next

lorna
Download Presentation

J2EE Technologies: Web Services I

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. J2EE Technologies: Web Services I Benny Rochwerger Research Staff Member

  2. Agenda • Web Services: What is it about • XML Primer • Simple Object Access Protocol – SOAP • Describing Web Services – WSDL • Discovering Web Services – UDDI • Web Services in the Marketplace • What is next • The Open Grid Services Architecture

  3. Web Services Overview • An platform and language independent architecture for program to program communications • A Web Service is a software component that can be: • Described using a service description language • Published to a registry of services • Discovered using a standard mechanism (at runtime or design time) • Invoked through a declared API (usually over the network) • Composed with other services

  4. Web Services Overview (cont.) • A Web Service is an interface that describes a collection of operations that are network accessible through standardized XML messaging • A Web Service is described using a standard, formal XML notion, called service description, which covers message formats, transport protocols and location • The interface hides the implementation details of the service

  5. The Service Oriented Architecture (SOA) ServiceRegistry Publish Find ServiceProvider ServiceRequestor Bind

  6. The Web Services Stack ServicePublication/Discovery UDDI ServiceDescription WSDL XML Messaging SOAP Transport Network HTTP, SMTP, MQSeries, etc.

  7. Web Services Advantages • Big players, such as IBM, Sun and Microsoft, actively support it • Reuses the big infrastructure already built for the Web and the HTTP protocol • SOAP as the de facto standard of doing RPC over the web • It has the potential to become a lingua franca that you can fall back on when all else fails • CORBA’s IIOP has not penetrated the internet as HTTP has • If SOAP can run on HTTP or any other Internet Protocol, it is bound to enter the domain the IIOP has not • Web Services are poised to do to program to program interactions, what the Web did for program to user interactions

  8. The eXtensible Markup Language - XML • Generalized Markup Languages • Use tags to identify information • Surround information with start and end tags <book> <title>Crime and Punishment</title> <author> <FirstName>Fyodor</FirstName> <LastName>Dostoevsky</LastName> </author> <Published>1866</Published> </book>

  9. The XML Evolution • 1986 - Standard Generalized Markup Language (SGML) • Meta-language • Do not defined a particular markup • Define how to formally specify markup languages • SGML application • Specific markup languages defined with the SGML meta-language • Very complex • Expensive software needed to process SGML

  10. The XML Evolution (cont.) • 1992 - Hypertext Markup Language (HTML) • Successful instance of a SGML application • Tags to represent rich hypertext: • Text structuring: <H1>, <H2>, <P>, <BR> • Formatting: <B>, <I> • Linking and embedding: <A>, <IMG> • Data input: <FORM>, <INPUT> • Not extensible • Vendors added incompatible tags

  11. The XML Evolution (cont.) • 2000 – eXtensible Markup Language (XML) • Simplify SGML • Control evolution of HTML • As SGML, it is a meta-language • Few optional features • Difficult to implement SGML features were dropped • De-facto standard for representing structured and semi-structured information in a textual form

  12. Document-Centric vs. Data-Centric • Document-Centric XML • Semi-structured documents • Technical manuals, legal documents, product catalog • Typically consumed by humans • Data-Centric XML • Textual representation of highly structured information • Relational data, financial transactions, programming languages data structures • Typically machine generated and consumed

  13. XML Instances Root element XML Declaration <?xml version=“1.0” encoding=“UTF-8” ?> <PhoneBook> <Contact> <FirstName>John</FirstName> <LastName>Doe</LastName> <phone location=“home”> 04 987 6543 </phone> <phone location=“work”> 04 876 5432 </phone> </Contact> </PhoneBook> Attribute Element Text

  14. XML Namespaces • Avoid collisions in elements with common names by qualifyingelement names with unique identifiers • QName = Namespace identifier + element name • Use URIs for identifiers (entirely for identification) • To ease use of identifiers assign each URI a prefix • Defined through attributes, valid for all contained elements: <Contact xmnls:myab=“http://my.company.com/addressbook” xmnls:bezeqab=“http://bezeq.co.il/addressbook”> <myab:entry> <myab:name>John Doe</myab:name> </myab:entry> <bezeqab:entry> <bezeqab:FirstName>John</bezeqab:FirstName> <bezeqab:LastName>Doe</bezeqab:LastName> </bezeqab:entry> </Contact>

  15. XML Schemas • Mechanism to specify: • the datatype of each element/attribute • "this element shall hold an integer with the range 0 to 12,000" • the structure of instance documents • "this element contains these elements, which contains these other elements, etc" • Declarative mechanism for validating the contents of XML documents • A powerful alternative to older Document Type Definitions (DTDs) • XML based – reduces the need for yet another parser • Designed with namespaces in mind since the beginning • Extensive pre-defined simple types • Easy mechanism for creating new types

  16. Define cardinality of elements Create complex types out of a sequence of simple types XML Schema for a Bookstore <?xml version="1.0" encoding="UTF-8" ?> <xsd:schema xmlns:xsd=http://www.w3.org/2001/XMLSchema> <xsd:element name="BookStore"> <xsd:complexType> <xsd:sequence> <xsd:element ref="Book" minOccurs="1" maxOccurs="unbounded" /> </xsd:sequence> </xsd:complexType> </xsd:element> <xsd:element name="Book"> <xsd:complexType> <xsd:sequence> <xsd:element name="Title" type="xsd:string" /> <xsd:element name="Author" type="xsd:string" /> <xsd:element name=“Published" type="xsd:date" /> </xsd:sequence> </xsd:complexType> </xsd:element> </xsd:schema>

  17. XML Schema Builtin Datatypes Time Data Binary Data Textual Data Numeric Data

  18. Processing XML – Parsing Models • Pull parsing • Application “pulls” from parser for next piece of information • No standard API yet • Push parsing • Parser “pushes” complete pieces of information read • Application provides event-callback • The Simple API for XML (SAX) is the de-facto standard • One-step parsing • Read entire XML document and build an equivalent parsed tree • The W3C Document Object Model (DOM) specification • Map XML objects to data structures used to build the parsed tree • Very popular due to simplicity (compared with other methods) • Not too efficient • Hybrid parsing • Application thinks entire tree has been built (one-step parsing) • Parser pulls data as needed (pull-parsing)

  19. Abstract class that defines all SAX callback interfaces Create the connection between our concrete handler and the SAX parser. Start parsing Receive notification of beginning of a document Receive notification of end of a document ` Processing XML – SAX-based import javax.xml.parsers.SAXParser;import javax.xml.parsers.SAXParserFactory;import org.xml.sax.Attributes;import org.xml.sax.SAXException;import org.xml.sax.helpers.DefaultHandler; public class MySaxBasedApplication extends DefaultHandler { public void processXML(InputStream XMLStream) { SAXParserFactory factory = SAXParserFactory.newInstance(); SAXParser parser = factory.newSAXParser(); parser.parse(XMLStream, this); } public void startDocument() throws SAXException { // My code goes here . . . } public void endDocument() throws SAXException { // My code goes here . . . }

  20. Receive notification of beginning of an element Receive notification of end of an element Receive notification of character data inside an element Processing XML – SAX-based (cont.) public void startElement(String namespaceURI, String localName, String qualifiedName, Attributes attrs) throws SAXException { // My code goes here . . . } public void endElement(String namespaceURI, String localName, String qualifiedName) throws SAXException { // My code goes here . . . } public void characters(char buf[], int offset, int len) throws SAXException { // My code goes here . . . }} // ENDOF: public class MySaxBasedApplication extends DefaultHandler

  21. Parse the entire XML document into a DOM tree Then use the DOM interfaces to manipulate the tree Processing XML – DOM-based import javax.xml.parsers.DocumentBuilder;import javax.xml.parsers.DocumentBuilderFactory;import org.w3c.dom.NodeList;import org.w3c.dom.Document;import org.w3c.dom.Element; public class MyDomBasedApplication { public void processXML(InputStream XMLStream) { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder = factory.newDocumentBuilder(); Document doc = builder.parser(XMLStream); // My code goes here . . . // use DOM interfaces to manipulate the tree: Element e = doc.getDocumentElement(); if (e.hasAttribute(“an-attribute”)) { // do something with Element e } }} // ENDOF: public class MyDomBasedApplication

  22. Processing XML – DOM-based (cont.)

  23. XML Summary • XML Namespaces • Key tool for resolving the problems of name recognition and collision • Fundamental for mixing information from multiple schemas into a single document • XML Schema • De facto standard for describing document structure and XML data types for data-oriented XML applications • Java APIs for XML processing • org.xml.sax • Push parsing, fast but hard to use • org.w3c.dom • One-step parsing, easy to use but inefficient

  24. The Simple Object Access Protocol (SOAP) • XML-based protocol for messaging and RPC • Can works on top of existing transports • HTTP, SMTP, FTP, MQSeries • Use of XML schema for encoding typed values • Language independent • Generation of SOAP messages available in popular programming language • C, Java, Perl

  25. A SOAP Message • Envelope • Mandatory root element of SOAP messages • Contains an optional header and the message body • Header • Primary extensibility mechanism • Usually handled by intermediaries • Typical uses: authentication, authorization, transaction management, tracing, etc. • One or more header entries or headers • Arbitrary XML • mustUnderstand attribute • Body • One or more header body entries or bodies • Arbitrary XML

  26. A SOAP Message - Example <env:Envelope xmlns:env="http://www.w3.org/2002/06/soap-envelope"> <env:Header> <n:alertcontrol env:mustUnderstand="false“ xmlns:n="http://example.org/alertcontrol"> <n:priority>1</n:priority> <n:expires>2001-06-22T14:00:00-05:00</n:expires> </n:alertcontrol> </env:Header> <env:Body> <m:alert xmlns:m="http://example.org/alert"> <m:msg>Pick up Mary at school at 2pm</m:msg> </m:alert> </env:Body> </env:Envelope>

  27. SOAP: XML Messaging Service Requestor Service Provider Application Web Service Application data Service data SOAP Engine SOAP Engine SOAP Envelope SOAP Envelope Network Protocol Network Protocol Protocol packet Protocol packet Response Request

  28. SOAP over HTTP The HTTP header The SOAP envelope as the HTTP payload POST /StockQuoteProj/servlet/rpcrouter HTTP/1.0 Host: localhost:9081 Content-Type: text/xml; charset=utf-8 Content-Length: 469 SOAPAction: "" <?xml version='1.0' encoding='UTF-8'?> <SOAP-ENV:Envelope xmlns:SOAPENV=“http://schemas.xmlsoap.org/soap/envelope/” xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> <SOAP-ENV:Body> <ns1:getQuote xmlns:ns1=“http://tempuri.org/StockQuoteService”> <symbol xsi:type="xsd:string">IBM</symbol> </ns1:getQuote> </SOAP-ENV:Body> </SOAP-ENV:Envelope>

  29. SOAP over SMTP The SOAP envelope as the SMTP payload The SMTP header From: john.public@mycompany.example.com To: reservations@travelcompany.example.org Subject: Travel to LA Date: Thu, 29 Nov 2001 13:20:00 EST Message-Id: <EE492E16A0B8D311AC490090276D208424960C0C@mycompany.example.com> <?xml version='1.0' ?> <env:Envelope xmlns:env="http://www.w3.org/2001/12/soap-envelope"> <env:Body> <p:itinerary xmlns:p="http://travelcompany.example.org/reservation/travel"> <p:departure> <p:departing>New York</p:departing> <p:departureDate>2003-05-25</p:departureDate> <p:departureTime>late afternoon</p:departureTime> </p:departure> <p:return> <p:departing>Los Angeles</p:departing> <p:departureDate>2003-05-30</p:departureDate> <p:departureTime>mid morning</p:departureTime> </p:return> </p:itinerary> </env:Body> </env:Envelope>

  30. SOAP Intermediaries • Vertical extensibility • Capability of adding new pieces of information within a SOAP message • Horizontal extensibility • Targeting different parts of a SOAP message to different recipients • Achieved through intermediaries that process parts of SOAP messages as they travel from source to destination • Security • Scalability • Tracing • SOAP headers can be explicitly targeted at intermediaries • SOAP-ENV:actor attribute • http://schemas.xmlsoap.org/soap/actor/next

  31. SOAP Intermediaries Service Requestor Service Provider Application Web Service Actor 1 Actor 2 Application data Service data SOAP Engine SOAP Engine SOAP Engine SOAP Engine SOAP Envelope SOAP Envelope SOAP Envelope SOAP Envelope Network Protocol Network Protocol Network Protocol Network Protocol Protocol packet Protocol packet

  32. The reservation system must keep an unique reference to the itinerary The employees system must know who is traveling SOAP Intermediaries – Example <env:Envelope xmlns:env="http://www.w3.org/2001/12/soap-envelope"> <env:Header> <m:reservation xmlns:m="http://travelcompany.example.org/reservation" env:actor="http://www.w3.org/2001/12/soap-envelope/actor/next" env:mustUnderstand="true"> <m:reference>uuid:093a2da1-q345-739r-ba5d-pqff98fe8j7d</reference> </m:reservation> <n:passenger xmlns:n="http://mycompany.example.com/employees" env:actor="http://www.w3.org/2001/12/soap-envelope/actor/next" env:mustUnderstand="true"> <n:name>John Q. Public</n:name> </n:passenger> </env:Header> <env:Body> <p:itinerary xmlns:p="http://travelcompany.example.org/reservation/travel"> <p:departure> <p:departing>New York</p:departing><p:departureDate>2001-12-14</p:departureDate> </p:departure> <p:return> <p:departing>Los Angeles</p:departing><p:departureDate>2001-12-20</p:departureDate> </p:return> </p:itinerary> </env:Body> </env:Envelope>

  33. Where in the message path the error ocurred The mandatory faultcode element: - VersionMismatch - MustUnderstand - Client - Server Transport Protocol Error indication Human readable message identifying cause of the problem SOAP Error Handling HTTP/1.0 500 Internal Server ErrorContent-Type: text/xml; charset=“utf-8”Content-Length: nnnn<SOAP-ENV:Envelope xmlns:SOAP-ENV=“http://www.w3.org/2001/12/soap-envelope” SOAP-ENV:encodingStyle=“http://schemas.xmlsoap.org/soap/enconding/”> <SOAP-ENV:Body><SOAP-ENV:Fault> <faultcode>Client.AuthenticationFailure</faultcode> <faultstring>Failed to authenticate client</faultstring> <faultactor>where-the-problem-occurred</faultactor></SOAP-ENV:Fault> </SOAP-ENV:Body></SOAP-ENV:Envelope>

  34. SOAP Data Encoding • How to encode complex data types that do not have a direct representation in XML Schema • Arrays, arbitrary data structures • Explicitly specify encoding rules of the message or parts of it • The encodingStyle attribute • SOAP defined encoding rulesSOAP-ENV:encodingStyle=http://schemas.xmlsoap.org/soap/encoding • No default encoding, i.e., this attribute is mandatory at least for the SOAP-ENV:Envelope element • Data encoding rules • Well defined mapping between abstract data models (ADM) and XML syntax

  35. SOAP Data Encoding (cont.) • Simple types • Map to XML Schema built-in types • Compound types • Composed of several parts, each with an associated type • Parts are distinguished by an accesor • Name or relative position of a part • Structs • Compound types whose parts are distinguished only by their name • Arrays • Compound types whose parts are distinguished only by their ordinal position

  36. SOAP Data Encoding - Arrays Encoding using the schema Schema for an array of integers Array encoding without schema <element name=“arrayOfNumbers”> <complexType base=“SOAP-ENC:Array> <element name=“number” type=“xsd:int” maxOcurrs=“unbounded”/> </complexType></element> <arrayOfNumbers SOAP-ENC:arrayType=“xsd:int[2]”> <number>11</number> <number>22</number></arrayOfNumbers> <SOAP-ENC:Array SOAP-ENC:arrayType=“xsd:int[2]”> <SOAP-ENC:int>11</SOAP-ENC:int> <SOAP-ENC:int>22</SOAP-ENC:int></SOAP-ENC:Array>

  37. SOAP Data Encoding – Structured Data • Does the XML format on the wire matters ? • No  Use automatic “data to XML and back” encoding systems Serializer Application Data XML Deserializer

  38. codegen codegen SOAP Data Encoding – Structured Data • Does the XML format on the wire matters ? • Yes  Automatic generated XML might not be good enough • Delegate XML processing to application • Build and register custom serializers/deserializers • Manually • Use of schema compilers Serializer Application Data XML Schema Schema Compiler Deserializer

  39. Messaging Focus is data, which can be in any conceivable format APIs sendMessage(), getMessage(), registerMessageCallback() In the WS context Carry XML data Could be one-way or request-response Asynchronous Remote Procedure Call Focus is logic APIs: Call(target, operation, params[]) In the WS context Direct, synchronous, request-response invocations Pass data structures Messaging versus RPC

  40. Operation SOAP RPC <?xml version='1.0' encoding='UTF-8'?> <SOAP-ENV:Envelope xmlns:SOAPENV=“http://schemas.xmlsoap.org/soap/envelope/” xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> <SOAP-ENV:Body> <ns1:getQuote xmlns:ns1=“http://tempuri.org/StockQuoteService”> <symbol xsi:type="xsd:string">IBM</symbol> </ns1:getQuote> </SOAP-ENV:Body> </SOAP-ENV:Envelope> Parameter

  41. SOAP Messaging <env:Envelope xmlns:env="http://www.w3.org/2001/12/soap-envelope"> <env:Body> <p:itinerary xmlns:p="http://travelcompany.example.org/reservation/travel"> <p:departure> <p:departing>New York</p:departing> <p:departureDate>2003-05-25</p:departureDate> <p:departureTime>late afternoon</p:departureTime> </p:departure> <p:return> <p:departing>Los Angeles</p:departing> <p:departureDate>2003-05-30</p:departureDate> <p:departureTime>mid morning</p:departureTime> </p:return> </p:itinerary> </env:Body> </env:Envelope>

  42. SOAP Summary • The flexible SOAP envelope • Vertical extensibility using SOAP headers • SOAP intermediaries • Horizontal extensibility • Encoding data using SOAP • SOAP for messaging and RPC applications • SOAP over multiple network protocols

  43. Agenda • Web Services: What is it about • XML Primer • Simple Object Access Protocol – SOAP • Describing Web Services – WSDL • Discovering Web Services – UDDI • Web Services in the Marketplace • What is next • The Open Grid Services Architecture

  44. J2EE Technologies: Web Services I Benny Rochwerger Research Staff Member

More Related