1 / 48

Lecture 21

CS441 CURRENT TOPICS IN PROGRAMMING LANGUAGES. Lecture 21. George Koutsogiannakis Summer 2011. Topics. Web Services. XML SOAP WSDL UDDI. Web Services. Two competing architectures. .NET (Microsoft). Sun’s Java Web Services. We will discuss Sun’s Web Services. Web Services.

miles
Download Presentation

Lecture 21

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. CS441 CURRENT TOPICS IN PROGRAMMING LANGUAGES Lecture 21 George Koutsogiannakis Summer 2011

  2. Topics • Web Services. • XML • SOAP • WSDL • UDDI

  3. Web Services • Two competing architectures. • .NET (Microsoft). • Sun’s Java Web Services. • We will discuss Sun’s Web Services.

  4. Web Services • Deployment is independent of the two technologies. • Interoperability between different languages. • Interoperability between different platforms. • Interoperability between transport protocols (messages can ride on top of existing protocols by adding an extra layer).

  5. Java Web Services • Java Web Services Developer Pack is used for web services and clients. • Java Web Services Developer Pack includes the following: • 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) • Java API for XML Web Services (JAX-WS) • SOAP with Attachments API for Java (SAAJ) • Java Server Pages Standard Tag Library (JSTL) • Java Server Faces • Java WSDP Registry Server • Web Applications Deployment Tool • Ant Build Tool • Apache Tomcat servlet container • All of the above are part of EE5 and up .

  6. Java Web Services Convert XML to Java Service Client Convert Java Type to XML Java Types Communicatiosn XML messages communications

  7. Web Services • Web Services is a technology geared for Internet Based Distributed Computing. • Requires adding to the Internet infrastructure another layer that is responsible for managing the resources needed for Web Services. • Designers can design a Web Service without a concern as to the type or the number of nodes that are going to use the service. • It is based on request/response messages.

  8. Web Services • Web Services use Internet protocols to publish their existence, discover each other and invoke each other. • Publishing and discovery is done via: • UDDI Universal Description, Discovery and Integration specification. • It is used to list the available services. • WSDL Web Services Description Language • Describes the available services.

  9. Web Services • Other Protocols involved: • XML • Custom made tags are used to structure the message. • SOAP (Simple Object Access protocol) • Transfers the messages.

  10. Web Services • Web Services are based on the concept of Service-Oriented Architecture (SOA). • SOAP is based on building components that can communicate with each other. • The components as in previous architectures that we studied (RMI, EJBs) must have well defined interfaces.

  11. Web Services • Any service architecture contains 3 roles: • A service provider • Deployment of the service. • Publishing (registering) the service. • A service requestor • Finds a service description published in one or more registries. • Invokes the desired service. • A service registry • Advertizes web services descriptions published. It is the match maker between requestor and provider.

  12. Web Services-XML • XML mark up language’ specification identifies element as: • A pairing of start and end tags in a XML document. • Elements have one of the following: • element-only content • Nested elements • mixed content • Nested elements and text mixed. • empty content.

  13. Web Services -XML • Elements can have attributes • A name value pair • Value is enclosed in quotation marks. • For instance we can have an element called purchase order (<po>) <po id=“43871” submitted=“2009-04-21” customerID=“1234”> </po>

  14. Web Services -XML • Alternatively instead of attributes we can define nested elements: <po> <id>43871</id> <submitted>2009-04-21</submitted> <customerID>1234</customerID> </po>

  15. Web Services-XML- • XML schemas • Document Type Definitions (DTD) document describes rules regarding the elements used. • Schemas are used to validate the contents of XML documents as they are parsed by the XML parser. • Schemas enable the following: • Identification of the elements that are in a XML document. • Identification of the order and relationship between elements in the XML document.

  16. Web Services-XML • Identification of the attributes of an element. • Identification of the data type of the value of an attribute. • Thus in summary, we have: • An XML document that defines the messages (data) in terms of XML elements. • A DTD document that describes the elements. • A need for a parser (can be written in Java) that checks the XML document against the DTD. • If the XML document adheres to DTD it is called “well formed” otherwise errors are generated.

  17. Web Services-XML • The XML document then is made of 3 pieces: Called entities: • Elements • Attributes • Data

  18. Web Services-SOAP • SOAP is a specification that describes how data should be structured in order to be transported over the Internet as part of distributed services. • SOAP is intended for B2B (Business to Business) or A2A (Application to Application) or EAI (Enterprise Application Integration). • It is not intended for Business to Customer.

  19. Web Services -SOAP • SOAP is usually embedded in HTTP packets as part of request / response • The riding of one protocol on top of another is called “tunneling”. • SOAP handles data in terms of a textual form (RMI, CORBA and other distributed services protocols handle data in binary form).

  20. Web Services-SOAP • SOAP message • An instance of the XML document • SOAP nodes • Peers of the distributed network that uses SOAP. • SOAP receiver • A SOAP node that receives the SOAP message and processes it. • SOAP intermediary • A SOAP node that acts as receiver and sender.

  21. Web Services-SOAP intermediary Ultimate receiver Client requests service intermediay Web Service resides in this node SOAP Message Path

  22. Web Services-SOAP • Intermediaries: • Can both accept and forward a message. • They can do some message processing. • Security domains are defined for the message.

  23. Web Services-SOAP • Message Exchange Patterns (MEP) • One way communication that specifies • How many messages are interchanged in a given transaction. • Originator of the message. • Ultimate receiver of the message. • Two types of MEP • Request-Response MEP, similar to POST in http. • Response MEP , similar to GET in http.

  24. Web Services-SOAP • A SOAP message consists of: • Envelope (mandatory) • It is the root element of the XML document • Header (Optional) • Passes application specific information. • It is used for transaction processing, authentication, login in. • Body (mandatory) • Actual application data to be transported. • Fault • Used to report errors back to sender

  25. Web Services-SOAP • <soap: envelope> <soap: header> <……………> </soap:header> <soap:body> <………………> <soap:fault> <…………….> </soap:fault> </soap:body> </soap:envelope>

  26. Web Services-SOAP • The header uses special elements like: <wsa (web services addressing) i.e. <wsa:ReplyTo><wsa:Address>http://MyBusiness/Client/ </wsa:Address></wsa:ReplyTo> <wsa:To>http://YourBusiness/purchasing</wsa:To> <wsa:Action>http://YourBusiness/SubmitPO</wsa:Action> • Message Exchange Pattern (MEP) type can be specified in the header.

  27. Web Services-SOAP • The body can be something like: <soap:Body wsu: ID=“Body”> <po:purchaseOrder xmlsn: po=http://YourBusiness/PO> <po:customer>………….</po:customer> <po:creditCardType>……..</po:creditCardType> <po:creditCardNumber>…….</po:creditCardNumber> </po:purchaseOrder> </soap:Body>

  28. Web Services-SOAP • SOAP data model follows a hierarchical tree of nodes in the structure of the elements. • Therefore we can have a Java program that creates the elements for the message , based on some tree structure.

  29. Web Services-SOAP Bill Eva 1000 streetNumber name name address address Person Address Person gender gender city state Female Male IL Chicago

  30. Web Services-SOAP • The java program can be: class Address { String city; String state; int streetNumber; public Address(int stNum, String c, String st) { this.streetNumber=stNum; this.city=c; this.state=st; } }

  31. Web Services-SOAP Class Person { String name; String gender; Address address; public Person(String n, String g, Address ad) { this.name=n; this.gender=g; this.Address=address; } }

  32. Web Services-SOAP • How Java is used in Web Services: • We can create XML documents in XML • We can use a Java parser to parse the XML document’ s elements. • The Java parser can use our DTD document a steh grammar file. • We can use a Java program based on JAXP API to read the XML elements and the data in the XML document.

  33. Web Services-JAXP API • JAXP (java API for XML Processing) has parsers for XML documents. • It provides a default parser. • Or it can be configured to use other parsers. • Can create a DTD programmatically. • Can create the XML document

  34. JAX-WS API • AX-WS stands for Java API for XML Web Services. • JAX-WS is a technology for building web services using XML. • It allows developers to write message-oriented as well as RPC-oriented web services. • In JAX-WS, a web service operation invocation is represented by an XML-based protocol such as SOAP

  35. JAX-WS API • JAX-WS API hides the SOAP complexity from the application developer. • On the server side, the developer specifies the web service operations by defining methods in an interface written in the Java programming language. • The developer also codes one or more classes that implement those methods.

  36. JAX-WS API • A client creates a proxy (a local object representing the service) and then simply invokes methods on the proxy. • The developer does not generate or parse SOAP messages. It is the JAX-WS runtime system that converts the API calls and responses to and from SOAP messages.

  37. JAX-WS API Just like in EE beans and JPA classes , annotations are used here also.

  38. JAX-WS API • package helloservice.endpoint; import javax.jws.WebService; @WebService public class Hello { private String message = new String("Hello, "); public void Hello() {} @WebMethod public String sayHello(String name) { return message + name + "."; } }

  39. JAX-WS API • In this example, the implementation class, Hello, is annotated as a web service endpoint using the @WebService annotation. • Hello declares a single method named sayHello, annotated with the @WebMethod annotation. • @WebMethod exposes the annotated method to web service clients. sayHello returns a greeting to the client, using the name passed to sayHello to compose the greeting. The implementation class also must define a default, public, no-argument constructor.

  40. JAX-WS API • When invoking the remote methods on the port, the client performs these steps: • Uses the generated helloservice.endpoint.HelloService class which represents the service at the URI of the deployed service’s WSDL file. • HelloService service = new HelloService(); • Retrieves a proxy to the service, also known as a port, by invoking getHelloPort on the service. • Hello port = service.getHelloPort();The port implements the SEI defined by the service. • Invokes the port’s sayHello method, passing to the service a name.

  41. JAX-WS API • package simpleclient; import javax.xml.ws.WebServiceRef; import helloservice.endpoint.HelloService; import helloservice.endpoint.Hello; public class HelloClient { public static void main(String[] args) { try { HelloClient client = new HelloClient(); client.doTest(args); } catch(Exception e) { e.printStackTrace(); } }

  42. JAX-WS API public void doTest(String[] args) { try { System.out.println("Retrieving the port from the following service: " + service); HelloService service = new HelloService(); Hello port = service.getHelloPort(); System.out.println("Invoking the sayHello operation on the port."); String name; if (args.length > 0) { name = args[0]; } else { name = "No Name"; } String response = port.sayHello(name); System.out.println(response); } catch(Exception e) { e.printStackTrace(); } }

  43. Web Services-WSDL • WSDL is used to describe the message syntax associated with the invocation and response of a web service. • It is an XML document that conforms to WSDL schema definition. • WSDL is to the web services what IDL is to RMI over IIOP and Corba.

  44. Web Services-WSDL • It describes 3 fundamental properties of a web service: • What a service does- that is the methods of the web service that can be invoked. • How a service is accessed- the data formats and protocols required to access the service. • Where a service is located- such as the URL for the service. • It has special elements to allow description of the above i.e <portType name=“PriceCheckPortType”> <operation name=”checkPrice”> <input message=“pc:PriceCheckRequest”/> <output message=“PriceCheckResponse”> </operation> </portType>

  45. Web Services-WSDL • Where message is modeled via the XML document. • It has a collection of elements. • A special element in WSDL called binding tells how to format the message (the XML elements) • The binding element tells how to invoke the operation using SOAP over HTTP (or some other protocol). • WSDL maps to Java via tools that automate the process. • A tool like that is WSDL2Java provided by Apache Axis. (AXIS = Apache eXtensible Interaction System) .

  46. Web Services-UDDI • UDDI facilitates service discovery • At design time (static discovery) • Or, at runtime (dynamic discovery). • UDDI makes reference to a specific WSDL document for the service. • UDDI uses its own elements to provide the description of the service. • You can use Java to do the registration or the discovery of the service. • A UDDI can be looked at as another web service. • It could be accomplished by using JAX (Java for XML ) API.

  47. UDDI Registry Links to WSDL Documents Publish Search Service Consumers Service Provider SOAP messages

  48. Study Guide • Chapter 16 of EE5 Tutorial • Or Chapters 11,12,13 of EE6 Tutorial

More Related