Presentation is loading. Please wait.

Presentation is loading. Please wait.

1 Lecture 21 George Koutsogiannakis Summer 2011 CS441 CURRENT TOPICS IN PROGRAMMING LANGUAGES.

Similar presentations


Presentation on theme: "1 Lecture 21 George Koutsogiannakis Summer 2011 CS441 CURRENT TOPICS IN PROGRAMMING LANGUAGES."— Presentation transcript:

1 1 Lecture 21 George Koutsogiannakis Summer 2011 CS441 CURRENT TOPICS IN PROGRAMMING LANGUAGES

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

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

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). 4

5 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 6 Java Web Services Client Convert XML to Java Convert Java Type to XML Service 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. 7

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

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

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

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

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

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 ( ) 13

14 Web Services -XML Alternatively instead of attributes we can define nested elements: 43871 2009-04-21 1234 14

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

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

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

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

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). 19

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

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

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

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

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 24

25 Web Services-SOAP 25

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

27 Web Services-SOAP The body can be something like: …………. …….. ……. 27

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

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

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; } 30

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; } 31

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

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 33

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 34

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

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

37 JAX-WS API 37 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 + "."; } } 38

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

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

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(); } } 41

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(); } } 42

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

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 44

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). 45

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

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

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


Download ppt "1 Lecture 21 George Koutsogiannakis Summer 2011 CS441 CURRENT TOPICS IN PROGRAMMING LANGUAGES."

Similar presentations


Ads by Google