hy559 infrastructure technologies for large- scale service ...2011/03/11  · getting software •...

26
Tutorial on Web Services HY559 Infrastructure Technologies for Large- Scale Service-Oriented Systems Jason Polakis [email protected]

Upload: others

Post on 27-Jul-2020

0 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: HY559 Infrastructure Technologies for Large- Scale Service ...2011/03/11  · Getting Software • Either directly from given links, or: • In Ubuntu(as root) • To search for software

Tutorial on Web Services

HY559

Infrastructure Technologies for Large-

Scale Service-Oriented Systems

Jason Polakis

[email protected]

Page 2: HY559 Infrastructure Technologies for Large- Scale Service ...2011/03/11  · Getting Software • Either directly from given links, or: • In Ubuntu(as root) • To search for software

Required Software

•Eclipse IDE for Java developers EE

http://www.eclipse.org/downloads/

•Netbeans IDE

http://netbeans.org/downloads/

•Apache Tomcat•Apache Tomcat

http://tomcat.apache.org/

•Apache AXIS2

http://axis.apache.org/axis2/java/core/download.cgi

•Apache JUDDI

http://juddi.apache.org/releases.html

Page 3: HY559 Infrastructure Technologies for Large- Scale Service ...2011/03/11  · Getting Software • Either directly from given links, or: • In Ubuntu(as root) • To search for software

Getting Software

• Either directly from given links, or:

• In Ubuntu (as root)

• To search for software

– apt-cache search <program name>– apt-cache search <program name>

– Returns list of <packages> with short description

• To install software

– apt-get install <package>

– Installs software, as well as dependencies

Page 4: HY559 Infrastructure Technologies for Large- Scale Service ...2011/03/11  · Getting Software • Either directly from given links, or: • In Ubuntu(as root) • To search for software

Web Services

“Any piece of software that makes itself available over the Internet and uses a standardized XML messaging system”

•Extremely available

•Language and platform independent

•Distributed application components•Distributed application components

•Discoverable via a simple find mechanism

•Components of Web Services– SOAP (Simple Object Access Protocol)

– WSDL (Web Services Description Language)

– UDDI (Universal Description, Discovery and Integration)

Page 5: HY559 Infrastructure Technologies for Large- Scale Service ...2011/03/11  · Getting Software • Either directly from given links, or: • In Ubuntu(as root) • To search for software

Web Service Architecture

•Web Service Protocol Stack

–Service transport (transport messages between applications)

•HTTP, SMTP, FTP

–XML messaging (encode messages in common XML format )–XML messaging (encode messages in common XML format )

• XML-RPC, WS-Addressing, and SOAP

–Service description (describe public interface of service)

–Service discovery (centralize services into common registry)

•Programming models:

–REST-based web services

–SOAP-based web services

Page 6: HY559 Infrastructure Technologies for Large- Scale Service ...2011/03/11  · Getting Software • Either directly from given links, or: • In Ubuntu(as root) • To search for software

SOAP-based Services

•Use SOAP

–protocol for exchanging structured information

•Use WSDL

–xml-based language for describing Web services

•WSDL file

–created based on the JAVA code in the service–created based on the JAVA code in the service

–exposed on the net

•To use service, must create a client

–based on WSDL info

•Messages exchanged in SOAP

•Java API for XML Web Services (JAX-WS) model also used for SOAP services. Can use instead of AXIS2.

Page 7: HY559 Infrastructure Technologies for Large- Scale Service ...2011/03/11  · Getting Software • Either directly from given links, or: • In Ubuntu(as root) • To search for software

WSDL example

•Web service

•Single publicly available function sayHello•Single publicly available function sayHello

–argument: string

–return value: string

Page 8: HY559 Infrastructure Technologies for Large- Scale Service ...2011/03/11  · Getting Software • Either directly from given links, or: • In Ubuntu(as root) • To search for software

WSDL Definitions element<definitions name="HelloService"

targetNamespace="http://www.examples.com/wsdl/HelloService.wsdl"

xmlns="http://schemas.xmlsoap.org/wsdl/"

xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"

xmlns:tns="http://www.examples.com/wsdl/HelloService.wsdl"

xmlns:xsd="http://www.w3.org/2001/XMLSchema">

................................................

•container of all other elements

•specifies that this document is the HelloService

•Namespace: abstract container providing context -> logical grouping of code

•specifies a targetNamespace attribute (XML convention) → enables self reference

•specifies a default namespace

•specifies numerous namespaces that will be used

................................................

</definitions>

Page 9: HY559 Infrastructure Technologies for Large- Scale Service ...2011/03/11  · Getting Software • Either directly from given links, or: • In Ubuntu(as root) • To search for software

WSDL types

•Describes data types used

between client and server

•Uses W3C XML Schema

specification as default

<types>

<schema

targetNamespace="http://example.com/stockquote.xsd"

xmlns="http://www.w3.org/2000/10/XMLSchema">

<element name="TradePriceRequest">

<complexType>

<all>

<element name="tickerSymbol" type="string"/>

</all>specification as default

choice to define data types

•If the service uses only XML

Schema built-in simple

types, such as strings and

integers, then types element

is not required

</all>

</complexType>

</element>

<element name="TradePrice">

<complexType>

<all>

<element name="price" type="float"/>

</all>

</complexType>

</element>

</schema>

</types>

Page 10: HY559 Infrastructure Technologies for Large- Scale Service ...2011/03/11  · Getting Software • Either directly from given links, or: • In Ubuntu(as root) • To search for software

WSDL message

•<message>: describes the data exchanged between service providers and consumers

<message name="SayHelloRequest">

<part name="firstName" type="xsd:string"/>

</message>

<message name="SayHelloResponse">

<part name="greeting" type="xsd:string"/>

</message>

•<message>: describes the data exchanged between service providers and consumers

•Each Web Service has two messages: input and output

•Input: parameters for the Web Service

•Output: return data from the Web Service

•Each message contains zero or more <part> parameters, one for each parameter of

the function

•Each <part> parameter associates with a concrete type defined in the <types>

container element

Page 11: HY559 Infrastructure Technologies for Large- Scale Service ...2011/03/11  · Getting Software • Either directly from given links, or: • In Ubuntu(as root) • To search for software

WSDL portType element

•Basically, defines an interface: how unrelated objects communicate with

<portType name="Hello_PortType">

<operation name="sayHello">

<input message="tns:SayHelloRequest"/>

<output message="tns:SayHelloResponse"/>

</operation>

</portType>

•Basically, defines an interface: how unrelated objects communicate with each other

•"portType“ used to define one or multiple operations

•Operation: a sequence of messages to form an input-output pattern

•WSDL supports four basic patterns of operation

–One-way (input)

–Request-response (input, output)

–Solicit-response (output, input)

–Notification (output)

•Is an abstract definition

Page 12: HY559 Infrastructure Technologies for Large- Scale Service ...2011/03/11  · Getting Software • Either directly from given links, or: • In Ubuntu(as root) • To search for software

WSDL Binding Element

•Concrete implement. of

portType

•How portType operation will

be transmitted

•Where service is located

•name attribute defines the

name of the binding

<binding name="Hello_Binding" type="tns:Hello_PortType">

<soap:binding style="rpc"

transport="http://schemas.xmlsoap.org/soap/http"/>

<operation name="sayHello">

<soap:operation soapAction="sayHello"/>

<input>

<soap:body

encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"name of the binding

•type attribute points to the

port for the binding

•Binding: format of messages,

transport type (http)

•Operation: specifies that

soapAction HTTP header

identifies the service

•Body: specify the details of

the input and output messages

encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"

namespace="urn:examples:helloservice"

use="encoded"/>

</input>

<output>

<soap:body

encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"

namespace="urn:examples:helloservice"

use="encoded"/>

</output>

</operation>

</binding>

Page 13: HY559 Infrastructure Technologies for Large- Scale Service ...2011/03/11  · Getting Software • Either directly from given links, or: • In Ubuntu(as root) • To search for software

WSDL port<service name="Hello_Service">

<documentation>WSDL File for HelloService</documentation>

<port binding="tns:Hello_Binding" name="Hello_Port">

<soap:address

location="http://www.examples.com/SayHello/">

</port>

</service>

•<port> element defines individual endpoint. Specifies single address

for binding

•name attribute: unique name among all ports defined

•binding attribute: refers to binding element

</service>

Page 14: HY559 Infrastructure Technologies for Large- Scale Service ...2011/03/11  · Getting Software • Either directly from given links, or: • In Ubuntu(as root) • To search for software

WSDL service<service name="Hello_Service">

<documentation>WSDL File for HelloService</documentation>

<port binding="tns:Hello_Binding" name="Hello_Port">

<soap:address

location="http://www.examples.com/SayHello/">

</port>

</service>

•Defines ports supported by Web service

•Service element: a collection of ports

•For each supported protocol, there is one port element

•clients learn from service element –where to access the service

–through which port to access the Web service

•Human-readable documentation

•Binding attribute associates service with binding element

Page 15: HY559 Infrastructure Technologies for Large- Scale Service ...2011/03/11  · Getting Software • Either directly from given links, or: • In Ubuntu(as root) • To search for software

Apache Tomcat

•Open source servlet container

•HTTP web server environment for serving Java

Implements

•Java Servlet: class for responding to HTTP requests

–Create object that receives a request

–Generates responses based on requests

•JavaServer Pages (JSP): serve dynamically generated

web pages

–Java code interleaved with static web content

–Compiled and executed on server

–Resulting HTML or XML document served

Page 16: HY559 Infrastructure Technologies for Large- Scale Service ...2011/03/11  · Getting Software • Either directly from given links, or: • In Ubuntu(as root) • To search for software

Apache AXIS2

• Web service framework

• Will run over Tomcat

• SOAP / WSDL engine

• Also supports RESTful web services• Also supports RESTful web services

• Web service creation example

– http://netbeans.org/kb/docs/websvc/gs-axis.html#deploy_axis

– http://today.java.net/pub/a/today/2006/12/13/invoking-web-services-using-apache-axis2.html

Page 17: HY559 Infrastructure Technologies for Large- Scale Service ...2011/03/11  · Getting Software • Either directly from given links, or: • In Ubuntu(as root) • To search for software

Apache AXIS2

• Send SOAP messages

• Receive and process SOAP messages

• Create a Web service out of a plain Java class

• Create implementation classes for both the • Create implementation classes for both the

server and client using WSDL

• Easily retrieve the WSDL for a service

• Send and receive SOAP messages with

attachments

• Create or utilize a REST-based Web service

Page 18: HY559 Infrastructure Technologies for Large- Scale Service ...2011/03/11  · Getting Software • Either directly from given links, or: • In Ubuntu(as root) • To search for software

Netbeans IDE

•Creating an Axis2 “Hello World” Web Service

•First setup Axis2 and Tomcat

–http://netbeans.org/kb/docs/websvc/gs-

axis.html#setupaxis.html#setup

–http://netbeans.org/kb/docs/websvc/gs-

axis.html#axis_options_tomcat

Page 19: HY559 Infrastructure Technologies for Large- Scale Service ...2011/03/11  · Getting Software • Either directly from given links, or: • In Ubuntu(as root) • To search for software

Netbeans IDE exampleFile -> New Project

Name it AxisHello, click Finish

Right-click project node , context menu opens

choose New -> Other, Wizard opens

Page 20: HY559 Infrastructure Technologies for Large- Scale Service ...2011/03/11  · Getting Software • Either directly from given links, or: • In Ubuntu(as root) • To search for software

Netbeans IDE example

• Click Next, Name the Java class HelloAxisWorld.

• Name the package axishello. Click Finish.

• Application created.

Page 21: HY559 Infrastructure Technologies for Large- Scale Service ...2011/03/11  · Getting Software • Either directly from given links, or: • In Ubuntu(as root) • To search for software

Netbeans IDE example

Page 22: HY559 Infrastructure Technologies for Large- Scale Service ...2011/03/11  · Getting Software • Either directly from given links, or: • In Ubuntu(as root) • To search for software

Netbeans IDE example

• Time to deploy Axis2 web service to the server

• Right-click the web service's node -> Deploy to

Server

• Axis2 AAR file created, copied to .war file used by

serverserver

• To test service, expand web service node

• Right-click “hello: String” node. -> Test in Browser

Page 23: HY559 Infrastructure Technologies for Large- Scale Service ...2011/03/11  · Getting Software • Either directly from given links, or: • In Ubuntu(as root) • To search for software

Netbeans IDE example

• Browser opens, with test value for variables

Page 24: HY559 Infrastructure Technologies for Large- Scale Service ...2011/03/11  · Getting Software • Either directly from given links, or: • In Ubuntu(as root) • To search for software

Netbeans IDE example

• Change value and press Enter. Results change.

Page 25: HY559 Infrastructure Technologies for Large- Scale Service ...2011/03/11  · Getting Software • Either directly from given links, or: • In Ubuntu(as root) • To search for software

Netbeans IDE example

• Change Web Service Operation.

• Edit Java file in Editor.

• Save the Java file, Redeploy Web Service and

test!!!

Page 26: HY559 Infrastructure Technologies for Large- Scale Service ...2011/03/11  · Getting Software • Either directly from given links, or: • In Ubuntu(as root) • To search for software

Apache JUDDI

•XML-based registry for registering and locating web service applications

•Interact through SOAP, access WSDL documents

Link1, link2, link3