RESTful Service Composition with JOperathe integration logic of a mashup into a reusable service API...

56
RESTful Service Composition with JOpera Cesare Pautasso Faculty of Informatics, USI Lugano, Switzerland [email protected] http://www.pautasso.info http://twitter.com/pautasso 21.5.2010

Transcript of RESTful Service Composition with JOperathe integration logic of a mashup into a reusable service API...

Page 1: RESTful Service Composition with JOperathe integration logic of a mashup into a reusable service API and keep it separate from its UI made out of reusable widgets RESTful Web service

RESTful Service Composition with JOpera

Cesare PautassoFaculty of Informatics, USI Lugano, [email protected]://www.pautasso.infohttp://twitter.com/pautasso

21.5.2010

Page 2: RESTful Service Composition with JOperathe integration logic of a mashup into a reusable service API and keep it separate from its UI made out of reusable widgets RESTful Web service

AbstractNext generation Web services technologies challenge theassumptions made by current standards for process-basedservice composition. For example, most existing RESTfulWeb service APIs cannot natively be composed using theWS-BPEL standard. In this talk we apply the notion ofcomposition to RESTful services and discuss theconceptual relationship between business processes andstateful resources. Our goal is to enable lightweight accessto service compositions published with a RESTful API.We show that the uniform interface and the hyper-linkingcapabilities of RESTful services provide an excellentabstraction for publishing proceses as a resource andexposing in a controlled way the execution state of aservice composition.To do so, we present how to build a composite application(DoodleMap) out of some well-known, public and currentlyexisting RESTful service APIs.

©2009-2010 - Cesare Pautasso, Erik Wilde 2

Page 3: RESTful Service Composition with JOperathe integration logic of a mashup into a reusable service API and keep it separate from its UI made out of reusable widgets RESTful Web service

©2010 - Cesare Pautasso 3

We believe there is huge potential to marrying REST with workflow and BPM.

[…]Combined with the architecture of the Web, a workflow service can provide both a truly simple, portable, and flexible way to build workflow driven integrations and applications.

From REST-*

http

://w

ww.

jbos

s.or

g/re

stst

ar/s

peci

ficat

ions

/wor

kflo

w.ht

ml“

Page 4: RESTful Service Composition with JOperathe integration logic of a mashup into a reusable service API and keep it separate from its UI made out of reusable widgets RESTful Web service

©2010 - Cesare Pautasso 4

WS-BPEL Primitives

WebService<invoke>

WebService

<invoke>

<receive><reply>

<receive>

The workflow language natively supports the RPC or message-based connectors

Page 5: RESTful Service Composition with JOperathe integration logic of a mashup into a reusable service API and keep it separate from its UI made out of reusable widgets RESTful Web service

©2010 - Cesare Pautasso 5

WS-BPEL Primitives

WebService<invoke>

WebService

<invoke>

<receive><reply>

<receive> Easy to map this to HTTP!

Page 6: RESTful Service Composition with JOperathe integration logic of a mashup into a reusable service API and keep it separate from its UI made out of reusable widgets RESTful Web service

©2009-2010 - Cesare Pautasso, Erik Wilde 6

WSDL 2.0 HTTP Binding can wrap RESTful Web Services

BPEL and WSDL 2.0

(WS-BPEL 2.0 does not support WSDL 2.0)

Page 7: RESTful Service Composition with JOperathe integration logic of a mashup into a reusable service API and keep it separate from its UI made out of reusable widgets RESTful Web service

©2010 - Cesare Pautasso 7

RESTful APIs…

…do not use WSDL

Page 8: RESTful Service Composition with JOperathe integration logic of a mashup into a reusable service API and keep it separate from its UI made out of reusable widgets RESTful Web service

©2010 - Cesare Pautasso 8

WS-BPEL Primitives

WebService<invoke>

WebService

<invoke>

<receive><reply>

<receive> Easy to map this to HTTP?

We need something else

Page 9: RESTful Service Composition with JOperathe integration logic of a mashup into a reusable service API and keep it separate from its UI made out of reusable widgets RESTful Web service

©2010 - Cesare Pautasso 9

We believe there is huge potential to marrying REST with workflow and BPM. The HATEOAS (hypermedia and linking)

principal of REST is logically a dynamic state machine and fits very well with how workflow and BPM systems are designed. Combined with the architecture of the Web,

a workflow service can provide both a truly simple, portable, and flexible way to build workflow driven integrations and applications.

From REST-*

http

://w

ww.

jbos

s.or

g/re

stst

ar/s

peci

ficat

ions

/wor

kflo

w.ht

ml“

Page 10: RESTful Service Composition with JOperathe integration logic of a mashup into a reusable service API and keep it separate from its UI made out of reusable widgets RESTful Web service

©2009-2010 - Cesare Pautasso, Erik Wilde 10

Outline

1. Introduction to RESTful Web Services

2. DefiningRESTful Service Composition

3. JOpera Demo4. More than Mashups?

Page 11: RESTful Service Composition with JOperathe integration logic of a mashup into a reusable service API and keep it separate from its UI made out of reusable widgets RESTful Web service

©2010 - Cesare Pautasso 11

Web Services expose their data and functionality trough resources identified by URI

Uniform Interface Principle: Clients interact with resources through a fix set of verbs. Example HTTP:GET (read), POST (create), PUT (update), DELETE

Multiple representations for the same resource Hyperlinks model resource relationships and valid

state transitions for dynamic protocol description and discovery

REST in one slide

RPUT

DELETE

GET

POST

Page 12: RESTful Service Composition with JOperathe integration logic of a mashup into a reusable service API and keep it separate from its UI made out of reusable widgets RESTful Web service

©2009-2010 - Cesare Pautasso, Erik Wilde 12

Design Methodology1. Identify resources to be exposed as

services (e.g., yearly risk report, book catalog, purchase order, open bugs, polls and votes)

2. Model relationships (e.g., containment, reference, state transitions) between resources with hyperlinks that can be followed to get more details (or perform state transitions)

3. Define “nice” URIs to address the resources

4. Understand what it means to do a GET, POST, PUT, DELETE for each resource (and whether it is allowed or not)

5. Design and document resource representations

6. Implement and deploy on Web server7. Test with a Web browser

GET

PUT

POST

DELETE

/loan

/balance

/client

/book

/order ?

/soap

Page 13: RESTful Service Composition with JOperathe integration logic of a mashup into a reusable service API and keep it separate from its UI made out of reusable widgets RESTful Web service

©2009-2010 - Cesare Pautasso, Erik Wilde 13

Design SpaceM Representations (Variable)

Page 14: RESTful Service Composition with JOperathe integration logic of a mashup into a reusable service API and keep it separate from its UI made out of reusable widgets RESTful Web service

©2009-2010 - Cesare Pautasso, Erik Wilde 14

Simple Doodle API Example1. Resources:

polls and votes2. Containment Relationship:

GET

PUT

POST

DELETE

/poll

/poll/{id}

/poll/{id}/vote

/poll/{id}/vote/{id} ?

poll{id1}

3. URIs embed IDs of “child” instance resources

4. POST on the container is used to create child resources

5. PUT/DELETE for updating and removing child resources

{id2}

{id3}

vote

{id4}

{id5}

Page 15: RESTful Service Composition with JOperathe integration logic of a mashup into a reusable service API and keep it separate from its UI made out of reusable widgets RESTful Web service

©2009-2010 - Cesare Pautasso, Erik Wilde 15

Simple Doodle API Example1. Creating a poll

(transfer the state of a new poll on the Doodle service)

2. Reading a poll (transfer the state of the poll from the Doodle service)

POST /poll<options>A,B,C</options>

201 CreatedLocation: /poll/090331x

GET /poll/090331x

200 OK<options>A,B,C</options><votes href=“/vote”/>

/poll/poll/090331x/poll/090331x/vote

Page 16: RESTful Service Composition with JOperathe integration logic of a mashup into a reusable service API and keep it separate from its UI made out of reusable widgets RESTful Web service

©2009-2010 - Cesare Pautasso, Erik Wilde 16

Simple Doodle API Example Participating in a poll by creating a new vote sub-resource

POST /poll/090331x/vote<name>C. Pautasso</name><choice>B</choice>

201 CreatedLocation: /poll/090331x/vote/1

GET /poll/090331x

200 OK<options>A,B,C</options><votes><vote id=“1”><name>C. Pautasso</name><choice>B</choice></vote></votes>

/poll/poll/090331x/poll/090331x/vote/poll/090331x/vote/1

Page 17: RESTful Service Composition with JOperathe integration logic of a mashup into a reusable service API and keep it separate from its UI made out of reusable widgets RESTful Web service

©2009-2010 - Cesare Pautasso, Erik Wilde 17

Simple Doodle API Example Existing votes can be updated (access control headers not shown)

PUT /poll/090331x/vote/1<name>C. Pautasso</name><choice>C</choice>

200 OK

GET /poll/090331x

200 OK<options>A,B,C</options><votes><vote id=“/1”><name>C. Pautasso</name><choice>C</choice></vote></votes>

/poll/poll/090331x/poll/090331x/vote/poll/090331x/vote/1

Page 18: RESTful Service Composition with JOperathe integration logic of a mashup into a reusable service API and keep it separate from its UI made out of reusable widgets RESTful Web service

©2009-2010 - Cesare Pautasso, Erik Wilde 18

Simple Doodle API Example Polls can be deleted once a decision has been made

DELETE /poll/090331x

200 OK

GET /poll/090331x

404 Not Found

/poll/poll/090331x/poll/090331x/vote/poll/090331x/vote/1

Page 19: RESTful Service Composition with JOperathe integration logic of a mashup into a reusable service API and keep it separate from its UI made out of reusable widgets RESTful Web service

©2009-2010 - Cesare Pautasso, Erik Wilde 19

Real Doodle Demo• Info on the real Doodle API: http://doodle.com/xsd1/RESTfulDoodle.pdf

• Lightweight demo with Poster Firefox Extension:http://addons.mozilla.org/en-US/firefox/addon/2691

Page 20: RESTful Service Composition with JOperathe integration logic of a mashup into a reusable service API and keep it separate from its UI made out of reusable widgets RESTful Web service

©2010 - Cesare Pautasso 20

Different software connectors

RPC ESB

WWW

Page 21: RESTful Service Composition with JOperathe integration logic of a mashup into a reusable service API and keep it separate from its UI made out of reusable widgets RESTful Web service

©2009-2010 - Cesare Pautasso, Erik Wilde 21

REST Architectural Elements

User Agent Origin Server

Cache

Proxy

Gateway

Connector (HTTP)

Client/Server Layered CacheStateless Communication

Page 22: RESTful Service Composition with JOperathe integration logic of a mashup into a reusable service API and keep it separate from its UI made out of reusable widgets RESTful Web service

©2009-2010 - Cesare Pautasso, Erik Wilde 22

Basic Setup

User Agent Origin Server

HTTP

CachingUser Agent

Origin Server

HTTP

User Agent CachingOrigin Server

HTTP

Adding Caching

CachingUser Agent

CachingOrigin Server

HTTP

Page 23: RESTful Service Composition with JOperathe integration logic of a mashup into a reusable service API and keep it separate from its UI made out of reusable widgets RESTful Web service

©2009-2010 - Cesare Pautasso, Erik Wilde 23

Proxy or Gateway?

Client ProxyHTTP Origin Server

HTTP

Client GatewayHTTP

Origin ServerHTTP

Intermediaries forward (and may translate) requests and responses

A proxy is chosen by the Client (for caching, or access control)

The use of a gateway (or reverse proxy) is imposed by the server

Page 24: RESTful Service Composition with JOperathe integration logic of a mashup into a reusable service API and keep it separate from its UI made out of reusable widgets RESTful Web service

©2009-2010 - Cesare Pautasso, Erik Wilde 24

What about composition?

The basic REST design elements do not take composition into account

WS-BPEL is the standard Web service composition language. Business process models are used to specify how a collection of services is orchestrated into a composite service

Can we apply WS-BPEL to RESTful services?

User Agent Origin Server

HTTP

?

Origin Server

Origin Server

User Agent

HTTP

Page 25: RESTful Service Composition with JOperathe integration logic of a mashup into a reusable service API and keep it separate from its UI made out of reusable widgets RESTful Web service

©2010 - Cesare Pautasso 25

REST Scalability

Origin Server

Clients

Proxy/Gateway

One example of REST middleware is to help with the scalability of a server, which may need to service a very large number of clients

Cache

Page 26: RESTful Service Composition with JOperathe integration logic of a mashup into a reusable service API and keep it separate from its UI made out of reusable widgets RESTful Web service

©2010 - Cesare Pautasso 26

REST Composition

Origin Server

Clients

Proxy/Gateway

Composition shifts the attention to the client which should consume and aggregate from many servers

Page 27: RESTful Service Composition with JOperathe integration logic of a mashup into a reusable service API and keep it separate from its UI made out of reusable widgets RESTful Web service

©2010 - Cesare Pautasso 27

Servers

REST Composition

Origin Client

The “proxy” intermediate element which aggregates the resources provided by multiple servers plays the role of a composite RESTful service Can/Should we implement it with BPM?

CompositeRESTfulservice

Page 28: RESTful Service Composition with JOperathe integration logic of a mashup into a reusable service API and keep it separate from its UI made out of reusable widgets RESTful Web service

©2010 - Cesare Pautasso 28

Composite Resources

PUT

DELETE

GET

POST

PUT

DELETE

GET

POST

C

RPUT

DELETE

GET

POST

S

Page 29: RESTful Service Composition with JOperathe integration logic of a mashup into a reusable service API and keep it separate from its UI made out of reusable widgets RESTful Web service

©2010 - Cesare Pautasso 29

Composite Resources

StateR

StateS

C

R S

The composite resource only aggregates the state of its component resources

Page 30: RESTful Service Composition with JOperathe integration logic of a mashup into a reusable service API and keep it separate from its UI made out of reusable widgets RESTful Web service

©2010 - Cesare Pautasso 30

Composite Resources

StateR

StateS

StateC

C

R S

The composite resource augments (or caches) the state of its component resources

Page 31: RESTful Service Composition with JOperathe integration logic of a mashup into a reusable service API and keep it separate from its UI made out of reusable widgets RESTful Web service

©2010 - Cesare Pautasso 31

PUT

PUT

DELETE

DELETE

GET

GETPOST

POSTC

RS

LinkR

LinkS

Composite Representation

Composite Representation

Page 32: RESTful Service Composition with JOperathe integration logic of a mashup into a reusable service API and keep it separate from its UI made out of reusable widgets RESTful Web service

©2010 - Cesare Pautasso 32

Composite Representation

CompositeRepresentation

Origin Servers

Client

OriginServer

A composite representation is interpreted by the client that follows its hyperlinks and aggregates the state of the referenced component resources

Page 33: RESTful Service Composition with JOperathe integration logic of a mashup into a reusable service API and keep it separate from its UI made out of reusable widgets RESTful Web service

©2010 - Cesare Pautasso 33

Bringing it all together

CompositeRepresentation

Origin Servers

Client

CompositeRESTfulservice

A composite representation can be produced by a composite service too

Origin Servers

Page 34: RESTful Service Composition with JOperathe integration logic of a mashup into a reusable service API and keep it separate from its UI made out of reusable widgets RESTful Web service

©2010 - Cesare Pautasso 34

Doodle Map Example

CompositeRepresentation

Origin Servers

Client

CompositeRESTfulservice

Vote on a meeting place based on its geographic location

Origin Servers

Page 35: RESTful Service Composition with JOperathe integration logic of a mashup into a reusable service API and keep it separate from its UI made out of reusable widgets RESTful Web service

©2010 - Cesare Pautasso 35

Composite Resource

PUT

DELETE

GET

POST

PUT

DELETE

GET

POST

C

RPUT

DELETE

GET

POST

S

Page 36: RESTful Service Composition with JOperathe integration logic of a mashup into a reusable service API and keep it separate from its UI made out of reusable widgets RESTful Web service

©2010 - Cesare Pautasso 36

GET

DELETE

GET

POST

C

RPUT

DELETE

GET

POST

S

Composite Resource

Page 37: RESTful Service Composition with JOperathe integration logic of a mashup into a reusable service API and keep it separate from its UI made out of reusable widgets RESTful Web service

©2010 - Cesare Pautasso 37

Composite Representation

GET

DELETE

GET

POST

C

RPUT

DELETE

GET

POST

S

DMLinkG

LinkC

GETG

LinkD

Page 38: RESTful Service Composition with JOperathe integration logic of a mashup into a reusable service API and keep it separate from its UI made out of reusable widgets RESTful Web service

©2009-2010 - Cesare Pautasso, Erik Wilde 38

Demo

Page 39: RESTful Service Composition with JOperathe integration logic of a mashup into a reusable service API and keep it separate from its UI made out of reusable widgets RESTful Web service

©2009-2010 - Cesare Pautasso, Erik Wilde 39

Doodle Map Architecture

Web Browser WorkflowEngine

RESTfulWeb Services

APIsGET

POSTGET

REST

ful A

PI

Page 40: RESTful Service Composition with JOperathe integration logic of a mashup into a reusable service API and keep it separate from its UI made out of reusable widgets RESTful Web service

©2010 - Cesare Pautasso 40

DoodleMap Model

Page 41: RESTful Service Composition with JOperathe integration logic of a mashup into a reusable service API and keep it separate from its UI made out of reusable widgets RESTful Web service

©2010 - Cesare Pautasso 41

Viewpoints

DataFlow

ControlFlow

ServiceBindings

HTTPXPATH XSLTJAVA HTML …

Page 42: RESTful Service Composition with JOperathe integration logic of a mashup into a reusable service API and keep it separate from its UI made out of reusable widgets RESTful Web service

©2010 - Cesare Pautasso 42

ControlFlow

Control FlowDependency

Page 43: RESTful Service Composition with JOperathe integration logic of a mashup into a reusable service API and keep it separate from its UI made out of reusable widgets RESTful Web service

©2010 - Cesare Pautasso 43

ServiceBindings

HTTP

XPATH

XSLT

JAVA

HTML

Page 44: RESTful Service Composition with JOperathe integration logic of a mashup into a reusable service API and keep it separate from its UI made out of reusable widgets RESTful Web service

©2010 - Cesare Pautasso 44

DataFlow

Data Flow(Copy)

Page 45: RESTful Service Composition with JOperathe integration logic of a mashup into a reusable service API and keep it separate from its UI made out of reusable widgets RESTful Web service

©2010 - Cesare Pautasso 45

Was it just a mashup?

MashupREST

Composition

Mashup

(It depends on the definition of Mashup)

Page 46: RESTful Service Composition with JOperathe integration logic of a mashup into a reusable service API and keep it separate from its UI made out of reusable widgets RESTful Web service

©2010 - Cesare Pautasso 46

Read-only vs. Read/Write

Moving state around

PUT

DELETE

GET

POST

PUT

DELETE

GET

POST

C

RPUT

DELETE

GET

POST

S

Page 47: RESTful Service Composition with JOperathe integration logic of a mashup into a reusable service API and keep it separate from its UI made out of reusable widgets RESTful Web service

©2010 - Cesare Pautasso 47

Read-only vs. Read/write

Simply aggregating data

GET

GETC

RGET

S

Page 48: RESTful Service Composition with JOperathe integration logic of a mashup into a reusable service API and keep it separate from its UI made out of reusable widgets RESTful Web service

©2010 - Cesare Pautasso 48

UI vs. API Composition

Is your composition reusable?

CompositeRepresentation

Origin Servers

Client

CompositeRESTfulservice

Origin Servers

API

UI Reusable services vs. Reusable Widgets

Page 49: RESTful Service Composition with JOperathe integration logic of a mashup into a reusable service API and keep it separate from its UI made out of reusable widgets RESTful Web service

©2010 - Cesare Pautasso 49

Can you always do thisfrom a web browser?

Single-Origin Sandbox

Client

CompositeRESTfulservice

Origin Servers

Origin Servers

CompositeRepresentation

Page 50: RESTful Service Composition with JOperathe integration logic of a mashup into a reusable service API and keep it separate from its UI made out of reusable widgets RESTful Web service

©2010 - Cesare Pautasso 50

Security Policies on the client may not always allow it to aggregate data from multiple different sources

This will change very soon with HTML5

Single-Origin Sandbox

CompositeRepresentation

Client

CompositeRESTfulservice

N Origin Servers

1 Origin Server

Page 51: RESTful Service Composition with JOperathe integration logic of a mashup into a reusable service API and keep it separate from its UI made out of reusable widgets RESTful Web service

©2010 - Cesare Pautasso 51

Complementary

Mashup RESTComposition

Mashup

Read-OnlyRead/Write

APIUI

SituationalReusable

ServiceSandboxed

Page 52: RESTful Service Composition with JOperathe integration logic of a mashup into a reusable service API and keep it separate from its UI made out of reusable widgets RESTful Web service

©2010 - Cesare Pautasso 52

REST brings a new perspective and new problems to service composition RESTful services can be composed on the

server by defining composite resources and on the client with composite representations Composing RESTful services helps to put

the integration logic of a mashup into a reusable service API and keep it separate from its UI made out of reusable widgets RESTful Web service composition is

different than mashups, but both can be built using BPM tools like JOpera

GET http://www.jopera.org/

Conclusions

Page 53: RESTful Service Composition with JOperathe integration logic of a mashup into a reusable service API and keep it separate from its UI made out of reusable widgets RESTful Web service

©2009-2010 - Cesare Pautasso, Erik Wilde 53

References Roy Fielding, Architectural Styles and the Design of Network-based

Software Architectures, PhD Thesis, University of California, Irvine, 2000

Leonard Richardson, Sam Ruby, RESTful Web Services, O’Reilly, May 2007

Jim Webber, Savas Parastatidis, Ian Robinson, REST in Practice: Hypermedia and Systems Architecture, O‘Reilly, 2010

Subbu Allamaraju, RESTful Web Services Cookbook: Solutions for Improving Scalability and Simplicity, O’Reilly, 2010

Stevan Tilkov, HTTP und REST, dpunkt Verlag, 2009,http://rest-http.info/

Thomas Erl, Raj Balasubramanians, Cesare Pautasso, Benjamin Carlyle, SOA with REST, Prentice Hall, end of 2010

Martin Fowler, Richardson Maturity Model: steps toward the glory of REST,

http://martinfowler.com/articles/richardsonMaturityModel.html

Page 54: RESTful Service Composition with JOperathe integration logic of a mashup into a reusable service API and keep it separate from its UI made out of reusable widgets RESTful Web service

©2009-2010 - Cesare Pautasso, Erik Wilde 54

Self-References Cesare Pautasso, Olaf Zimmermann, Frank Leymann,

RESTful Web Services vs. Big Web Services: Making the Right Architectural Decision, Proc. of the 17th International World Wide Web Conference (WWW2008), Bejing, China, April 2008.

Cesare Pautasso and Erik Wilde. Why is the Web Loosely Coupled? A Multi-Faceted Metric for Service Design, Proc of the 18th International World Wide Web Conference (WWW2009), Madrid, Spain, April 2009.

Cesare Pautasso, BPEL for REST, Proc. of the 6th International Conference on Business Process Management (BPM 2008), Milan, Italy, September 2008.

Cesare Pautasso, RESTful Web Service Composition with JOpera, Proc. Of the International Conference on Software Composition (SC 2009), Zurich, Switzerland, July 2009.

Cesare Pautasso, Gustavo Alonso: From Web Service Composition to Megaprogramming In: Proceedings of the 5th VLDB Workshop on Technologies for E-Services (TES-04), Toronto, Canada, August 2004.

Page 55: RESTful Service Composition with JOperathe integration logic of a mashup into a reusable service API and keep it separate from its UI made out of reusable widgets RESTful Web service

©2009-2010 - Cesare Pautasso, Erik Wilde 55

Leonard Richardson, Sam Ruby, RESTful Web Services, O’Reilly, May 2007

Raj Balasubramanians, Benjamin Carlyle,Thomas Erl, Cesare Pautasso, SOA with REST, Prentice Hall, end of 2010

Page 56: RESTful Service Composition with JOperathe integration logic of a mashup into a reusable service API and keep it separate from its UI made out of reusable widgets RESTful Web service

©2009-2010 - Cesare Pautasso, Erik Wilde 56Abstract Submission: Friday, July 16, 2010