1 lecture 21 george koutsogiannakis summer 2011 cs441 current topics in programming languages

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

Upload: blanche-mason

Post on 26-Dec-2015

213 views

Category:

Documents


0 download

TRANSCRIPT

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

1

Lecture 21George Koutsogiannakis Summer 2011

CS441

CURRENT TOPICS IN PROGRAMMING LANGUAGES

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

Topics

• Web Services.– XML– SOAP– WSDL– UDDI

2

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

Web Services

• Two competing architectures.– .NET (Microsoft).– Sun’s Java Web Services.

• We will discuss Sun’s Web Services.

3

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

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

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

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 .

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

6

Java Web Services

Client

Convert XML to Java

Convert Java Type to XML

Service

Java Types Communicatiosn

XML messages communications

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

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

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

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

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

Web Services

• Other Protocols involved:– XML

• Custom made tags are used to structure the message.

– SOAP (Simple Object Access protocol)• Transfers the messages.

9

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

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

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

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

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

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

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

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>

13

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

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>

14

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

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

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

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

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

Web Services-XML

• The XML document then is made of 3 pieces:Called entities:

– Elements– Attributes– Data

17

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

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

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

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

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

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

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

Web Services-SOAP

21

Client requests service

intermediary intermediayUltimate

receiver

SOAP Message Path

Web Service resides in this node

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

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

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

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

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

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 sender24

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

Web Services-SOAP• <soap: envelope>

<soap: header> <……………> </soap:header> <soap:body> <………………> <soap:fault> <…………….> </soap:fault> </soap:body> </soap:envelope>

25

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

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.

26

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

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>

27

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

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

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

Web Services-SOAP

29

Person

Bill

name

Male

gender

Address

1000

IL Chicago

Person

Eva

Female

address address

streetNumber

state city

name

gender

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

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

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

Web Services-SOAPClass 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

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

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

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

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

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

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

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

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

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

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

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

JAX-WS API

37

Just like in EE beans and JPA classes , annotations are used here also.

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

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

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

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

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

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

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

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

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

JAX-WS APIpublic 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

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

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

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

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>

44

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

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

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

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

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

47

Service Provider

Links to WSDL Documents

Service Consumer

s

UDDI Registry

Publish Search

SOAP messages

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

Study Guide

• Chapter 16 of EE5 Tutorial• Or Chapters 11,12,13 of EE6 Tutorial

48