middleware for synchronous requests illustrated with ...€¦1.5 middleware for distributed objects...

59
Middleware for synchronous requests illustrated with WebServices Sophie Chabridon and Chantal Taconet CCN/CSC7321 octobre 2017 Revision : 528

Upload: dinhkhanh

Post on 21-Apr-2018

236 views

Category:

Documents


2 download

TRANSCRIPT

Page 1: Middleware for synchronous requests illustrated with ...€¦1.5 Middleware for distributed objects history ... Middleware for synchronous requests illustrated with WebServices 1 Introduction

# 1

Middleware for synchronousrequests illustrated with

WebServicesSophie Chabridon and Chantal Taconet

CCN/CSC7321octobre 2017

Revision : 528

Page 2: Middleware for synchronous requests illustrated with ...€¦1.5 Middleware for distributed objects history ... Middleware for synchronous requests illustrated with WebServices 1 Introduction

Middleware for synchronous requests illustrated with WebServices

# 2

Outline

1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22 Synchronous middleware and the big picture . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 123 WebService introduction. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .274 Interface definition language . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 325 Distributed Identification . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 406 First steps with WebServices. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .437 Conclusions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55

Télécom SudParis — INF — octobre 2017 — CCN/CSC7321 2/58

Page 3: Middleware for synchronous requests illustrated with ...€¦1.5 Middleware for distributed objects history ... Middleware for synchronous requests illustrated with WebServices 1 Introduction

Middleware for synchronous requests illustrated with WebServices:

Télécom SudParis — INF — octobre 2017 — CCN/CSC7321 2-1/58

Page 4: Middleware for synchronous requests illustrated with ...€¦1.5 Middleware for distributed objects history ... Middleware for synchronous requests illustrated with WebServices 1 Introduction

Middleware for synchronous requests illustrated with WebServices

# 3

1 Introduction

1.1 Middleware for distribution. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .41.2 Goal : interoperability. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .51.3 Distribution models. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .61.4 Client-server models . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 71.5 Middleware for distributed objects history . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81.6 Synchronous vs asynchronous mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 91.7 Asynchronous call, synchronous call, buffered message. . . . . . . . . . . . . . . . . . . . . . . . . .101.8 Call-back and Inversion of control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11

Télécom SudParis — INF — octobre 2017 — CCN/CSC7321 3/58

Page 5: Middleware for synchronous requests illustrated with ...€¦1.5 Middleware for distributed objects history ... Middleware for synchronous requests illustrated with WebServices 1 Introduction

Middleware for synchronous requests illustrated with WebServices 1 Introduction

# 4

1.1 Middleware for distribution

network

Middleware Middleware

Application Artefacts Application Artefacts

Middleware API Middleware API

Protocole du middleware

OS 2 API

Operating System 2System 1

Operating

OS1 API

HeterogeneousHeterogeneous

■ Middleware is a software layer which provides :♦ Programming interfaces (common API)♦ Protocol for interoperability

▶ With data exchange format

. . . to support distribution and heterogeneity.

Télécom SudParis — INF — octobre 2017 — CCN/CSC7321 4/58

Page 6: Middleware for synchronous requests illustrated with ...€¦1.5 Middleware for distributed objects history ... Middleware for synchronous requests illustrated with WebServices 1 Introduction

Middleware for synchronous requests illustrated with WebServices 1 Introduction

# 5

1.2 Goal : interoperability

■ Existing “legacy code”,

■ Numerous languages,

■ Several operating systems,

■ Various hardware (e.g., little endian, big endian),

■ Several network protocols

⇒ need for interoperability !

Télécom SudParis — INF — octobre 2017 — CCN/CSC7321 5/58

Page 7: Middleware for synchronous requests illustrated with ...€¦1.5 Middleware for distributed objects history ... Middleware for synchronous requests illustrated with WebServices 1 Introduction

Middleware for synchronous requests illustrated with WebServices 1 Introduction

# 6

1.3 Distribution models

■ Point to point message

■ Point to multipoint message

■ Event/action

■ Publish/subscribe

■ Client/server

■ Mobile code

■ Virtual shared memory

Télécom SudParis — INF — octobre 2017 — CCN/CSC7321 6/58

Page 8: Middleware for synchronous requests illustrated with ...€¦1.5 Middleware for distributed objects history ... Middleware for synchronous requests illustrated with WebServices 1 Introduction

Middleware for synchronous requests illustrated with WebServices 1 Introduction

# 7

1.4 Client-server models

■ Procedural♦ Remote Procedure Call - RPC

■ Object-oriented♦ Remote Method Invocation (RMI, Common Object Request Broker

Architecture CORBA)

■ Data-oriented♦ SQL requests♦ REST (Representational State Transfer)- create, read, update, delete over

HTTP

■ Traditionnal Web (HTTP requests)

■ Web Services (SOAP over HTTP)

Télécom SudParis — INF — octobre 2017 — CCN/CSC7321 7/58

Page 9: Middleware for synchronous requests illustrated with ...€¦1.5 Middleware for distributed objects history ... Middleware for synchronous requests illustrated with WebServices 1 Introduction

Middleware for synchronous requests illustrated with WebServices 1 Introduction

# 8

1.5 Middleware for distributed objects history

■ Comes from two technologies :♦ Objects (inheritance, encapsulation and polymorphism)♦ RPC or Remote Procedure Call (distribution, heterogeneity, data marshalling

and unmarshalling)

Télécom SudParis — INF — octobre 2017 — CCN/CSC7321 8/58

Page 10: Middleware for synchronous requests illustrated with ...€¦1.5 Middleware for distributed objects history ... Middleware for synchronous requests illustrated with WebServices 1 Introduction

Middleware for synchronous requests illustrated with WebServices 1 Introduction

# 9

1.6 Synchronous vs asynchronous mode

■ Two entities (e.g., processus) communicate

♦ In synchronous mode : the two entities (client and server) are active at thesame time, after a request, client is waiting for server response.

♦ In asynchronous mode : entities send messages, they don’t wait for responses,they don’t know when the message will be delivered

Télécom SudParis — INF — octobre 2017 — CCN/CSC7321 9/58

Page 11: Middleware for synchronous requests illustrated with ...€¦1.5 Middleware for distributed objects history ... Middleware for synchronous requests illustrated with WebServices 1 Introduction

Middleware for synchronous requests illustrated with WebServices 1 Introduction

# 10

1.7 Asynchronous call, synchronous call, buffered message

a:Process

request

wait

a:Process

send msg 3

send msg 2

send msg 1deliver msg 1

deliver msg 2

deliver msg 3

Systemm:MsgPassing

ask for a msg

ask for a msg

ask for a msg

a:Process

event/message

b:Process

requesthandler

reply

b:Process

event/messagehandler

b:Process

wait

Buffered messagesSynchronous callAsynchronous event(push) (pull)

Télécom SudParis — INF — octobre 2017 — CCN/CSC7321 10/58

Page 12: Middleware for synchronous requests illustrated with ...€¦1.5 Middleware for distributed objects history ... Middleware for synchronous requests illustrated with WebServices 1 Introduction

Middleware for synchronous requests illustrated with WebServices 1 Introduction

# 11

1.8 Call-back and Inversion of control

A:ProcessA:Process B:ProcessB:Process

callbackcallback

controlled by Bservice request for A

The service request for Ais triggered from the outsidethrough B, which controls A

service request

result

Inversion of controlSynchronous call with callback

A callback is first registeredand later called asynchronously.

The control flow is no more under the responsability ofthe application but controlled by the framework.

Télécom SudParis — INF — octobre 2017 — CCN/CSC7321 11/58

Page 13: Middleware for synchronous requests illustrated with ...€¦1.5 Middleware for distributed objects history ... Middleware for synchronous requests illustrated with WebServices 1 Introduction

Middleware for synchronous requests illustrated with WebServices

# 12

2 Synchronous middleware and the big picture

TCP/UDPsockets

Synchronous Distributed RequestsWebServices/JavaRMI/CORBA

BPELSCA

Activity Orchestrations

Application servers

− Life cycle (instantiate)

− Persistency

Structural Compositions

JavaEE

Distributed Event Based System

RabbitMQ

Télécom SudParis — INF — octobre 2017 — CCN/CSC7321 12/58

Page 14: Middleware for synchronous requests illustrated with ...€¦1.5 Middleware for distributed objects history ... Middleware for synchronous requests illustrated with WebServices 1 Introduction

Middleware for synchronous requests illustrated with WebServices 2 Synchronous middleware and the big picture

# 13

2.1 Introduction of the distributed example

Device1

*

Printer<< Interface >>

PrinterInterface

docName)+submitPrint (

PrinterClient

■ Which distribution ?■ Which abstractions (service, object) ?■ Which middleware ?

Télécom SudParis — INF — octobre 2017 — CCN/CSC7321 13/58

Page 15: Middleware for synchronous requests illustrated with ...€¦1.5 Middleware for distributed objects history ... Middleware for synchronous requests illustrated with WebServices 1 Introduction

Middleware for synchronous requests illustrated with WebServices 2 Synchronous middleware and the big picture

# 14

2.2 Principle of distributed objects

Automatic generationstub and skeleton

implementationclient

clientskeleton

implementation

client implementationskeleton

};j=RI.submitPrint() j=I.submitPrint()

Interface (contract)interface Printer { JobInfo submitPrint ();

stub

stubcommunicationmessages

Télécom SudParis — INF — octobre 2017 — CCN/CSC7321 14/58

Page 16: Middleware for synchronous requests illustrated with ...€¦1.5 Middleware for distributed objects history ... Middleware for synchronous requests illustrated with WebServices 1 Introduction

Middleware for synchronous requests illustrated with WebServices 2 Synchronous middleware and the big picture

# 15

2.3 The stub and the skeleton

clientproxy

marshallingarguments unmarshalling

arguments

marshalling results

unmarshallingresults

PIstub skeleton implementation

message

message

t=RPI.submitPrint();

I.submitPrint()

submitPrint()

Télécom SudParis — INF — octobre 2017 — CCN/CSC7321 15/58

Page 17: Middleware for synchronous requests illustrated with ...€¦1.5 Middleware for distributed objects history ... Middleware for synchronous requests illustrated with WebServices 1 Introduction

Middleware for synchronous requests illustrated with WebServices 2 Synchronous middleware and the big picture

# 16

2.4 Proxy Object and inheritance tree

■ Proxy : Representative for remote access

interface

submitPrint()Printer Interface

ClientsubmitPrint()

Printer Implementation

submitPrint()Printer Proxy

delegates

<<implements>>

Télécom SudParis — INF — octobre 2017 — CCN/CSC7321 16/58

Page 18: Middleware for synchronous requests illustrated with ...€¦1.5 Middleware for distributed objects history ... Middleware for synchronous requests illustrated with WebServices 1 Introduction

Middleware for synchronous requests illustrated with WebServices 2 Synchronous middleware and the big picture

# 17

2.5 Proxy design pattern

■ Context : A client needs access to a remote service provided by some entity(called the “servant”)

■ Problem♦ Define an access mechanism that does not involve

▶ Hard-coding the location of the servant into the client code▶ Deep knowledge of the communication protocols by the client

♦ Desirable properties▶ Access should be efficient at run-time and secure▶ Programming should be simple : No difference between local and remote

access♦ Constraints : Distributed environment (no single address space)

■ Solutions♦ Use a local representative of the server on the client side that isolates the

client from the communication system and the servant♦ Keep the same interface for the representative as for the servant♦ Define a uniform proxy structure to facilitate automatic generation

Télécom SudParis — INF — octobre 2017 — CCN/CSC7321 17/58

Page 19: Middleware for synchronous requests illustrated with ...€¦1.5 Middleware for distributed objects history ... Middleware for synchronous requests illustrated with WebServices 1 Introduction

2 Synchronous middleware and the big picture 2.5 Proxy design pattern

# 18

2.5.1 Sequence diagram of Proxy

s:Servant

service request

c:Client p:Proxy

service request

result

pre−processinge.g., marshalling

post−processing

result

e.g., unmarshalling

Interface I

Télécom SudParis — INF — octobre 2017 — CCN/CSC7321 18/58

Page 20: Middleware for synchronous requests illustrated with ...€¦1.5 Middleware for distributed objects history ... Middleware for synchronous requests illustrated with WebServices 1 Introduction

Middleware for synchronous requests illustrated with WebServices 2 Synchronous middleware and the big picture

# 19

2.6 Distribution Implementation Process

1. Description of the interface in IDL

2. IDL compiler creates the stub andthe skeleton

3. Write both client and serverimplementations

client implementation

skeletonstub

interface Printer {

}; JobInfo submitPrint (in string docName, out short docSize);

;

RPrint proxy; class Printer {

Printer S

};

t=proxy.submitPrint ();

(to write)

(automatic generation)

IDL compiler

IDL Interface (to write)

Télécom SudParis — INF — octobre 2017 — CCN/CSC7321 19/58

Page 21: Middleware for synchronous requests illustrated with ...€¦1.5 Middleware for distributed objects history ... Middleware for synchronous requests illustrated with WebServices 1 Introduction

Middleware for synchronous requests illustrated with WebServices 2 Synchronous middleware and the big picture

# 20

2.7 Multi-languages (or multi-ORBs, or multi-OSs)Interface IDL

};

interface Printer { Tache submitPrint ();

compile IDL −>C++ compile IDL −>Java

skeletonstubJavaC++

stubJava

skeletonC++

printer.submitPrint();

};

;

classPrinterImpl {

client Javaimplementation

C++

Télécom SudParis — INF — octobre 2017 — CCN/CSC7321 20/58

Page 22: Middleware for synchronous requests illustrated with ...€¦1.5 Middleware for distributed objects history ... Middleware for synchronous requests illustrated with WebServices 1 Introduction

Middleware for synchronous requests illustrated with WebServices 2 Synchronous middleware and the big picture

# 21

2.8 Distribution implications

■ Objects/service implementation are in different spaces (not the same process, notthe same computer . . . ) :♦ Assign a unique identifier to each object/service in different spaces♦ Localize objects/service implementations♦ Transports requests and replys♦ Use of a neutral network format for the data

Télécom SudParis — INF — octobre 2017 — CCN/CSC7321 21/58

Page 23: Middleware for synchronous requests illustrated with ...€¦1.5 Middleware for distributed objects history ... Middleware for synchronous requests illustrated with WebServices 1 Introduction

Middleware for synchronous requests illustrated with WebServices 2 Synchronous middleware and the big picture

# 22

2.9 Invocation sequence diagram

locate

locate

submitPrint()

forwardRequest()

invoke()submitPrint()

ClientProxy

marshall

unmarshall

ProxyServer

marshall

unmarshall

Implementationc:Client m:Printer m:Printer i:Printer

Broker Broker:Request :Request

receive()

receive()

Télécom SudParis — INF — octobre 2017 — CCN/CSC7321 22/58

Page 24: Middleware for synchronous requests illustrated with ...€¦1.5 Middleware for distributed objects history ... Middleware for synchronous requests illustrated with WebServices 1 Introduction

Middleware for synchronous requests illustrated with WebServices 2 Synchronous middleware and the big picture

# 23

2.10 Middleware for synchronous requests : main concepts

ORB 1 ORB2

IDL

InterfaceDefinitionLanguage

MiddlewareProtocol

Server

client

message

messaget=rPI.submitPrint();

submitPrint()

implementation

i.submitPrint()

stub skeleton

Télécom SudParis — INF — octobre 2017 — CCN/CSC7321 23/58

Page 25: Middleware for synchronous requests illustrated with ...€¦1.5 Middleware for distributed objects history ... Middleware for synchronous requests illustrated with WebServices 1 Introduction

Middleware for synchronous requests illustrated with WebServices 2 Synchronous middleware and the big picture

# 24

2.11 Inherent complexity of distribution

■ No global state

■ Poor debugging tools

■ Partial failures, network partition

■ Requests in parallel (concurrency management)

■ Trusting the caller (authentication)

Télécom SudParis — INF — octobre 2017 — CCN/CSC7321 24/58

Page 26: Middleware for synchronous requests illustrated with ...€¦1.5 Middleware for distributed objects history ... Middleware for synchronous requests illustrated with WebServices 1 Introduction

Middleware for synchronous requests illustrated with WebServices 2 Synchronous middleware and the big picture

# 25

2.12 Main distributed object middleware

CORBA (OMG) 1991Java RMI (Sun) 1997DCOM (Microsoft) 1998.net (Microsoft) 2001WebService (w3C) 2001

.net

Web Service

1985 1990 1995 2000 2005 2010

RPC

C++

COM

WWW

JAVA

XML

DCOM

CORBA JAVA RMI REST

Télécom SudParis — INF — octobre 2017 — CCN/CSC7321 25/58

Page 27: Middleware for synchronous requests illustrated with ...€¦1.5 Middleware for distributed objects history ... Middleware for synchronous requests illustrated with WebServices 1 Introduction

Middleware for synchronous requests illustrated with WebServices 2 Synchronous middleware and the big picture

# 26

2.13 Middleware history

OMG OTS−1994

JMS

TIBCO TIB

InformationBus−R−1992

Module Interconnection Language−R−1976

Nested transaction−R−1980

Recoverability−R−1988

Arjuna−R−1989

IBM EncinaBEA Tuxedo

EJB & JTA

JBoss ASIBM WebSphere

BEA WLS

Field−R−1987

DEC FUSE

DEC MQ

BEA MQ

Mesa−R−1979

RPC−R−1981

Cedar RPC−R−1984

Emerald−R−1987

Orca−R−1989

Network Objects−R−1993

RPC Systems

ONC ANSA

CORBA

RMI

RMI−R−1998

SOAP & WSDL

XML

SGML−R−1986

Scribe−R−1981

GML−R−1981

Eclipse WTPApache Axis

Microsoft .NET

Télécom SudParis — INF — octobre 2017 — CCN/CSC7321 26/58

Page 28: Middleware for synchronous requests illustrated with ...€¦1.5 Middleware for distributed objects history ... Middleware for synchronous requests illustrated with WebServices 1 Introduction

Middleware for synchronous requests illustrated with WebServices

# 27

3 WebService introduction

3.1 Web Services specified by W3C . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 283.2 Two classes of WebServices . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 293.3 Web Service Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 303.4 Some WebServices implementations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31

Télécom SudParis — INF — octobre 2017 — CCN/CSC7321 27/58

Page 29: Middleware for synchronous requests illustrated with ...€¦1.5 Middleware for distributed objects history ... Middleware for synchronous requests illustrated with WebServices 1 Introduction

Middleware for synchronous requests illustrated with WebServices 3 WebService introduction

# 28

3.1 Web Services specified by W3C

■ World Wide Web Consortium♦ International standards organization for the World Wide Web created in 1994♦ 2011 : 322 members♦ Famous standards : CSS, CGI, DOM, HTML, OWL, SOAP, XML, XPath,

WSDL

http://www.w3c.org

Télécom SudParis — INF — octobre 2017 — CCN/CSC7321 28/58

Page 30: Middleware for synchronous requests illustrated with ...€¦1.5 Middleware for distributed objects history ... Middleware for synchronous requests illustrated with WebServices 1 Introduction

Middleware for synchronous requests illustrated with WebServices 3 WebService introduction

# 29

3.2 Two classes of WebServices

■ REST Web Services♦ Web resources manipulated through a uniform set of operations

▶ POST (create resource), GET (read resource), PUT (update resource),DELETE (delete resource) -(CRUD)

■ Arbitrary Web Services♦ Services expose an arbitrary set of operations

Télécom SudParis — INF — octobre 2017 — CCN/CSC7321 29/58

Page 31: Middleware for synchronous requests illustrated with ...€¦1.5 Middleware for distributed objects history ... Middleware for synchronous requests illustrated with WebServices 1 Introduction

Middleware for synchronous requests illustrated with WebServices 3 WebService introduction

# 30

3.3 Web Service Overview

SOAP

SOAP

ORB 1 ORB2

WSDL

IPTCP

HTTP

IPTCP

SMTP

REST WS

IPTCP

HTTP

Specialized Web Server

WADLREST WS

Arbitrary WS

Arbitrary WS

client

message

message

stub skeleton

t=rPI.submitPrint();submitPrint()

implementation

i.submitPrint()

Télécom SudParis — INF — octobre 2017 — CCN/CSC7321 30/58

Page 32: Middleware for synchronous requests illustrated with ...€¦1.5 Middleware for distributed objects history ... Middleware for synchronous requests illustrated with WebServices 1 Introduction

Middleware for synchronous requests illustrated with WebServices 3 WebService introduction

# 31

3.4 Some WebServices implementations

Some platforms among a list of many many Web services platforms(http://en.wikipedia.org/wiki/List_of_web_service_frameworks)

JDK(>1.6) JAVA Implémentation de JAX-WS (Java API for XML Web Services)

METRO JAVA Uptodate implementation of JAX-WS (Oracle)

glassfish JAVA Implementation of JAX-WS + application server + JavaEE (Oracle)

gsoap C, C++ free software

php/soap php free software

.net C#, VB Microsoft

Télécom SudParis — INF — octobre 2017 — CCN/CSC7321 31/58

Page 33: Middleware for synchronous requests illustrated with ...€¦1.5 Middleware for distributed objects history ... Middleware for synchronous requests illustrated with WebServices 1 Introduction

Middleware for synchronous requests illustrated with WebServices

# 32

4 Interface definition language

4.1 Interface definition language . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 334.2 RMI IDL. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .344.3 WSDL : Web Service Definition Language - Concepts . . . . . . . . . . . . . . . . . . . . . . . . . . 354.4 WSDL 1.1 vs WSDL 2.0 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 364.5 WSDL PrintService example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 374.6 WSDL : PrintService - text file excerpt . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 384.7 Design methodologies . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39

Télécom SudParis — INF — octobre 2017 — CCN/CSC7321 32/58

Page 34: Middleware for synchronous requests illustrated with ...€¦1.5 Middleware for distributed objects history ... Middleware for synchronous requests illustrated with WebServices 1 Introduction

Middleware for synchronous requests illustrated with WebServices 4 Interface definition language

# 33

4.1 Interface definition language

■ To produce stub and skeletons, middleware use Interface Definition Languages♦ Independent of implementation languages♦ Independent of hardware and operating systems,♦ Independent of implementation (processus, databases, objects. . .

Télécom SudParis — INF — octobre 2017 — CCN/CSC7321 33/58

Page 35: Middleware for synchronous requests illustrated with ...€¦1.5 Middleware for distributed objects history ... Middleware for synchronous requests illustrated with WebServices 1 Introduction

Middleware for synchronous requests illustrated with WebServices 4 Interface definition language

# 34

4.2 RMI IDL

import java.rmi.Remote;import java.rmi.RemoteException;

public interface PrinterOperations extends Remote {PrinterInfo getPrinterInfo ( ) throws RemoteException;JobInfo submitPrint ( String fileName)

throws PrintDenied, RemoteException;};

■ RMI client/server are written in JAVA/JAVA♦ JAVA interface is the interface definition language

Télécom SudParis — INF — octobre 2017 — CCN/CSC7321 34/58

Page 36: Middleware for synchronous requests illustrated with ...€¦1.5 Middleware for distributed objects history ... Middleware for synchronous requests illustrated with WebServices 1 Introduction

Middleware for synchronous requests illustrated with WebServices 4 Interface definition language

# 35

4.3 WSDL : Web Service Definition Language - Concepts

■ A service may have several ports (operations are grouped in ports)■ Bindings define protocols, and URL to access a port■ Each operation is then defined by request, response and fault messages

WSDL 1.1 (source wikipedia)

Télécom SudParis — INF — octobre 2017 — CCN/CSC7321 35/58

Page 37: Middleware for synchronous requests illustrated with ...€¦1.5 Middleware for distributed objects history ... Middleware for synchronous requests illustrated with WebServices 1 Introduction

Middleware for synchronous requests illustrated with WebServices 4 Interface definition language

# 36

4.4 WSDL 1.1 vs WSDL 2.0

a

a. source wikipedia

Télécom SudParis — INF — octobre 2017 — CCN/CSC7321 36/58

Page 38: Middleware for synchronous requests illustrated with ...€¦1.5 Middleware for distributed objects history ... Middleware for synchronous requests illustrated with WebServices 1 Introduction

Middleware for synchronous requests illustrated with WebServices 4 Interface definition language

# 37

4.5 WSDL PrintService example

PortTypeOperationsService Binding

SOAP 1.1

SOAP 1.2

HTTP POST

Télécom SudParis — INF — octobre 2017 — CCN/CSC7321 37/58

Page 39: Middleware for synchronous requests illustrated with ...€¦1.5 Middleware for distributed objects history ... Middleware for synchronous requests illustrated with WebServices 1 Introduction

Middleware for synchronous requests illustrated with WebServices 4 Interface definition language

# 38

4.6 WSDL : PrintService - text file excerpt<wsdl:types> ... </wsdl:types><wsdl:message name="submitPrintRequest">

<wsdl:part element="tns:submitPrintRequest" name="parameters"/></wsdl:message><wsdl:message name="submitPrintResponse">

<wsdl:part element="tns:submitPrintResponse" name="return"/></wsdl:message><wsdl:message name="submitPrintFault">

<wsdl:part name="fault" element="tns:submitPrintFault"></wsdl:part></wsdl:message><wsdl:portType name="PrinterService"><wsdl:operation name="submitPrint">

<wsdl:input message="tns:submitPrintRequest"/><wsdl:output message="tns:submitPrintResponse"/>

<wsdl:fault name="fault" message="tns:submitPrintFault"></wsdl:fault></wsdl:operation><wsdl:operation name="getPrinterInfo">

<wsdl:input message="tns:getPrinterInfoRequest"></wsdl:input><wsdl:output message="tns:getPrinterInfoResponse"></wsdl:output>

</wsdl:operation></wsdl:portType><wsdl:binding name="PrinterInterfaceSoap11Binding"> ... </wsdl:binding><wsdl:service name="PrinterInterface"> ... </wsdl:service>

</wsdl:definitions>

Télécom SudParis — INF — octobre 2017 — CCN/CSC7321 38/58

Page 40: Middleware for synchronous requests illustrated with ...€¦1.5 Middleware for distributed objects history ... Middleware for synchronous requests illustrated with WebServices 1 Introduction

Middleware for synchronous requests illustrated with WebServices 4 Interface definition language

# 39

4.7 Design methodologies

■ Bottom-Up strategy (for example JAX-WS)

1. Write implementation classes/interface with java annotations(@webservice,@webmethod)

2. WSDL generating tool to expose some methods as a Web Service

■ Top-Down strategy

1. Write WSDL

2. Produce the class skeleton (methods to be completed)

Télécom SudParis — INF — octobre 2017 — CCN/CSC7321 39/58

Page 41: Middleware for synchronous requests illustrated with ...€¦1.5 Middleware for distributed objects history ... Middleware for synchronous requests illustrated with WebServices 1 Introduction

Middleware for synchronous requests illustrated with WebServices

# 40

5 Distributed Identification

5.1 Distributed Identification . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 415.2 Web Services URLs. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .42

Télécom SudParis — INF — octobre 2017 — CCN/CSC7321 40/58

Page 42: Middleware for synchronous requests illustrated with ...€¦1.5 Middleware for distributed objects history ... Middleware for synchronous requests illustrated with WebServices 1 Introduction

Middleware for synchronous requests illustrated with WebServices 5 Distributed Identification

# 41

5.1 Distributed Identification

■ Because of distribution, objects/services don’t share the same space■ How middleware are able to :

♦ Provide unique identifiers♦ Locate distributed entities♦ Transport messages to their destination

Télécom SudParis — INF — octobre 2017 — CCN/CSC7321 41/58

Page 43: Middleware for synchronous requests illustrated with ...€¦1.5 Middleware for distributed objects history ... Middleware for synchronous requests illustrated with WebServices 1 Introduction

Middleware for synchronous requests illustrated with WebServices 5 Distributed Identification

# 42

5.2 Web Services URLs

■ For each service port : a URL■ NB : the URL is included in the interface (defined in WSDL)

<wsdl:service name="PrinterService">

<wsdl:port<!−− name of the port−−>name="PrinterInterfaceHttpSoap11Endpoint"<!−− binding has been defined previously (contains protocol and data format) −−>binding="PrinterServiceSoapBinding"

<wsdlsoap:address<!−− port URL−−>

location="http://localhost:9000/PrinterService"/></wsdl:port>

</wsdl:service>

Télécom SudParis — INF — octobre 2017 — CCN/CSC7321 42/58

Page 44: Middleware for synchronous requests illustrated with ...€¦1.5 Middleware for distributed objects history ... Middleware for synchronous requests illustrated with WebServices 1 Introduction

Middleware for synchronous requests illustrated with WebServices

# 43

6 First steps with WebServices

6.1 Development steps . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 446.2 The printer manager example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 456.3 Automatic generation of stub and skeleton. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .466.4 Service side : describe the interface of the service . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 476.5 Service side : provide an implementation of the service . . . . . . . . . . . . . . . . . . . . . . . . . 486.6 JAX-WS annotations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 506.7 Service side : write the publisher . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 516.8 Start the service . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 526.9 Client side : generate the stub . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .536.10 Client side in java . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54

Télécom SudParis — INF — octobre 2017 — CCN/CSC7321 43/58

Page 45: Middleware for synchronous requests illustrated with ...€¦1.5 Middleware for distributed objects history ... Middleware for synchronous requests illustrated with WebServices 1 Introduction

Middleware for synchronous requests illustrated with WebServices 6 First steps with WebServices

# 44

6.1 Development steps

■ On the server side♦ Define the interface of the service with WSDL or with a java interface♦ Translate the WSDL to java interface or java interface to WSDL with an

appropriate tool♦ Deploy the implementation in a Web server (or write a server which

instantiates the service)

■ On the client side♦ Generate the Web Service stub from the URL of the deployed WSDL♦ Write and test the client

Télécom SudParis — INF — octobre 2017 — CCN/CSC7321 44/58

Page 46: Middleware for synchronous requests illustrated with ...€¦1.5 Middleware for distributed objects history ... Middleware for synchronous requests illustrated with WebServices 1 Introduction

Middleware for synchronous requests illustrated with WebServices 6 First steps with WebServices

# 45

6.2 The printer manager example

PrinterService (interface)

PrinterClient

(server)PrinterServer

Printer

hp

Télécom SudParis — INF — octobre 2017 — CCN/CSC7321 45/58

Page 47: Middleware for synchronous requests illustrated with ...€¦1.5 Middleware for distributed objects history ... Middleware for synchronous requests illustrated with WebServices 1 Introduction

Middleware for synchronous requests illustrated with WebServices 6 First steps with WebServices

# 46

6.3 Automatic generation of stub and skeleton

@webservice

</definitions>...

(automatic generation)

java InterfaceWSDL Interface

wsgen

(JAXB XML schema to java classes)

skeletonstub

(JAXB java classes to XML schema)

wsimport javac (includes JAX−WS compiler)

};

interface PrinterService { JobInfo submitPrint (in string fileName);

<type> <message> <operation> <binding> ....<?xml ...><definitions>

<portType name="PrinterService">

<operation name="submitPrint">

Télécom SudParis — INF — octobre 2017 — CCN/CSC7321 46/58

Page 48: Middleware for synchronous requests illustrated with ...€¦1.5 Middleware for distributed objects history ... Middleware for synchronous requests illustrated with WebServices 1 Introduction

Middleware for synchronous requests illustrated with WebServices 6 First steps with WebServices

# 47

6.4 Service side : describe the interface of the service

■ For example with a java interface

package printer;import javax.jws.WebService;@WebServicepublic interface PrinterService {

public PrinterInfo getPrinterInfo();public JobInfo submitPrint (String fileName) throws PrintDenied;

}

public final class PrinterInfo{

private String printerName = null;private String hostName = null;private int currentJob = (int)0;

...}

Télécom SudParis — INF — octobre 2017 — CCN/CSC7321 47/58

Page 49: Middleware for synchronous requests illustrated with ...€¦1.5 Middleware for distributed objects history ... Middleware for synchronous requests illustrated with WebServices 1 Introduction

Middleware for synchronous requests illustrated with WebServices 6 First steps with WebServices

# 48

6.5 Service side : provide an implementation of the servicepackage printer;import java.net.∗;import java.io.∗;import javax.jws.WebMethod;import javax.jws.WebService;import javax.jws.WebParam;

@WebService(endpointInterface="printer.PrinterService")public class Printer {

private short currentJob;private String printerName;private String hostName;public Printer(String name) {

printerName=name;try {

hostName=InetAddress.getLocalHost().getHostName();} catch (UnknownHostException u) {hostName="unknown computer";}

System.out.println(hostName+ ": Printer "+name+ " instantiation ");}public Printer() {this("hp");}

@WebMethod()public PrinterInfo getPrinterInfo() {

return new PrinterInfo(printerName, hostName, currentJob);}

Télécom SudParis — INF — octobre 2017 — CCN/CSC7321 48/58

Page 50: Middleware for synchronous requests illustrated with ...€¦1.5 Middleware for distributed objects history ... Middleware for synchronous requests illustrated with WebServices 1 Introduction

Middleware for synchronous requests illustrated with WebServices 6 First steps with WebServices

# 49

@WebMethod()public JobInfo submitPrint (@WebParam(name = "fileName", targetNamespace = "")String fileName) \

throws PrintDenied {// Open the file and get its sizeSystem.out.println("Printing document : "+ fileName + " on " + printerName);File file=new File(fileName);if (file==null) //throw new PrintDenied(new PrinterInfo(printerName, hostName, currentJob), \

fileName+" can't open file");throw new PrintDenied(fileName+" can't open file");

if ( ! file.isFile() ) //throw new PrintDenied(new PrinterInfo(printerName, hostName, currentJob), \fileName+" : is not a file");

throw new PrintDenied(fileName+" : is not a file");if (currentJob > 5) {

System.out.println("I am definitely overloaded, you must restart !");throw new PrintDenied("overloaded");

}currentJob++;

System.out.println("... "+ " size " + file.length()+ " Current Job : "+currentJob);return new JobInfo(currentJob, (int)file.length());

}}

Télécom SudParis — INF — octobre 2017 — CCN/CSC7321 49/58

Page 51: Middleware for synchronous requests illustrated with ...€¦1.5 Middleware for distributed objects history ... Middleware for synchronous requests illustrated with WebServices 1 Introduction

Middleware for synchronous requests illustrated with WebServices 6 First steps with WebServices

# 50

6.6 JAX-WS annotations■ @WebService Marks a Java class as implementing a Web Service, or a Java

interface as defining a Web Service interface.// Link the class and the interface@WebService(endpointInterface="printer.PrinterService")public class Printer {

■ @WebMethod : Customizes a method that is exposed as a Web Service operation.■ @OneWay : the web method has only an input message and no output■ @WebParam : Customizes the mapping of an individual parameter to a Web

Service message part and XML element■ @WebResult : Customizes the mapping of the return value to a WSDL part and

XML element.@WebMethod(operationName="add") // for different names in WSDL@WebResult(name="return")public int addNumbers(

@WebParam(name="num1")int number1,@WebParam(name="num2")int number2);

@OneWaypublic void checkIn(String name);

Télécom SudParis — INF — octobre 2017 — CCN/CSC7321 50/58

Page 52: Middleware for synchronous requests illustrated with ...€¦1.5 Middleware for distributed objects history ... Middleware for synchronous requests illustrated with WebServices 1 Introduction

Middleware for synchronous requests illustrated with WebServices 6 First steps with WebServices

# 51

6.7 Service side : write the publisherpackage printer;import javax.xml.ws.Endpoint;

public class PrinterServer {

protected PrinterServer() throws Exception {// START SNIPPET: publishSystem.out.println("Starting Server");Printer printer = new Printer();String address = "http://localhost:9000/PrinterService";Endpoint.publish(address, printer);// END SNIPPET: publish

}

public static void main(String args[]) throws Exception {new PrinterServer();System.out.println("Server ready...");

Thread.sleep(360 ∗ 60 ∗ 1000);System.out.println("Server exiting");System.exit(0);

}}

Télécom SudParis — INF — octobre 2017 — CCN/CSC7321 51/58

Page 53: Middleware for synchronous requests illustrated with ...€¦1.5 Middleware for distributed objects history ... Middleware for synchronous requests illustrated with WebServices 1 Introduction

Middleware for synchronous requests illustrated with WebServices 6 First steps with WebServices

# 52

6.8 Start the service

■ Compile everything■ Starts the publisher

java −cp class printer.PrinterServerPublisher

■ In a navigator, verify that the service is deployed♦ http://localhost:9000/PrinterService

■ And have a look on the wsdl♦ http://localhost:9000/PrinterService?wsdl

Télécom SudParis — INF — octobre 2017 — CCN/CSC7321 52/58

Page 54: Middleware for synchronous requests illustrated with ...€¦1.5 Middleware for distributed objects history ... Middleware for synchronous requests illustrated with WebServices 1 Introduction

Middleware for synchronous requests illustrated with WebServices 6 First steps with WebServices

# 53

6.9 Client side : generate the stub

■ Produce the stub from the URLhttp://localhost:9000/PrinterService?wsdl with wsimport

wsimport −d class −s generated −keep http://localhost:9000/PrinterService?wsdl

Télécom SudParis — INF — octobre 2017 — CCN/CSC7321 53/58

Page 55: Middleware for synchronous requests illustrated with ...€¦1.5 Middleware for distributed objects history ... Middleware for synchronous requests illustrated with WebServices 1 Introduction

Middleware for synchronous requests illustrated with WebServices 6 First steps with WebServices

# 54

6.10 Client side in java

■ Write, compile and test a clientimport printer.∗;public class PrinterClient {

public static void main (String [] args){try{

if ( args.length < 1) {System.out.println("usage: java ClassName" + " file_name");System.exit (−1);

}String fileToPrint=args[0];PrinterService printerService = new PrinterService_Service().getPrinterPort();PrinterInfo printerInfo=printerService.getPrinterInfo();System.out.println("Printer :"+printerInfo.getPrinterName()+" \n\t on machine " + \

printerInfo.getHostName() + " \n\t running task : " + printerInfo.getCurrentJob() + "\n");JobInfo jobInfo=printerService.submitPrint(fileToPrint);System.out.println("\n submitPrint("+fileToPrint+")"+"Job "+ jobInfo.getJobNumber()+": \

"+jobInfo.getJobSize()+ " bytes");}catch(Exception e) {System.out.println(e);}

}}

Télécom SudParis — INF — octobre 2017 — CCN/CSC7321 54/58

Page 56: Middleware for synchronous requests illustrated with ...€¦1.5 Middleware for distributed objects history ... Middleware for synchronous requests illustrated with WebServices 1 Introduction

Middleware for synchronous requests illustrated with WebServices

# 55

7 Conclusions

7.1 Comparison CORBA/RMI/WebServices . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 567.2 Conclusions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57

Télécom SudParis — INF — octobre 2017 — CCN/CSC7321 55/58

Page 57: Middleware for synchronous requests illustrated with ...€¦1.5 Middleware for distributed objects history ... Middleware for synchronous requests illustrated with WebServices 1 Introduction

Middleware for synchronous requests illustrated with WebServices 7 Conclusions

# 56

7.1 Comparison CORBA/RMI/WebServices

CORBA RMI Web Services

Origin OMG SUN W3C

OS multiples multiples multiples

Prog. language multiples Java multiples

IDL IDL CORBA interface Java WSDL

data presentation CDR Java serialisation SOAP Envelope

protocole IIOP / GIOP JRMP ou IIOP SOAP Protocol above HTTP, SMTP, ...

connexions connected connected short connexions

object references IOR (location independant) symbolic names/IP+port URL (included in WSDL)

naming service NS, trading RMI registry, JNDI UDDI, WSIL

main advantages services/efficiency easy to use in java messages auto described

main difficulties complex to learn Java/Java lack of services

Télécom SudParis — INF — octobre 2017 — CCN/CSC7321 56/58

Page 58: Middleware for synchronous requests illustrated with ...€¦1.5 Middleware for distributed objects history ... Middleware for synchronous requests illustrated with WebServices 1 Introduction

Middleware for synchronous requests illustrated with WebServices 7 Conclusions

# 57

7.2 Conclusions

■ Granularity of distribution variable (object, service),■ Complexity of distribution■ Synchronous request middleware is the necessary foundation to build higher level

middleware♦ Middleware services (e.g. name service, yellow pages)♦ Message Oriented Middleware (MOM) (asynchronous middleware)♦ Application servers♦ Component middleware♦ Compositions and orchestrations

Télécom SudParis — INF — octobre 2017 — CCN/CSC7321 57/58

Page 59: Middleware for synchronous requests illustrated with ...€¦1.5 Middleware for distributed objects history ... Middleware for synchronous requests illustrated with WebServices 1 Introduction

Middleware for synchronous requests illustrated with WebServices

# 58

References

[Kalin, 2010] Kalin, M. (2010). Java Web Services, Up and Running. O’Reilly.[Krakowiak, 2009] Krakowiak, S. (2009). Middleware Architecture with Patterns and Frameworks.

http ://sardes.inrialpes.fr/ krakowia/MW-Book/ (.)[Object-Managment-Group, 2002] Object-Managment-Group (July 2002). The Common Object Request Broker :

Architecture and Specification version 3.0. OMG Documents formal/02-06-01.

... and omg.org, w3c.org

Télécom SudParis — INF — octobre 2017 — CCN/CSC7321 58/58