• No results found

WEB SERVICES WEB SERVICES

N/A
N/A
Protected

Academic year: 2021

Share "WEB SERVICES WEB SERVICES"

Copied!
12
0
0

Loading.... (view fulltext now)

Full text

(1)

1

WEB SERVICES

From Chapter 19 of Distributed Systems

Concepts and Design,4

th

Edition,

By G. Coulouris, J. Dollimore and T. Kindberg

Published by Addison Wesley/Pearson

Education June 2005

WEB SERVICES

2

Topics

• Introduccion

• Web Services

• SOAP (Simple Object Access Protocol)

Couloris,Dollimore and Kindberg Distributed Systems: Concepts & Design Edn. 4 , Pearson Education 2005

WEB SERVICES

Introduction

 Los servicios web son una manera de

interacción entre C/S mas general que

invocación de programas invocadas por el

browser.

 Los clientes acceden al servicio con el

mecanismo de pregunta/respuesta

(request/response) donde estas están

formateadas como XML y habitualmente

transferidas utilizando HTTP .

Couloris,Dollimore and Kindberg Distributed Systems: Concepts & Design Edn. 4 , Pearson Education 2005

(2)

4

Introduction

 Sirven para acceder servicios que se

encuentran en servidores ajenos y por

eso deberían de estar seguros.

 Transport Layer Security TLS no

proporciona la seguridad adecuada.

 XML security sirve mas.

 B2B services.

Couloris,Dollimore and Kindberg Distributed Systems: Concepts & Design Edn. 4 , Pearson Education 2005

WEB SERVICES

5

Introduction

Figure 1. Web services infrastructure and components

Couloris,Dollimore and Kindberg Distributed Systems: Concepts & Design Edn. 4 , Pearson Education 2005

WEB SERVICES

Introduction

 Marshalling de los mensajes en XML.

 Se identifica como URI (extension de URL)

 SOAP (Simple Object Access Protocol) Se

utiliza de modo habitual.

 SOAP se puede utilizar con HTTP/SMTP

etc.

 La descripcion de servicio proporciona la

definicion de la interfaz. Web Service

Description Language (WSDL).

Couloris,Dollimore and Kindberg Distributed Systems: Concepts & Design Edn. 4 , Pearson Education 2005

(3)

7

Web Services

 Una interfaz de SW consiste de un

conjunto de operaciones que el cliente

puede utilizar vía Internet.

 Pueden estar proporcionados de

diferentes formas (programas, objetos

remotos, bases de datos).

 Se puede manejar en paginas WEB o

puede estar totalmente separado de

paginas WEB.

Couloris,Dollimore and Kindberg Distributed Systems: Concepts & Design Edn. 4 , Pearson Education 2005

WEB SERVICES

8

Web Services

 Ejemplos: eBay.

 Amazon, Yahoo, Google.

 Amazon.com info de productos, compras.

Couloris,Dollimore and Kindberg Distributed Systems: Concepts & Design Edn. 4 , Pearson Education 2005

WEB SERVICES

Web Services

Combinacion de SW.

Couloris,Dollimore and Kindberg Distributed Systems: Concepts & Design Edn. 4 , Pearson Education 2005

(4)

10

Web Services

 Objetivo principal – hacer acceso mas fácil al

servicio.

 Nivel mas bajo – R/Wen SOAP, utilizando

XML.

Couloris,Dollimore and Kindberg Distributed Systems: Concepts & Design Edn. 4 , Pearson Education 2005

WEB SERVICES

11

SOAP (Simple Object Access Protocol)

 SOAP permite en una arquitectura C/S al

C y al S una interacción asíncrona (pero

también síncrona y de eventos).

 Esta definida como subnorma de XML

(esquema) para representar el los

mensajes contenido de

pregunta/respuesta.

 Inicialmente SOAP esta basado a HTTP,

pero se puede utilizar con varios TP:

SMTP, TCP o UDP.

 Coupling loose/no tanto.

Couloris,Dollimore and Kindberg Distributed Systems: Concepts & Design Edn. 4 , Pearson Education 2005

WEB SERVICES

SOAP (Simple Object Access Protocol)

SOAP is an XML based protocol for accessing Web

Services.

SOAP is a communication protocol

SOAP is for communication between applications

SOAP is a format for sending messages

SOAP communicates via Internet

(5)

WEB SERVICES

SOAP (Simple Object Access Protocol)

SOAP is platform independent

SOAP is language independent

SOAP is based on XML

SOAP is simple and extensible

SOAP allows you to get around firewalls

SOAP is a W3C recommendation

WEB SERVICES

SOAP (Simple Object Access Protocol)

 SOAP especifica:

 Como XML se utiliza en de representar

contenido de mensajes individuales.

 Como combinan la pregunta (request) y la

respuesta (reply).

 Como el recipiente tiene que interpretar

los elementos de XML.

 Como utilizar HTTP y SMTP para

comunicar msg. de SOAP.

Couloris,Dollimore and Kindberg Distributed Systems: Concepts & Design Edn. 4 , Pearson Education 2005

(6)

16

SOAP (Simple Object Access Protocol)

Mensaje del “sobre” de SOAP

Couloris,Dollimore and Kindberg Distributed Systems: Concepts & Design Edn. 4 , Pearson Education 2005

WEB SERVICES

17

SOAP (Simple Object Access Protocol)

 Headers establece el contexto, pero

también log y audit.

 El cuerpo (body) esta especifico para cada

servicio WEB.

Definición formal en SOAP XML namespace.

Couloris,Dollimore and Kindberg Distributed Systems: Concepts & Design Edn. 4 , Pearson Education 2005

WEB SERVICES

<SOAP-ENV:Envelope xmlns:SOAP- ENV="http://schemas.xmlsoap.org/soap/envelope/"

xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance"

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

<SOAP-ENV:Body>

<ns1:doGoogleSearch xmlns:ns1="urn:GoogleSearch"

SOAP- ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">

<key xsi:type="xsd:string">00000000000000000000000000000000</key>

<q xsi:type="xsd:string">lo que vamos a buscar google lo sabra</q>

<start xsi:type="xsd:int">0</start>

<maxResults xsi:type="xsd:int">10</maxResults>

<filter xsi:type="xsd:boolean">true</filter>

<restrict xsi:type="xsd:string"></restrict>

<safeSearch xsi:type="xsd:boolean">false</safeSearch>

<lr xsi:type="xsd:string"></lr>

<ie xsi:type="xsd:string">latin1</ie>

<oe xsi:type="xsd:string">latin1</oe>

</ns1:doGoogleSearch>

</SOAP-ENV:Body>

</SOAP-ENV:Envelope>

(7)

19

SOAP (Simple Object Access Protocol)

Ejemplo de request

Couloris,Dollimore and Kindberg Distributed Systems: Concepts & Design Edn. 4 , Pearson Education 2005

WEB SERVICES

<?xml version='1.0' encoding='UTF-8'?>

<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"

xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance"

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

<SOAP-ENV:Body>

<ns1:doGoogleSearchResponse xmlns:ns1="urn:GoogleSearch" SOAPENV:

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

<return xsi:type="ns1:GoogleSearchResult">

<documentFiltering xsi:type="xsd:boolean">false</documentFiltering>

<estimatedTotalResultsCount xsi:type="xsd:int">3</estimatedTotalResultsCount>

<directoryCategories xmlns:ns2="http://schemas.xmlsoap.org/soap/encoding/"

xsi:type="ns2:Array" ns2:arrayType="ns1:DirectoryCategory[0]"></directoryCategories>

<searchTime xsi:type="xsd:double">0.194871</searchTime>

<resultElements xmlns:ns3="http://schemas.xmlsoap.org/soap/encoding/"

xsi:type="ns3:Array" ns3:arrayType="ns1:ResultElement[3]">

<item xsi:type="ns1:ResultElement">

<cachedSize xsi:type="xsd:string">12k</cachedSize>

<hostName xsi:type="xsd:string"></hostName>

<snippet xsi:type="xsd:string"> &lt;b&gt;...&lt;/b&gt; on a simple dialog (via &lt;b&gt;teletype&lt;/b&gt;) with ... vintage 1970, and to

&lt;b&gt;...&lt;/b&gt;</snippet>

<directoryCategory xsi:type="ns1:DirectoryCategory">

<specialEncoding xsi:type="xsd:string"></specialEncoding>

<fullViewableName xsi:type="xsd:string"></fullViewableName>

</directoryCategory> ...

WEB SERVICES

SOAP (Simple Object Access Protocol)

Ejemplo reply

Couloris,Dollimore and Kindberg Distributed Systems: Concepts & Design Edn. 4 , Pearson Education 2005

(8)

22

SOAP (Simple Object Access Protocol)

 A transport protocol is required to send a

SOAP message to its destination.

 SOAP messages are independent of the

type of transport used- their envelopes

contain no reference to the destination

address.

Couloris,Dollimore and Kindberg Distributed Systems: Concepts & Design Edn. 4 , Pearson Education 2005

WEB SERVICES

23

SOAP (Simple Object Access Protocol)

 Figure 6 illustrates how the HTTP POST

method is used to transmit a SOAP

message.

Couloris,Dollimore and Kindberg Distributed Systems: Concepts & Design Edn. 4 , Pearson Education 2005

WEB SERVICES

SOAP (Simple Object Access Protocol)

Figure 6. Use of HTTP POST Request in SOAP client-server communication

Couloris,Dollimore and Kindberg Distributed Systems: Concepts & Design Edn. 4 , Pearson Education 2005

(9)

25

SOAP (Simple Object Access Protocol)

 The HTTP headers and body are used as

follows:

 The HTTP headers specify the endpoint

address (the URI of the ultimate receiver)

and the action to be carried out.

 The HTTP body carries the SOAP

message.

 As HTTP is a synchronous protocol, it is

used to return a reply containing the SOAP

reply, as shown in Figure 5.

Couloris,Dollimore and Kindberg Distributed Systems: Concepts & Design Edn. 4 , Pearson Education 2005

WEB SERVICES

WEB SERVICES

END (Java language)

Couloris,Dollimore and Kindberg Distributed Systems: Concepts & Design Edn. 4 , Pearson Education 2005

(10)

28

SOAP (Simple Object Access Protocol)

 Figure 7 shows a web service interface.

Couloris,Dollimore and Kindberg Distributed Systems: Concepts & Design Edn. 4 , Pearson Education 2005

WEB SERVICES

29

SOAP (Simple Object Access Protocol)

package ShapeListService;

import java.rmi.*;

public interface ShapeList extends Remote {

int newShape(GraphicalObject g) throws RemoteException;

int numberOfShapes()throws RemoteException;

int getVersion() throws RemoteException;

int getGOVersion(int i)throws RemoteException;

GraphicalObject getAllState(int i) throws RemoteException;

}

Figure 7. Java web service interface ShapeList

Couloris,Dollimore and Kindberg Distributed Systems: Concepts & Design Edn. 4 , Pearson Education 2005

WEB SERVICES

SOAP (Simple Object Access Protocol)

 The Java interface of a web service must

conform to the following rules, some of

which are illustrated in Figure 7:

 It must extend the Remote interface.

 It must not have constant declarations,

such as public final static.

 The methods must throw the

java.rmi.RemoteException or one of its

subclasses.

 Method parameters and return types must

be permitted JAX-RPC types.

Couloris,Dollimore and Kindberg Distributed Systems: Concepts & Design Edn. 4 , Pearson Education 2005

(11)

31

SOAP (Simple Object Access Protocol)

 The class that implements the interface

ShapeList is shown in Figure 8.

Couloris,Dollimore and Kindberg Distributed Systems: Concepts & Design Edn. 4 , Pearson Education 2005

WEB SERVICES

32

SOAP (Simple Object Access Protocol)

package ShapeListService;

import java.util.Vector;

public class ShapeListImpl implements ShapeList{

private Vector theList = new Vector();

private int version = 0;

private Vector theVersions = new Vector();

public ShapeListImpl(){

version = 0;

theVersions = new Vector();

}

public int newShape(GraphicalObject g) { version++;

theList.addElement(g);

theVersions.addElement(new Integer(version));

return theList.size();

}

public int numberOfShapes(){

return theList.size();

} public int getVersion() {

return version;

}

public int getGOVersion(int i){

return ((Integer) theVersions.elementAt(i)).intValue();

}

public GraphicalObject getAllState(int i) { return (GraphicalObject)theList.elementAt(i);

} }

Figure 8. Java implementation of the ShapeListserver

Couloris,Dollimore and Kindberg Distributed Systems: Concepts & Design Edn. 4 , Pearson Education 2005

WEB SERVICES

SOAP (Simple Object Access Protocol)

 There is no main method, and the

implementation of the ShapeList interface

does not have a constructor.

 In effect, a web service is a single object

that offers a set of procedures.

Couloris,Dollimore and Kindberg Distributed Systems: Concepts & Design Edn. 4 , Pearson Education 2005

(12)

34

SOAP (Simple Object Access Protocol)

 Figure 9 shows the ShapeList client main

a call through a proxy.

Couloris,Dollimore and Kindberg Distributed Systems: Concepts & Design Edn. 4 , Pearson Education 2005

WEB SERVICES

35

SOAP (Simple Object Access Protocol)

package staticstub;

import javax.xml.rpc.Stub;

public class ShapeListClient{

public static void main(String args[]){

try{

Stub stub = createProxy();

stub._setProperty

(javax.xml.rpc.Stub.ENDPOINT_ADDRESS_PROPERTY, args[0]);

aShapeList = (ShapeList) stub;

System.out.println("Got stub");

int n = aShapeList.numberOfShapes();

System.out.println("Number of shapes=" + n);

int v = aShapeList.getVersion();

System.out.println("Version=" + v);

Vector sList = new Vector(n);

for(int i=0; i<n; i++){

System.out.println("shape no =" + i);

GraphicalObject g = aShapeList.getAllState(i);

System.out.println("Got shape " + i);

int vers = aShapeList.getGOVersion(i);

sList.addElement(g);

System.out.println("Version number " + vers);

g.print();

}

Couloris,Dollimore and Kindberg Distributed Systems: Concepts & Design Edn. 4 , Pearson Education 2005

WEB SERVICES

SOAP (Simple Object Access Protocol)

GraphicalObject g = new GraphicalObject(shapeType,30, 40, 3300, 5500, true);

System.out.println("Created graphical object");

int listLength = aShapeList.newShape(g);

System.out.println("Stored shape " + shapeType);

}catch(Exception e) {System.out.println("allShapes: " + e.getMessage());

} }

private static Stub createProxy() { return

(Stub) (new MyShapeListService_Impl().getShapeListPort());

} }

Figure 9. Java implementation of the ShapeListclient

Couloris,Dollimore and Kindberg Distributed Systems: Concepts & Design Edn. 4 , Pearson Education 2005

References

Related documents

Paper Mill: Manufactured in France by Arjo Wiggins (BV-COC-008904) Recommended Label : Recycled (optional to add the 100% moebius loop) Delivery Note / Invoice Text: FSC

Aiming to study different poplar clones behaviour in the Andinean Valley of Barreal, placed in the province of San Juan, Argenti- na, in 1995 was set a trial with the following

complying with the following conditions: (a) provide its Lifeline customers with 911 and enhanced 911 (E911) access regardless of activation status and availability of

The York review team sought to correct the record and expressed their concern over statements by groups including the British Fluoridation Society, British Dental Association, and

Within the living organization of the private ESL school, the DOS must seek to provide inspirational motivation (Bass, 1985) by unifying teachers, students and other

Unlike central corneal haze following myopic PRK which can result in symptoms of glare, halos, loss of best spectacle- corrected visual acuity and contrast sensitivity, we did

The study of Nonnenberg and Mendonca (2004) finds that the factors such as the market size measured by GNP, growth rate of the product, the availability of skilled labor,

Two representative types of market regulation are analyzed: the introduction of compulsory duration clauses in tenancy contracts (as a means of protecting the tenant against