WS-REST 2011.
Second International Workshop on RESTful Design.
Chairs: Cesare Pautasso, Erik Wilde, Rosa Alarcon.
<br>
Hypermedia and Model-Driven Development Session. Olga Liskin, Leif Singer and Kurt Schneider.
Logging/Request Tracing in Distributed Environment
Teaching Old Services New Tricks: Adding HATEOAS Support as an Afterthought
1. Teaching Old Services New
Tricks: Adding HATEOAS Support
as an Afterthought
Olga Liskin, Leif Singer, Kurt Schneider
{olga.liskin, leif.singer, kurt.schneider}
@inf.uni-hannover.de
28.03.2011
2. Content
Motivation
Main Goals
Service Example
Terminology
Notation for Application Models
Conception of Wrapper Component
Comparison
Conclusions & Outlook
Teaching Old Services New Tricks – Olga Liskin, Leif Singer, Kurt Schneider 28.03.2011 2
3. Motivation
Problem with web service communication: Client needs to
know exactly, what a request has to look like
Many sources for errors
– Coding errors
– Invalid requests
Idea: Server includes request-information in response
messages
– Which requests allowed next
– What they look like
HATEOAS
But: not many services conform to this principle
Teaching Old Services New Tricks – Olga Liskin, Leif Singer, Kurt Schneider 28.03.2011 3
4. Motivation
Example:
Service response without HATEOAS:
HTTP/1.1 200 OK
What can the client
Last-Modified: Wed, 01 Dec 2010 17:36:02 GMT next?
do
Content-Type: application/xml
<task>
<id>208</id>
<name>create GUI</name> No idea. The client
<status>inprogress</status> has to know by
itself.
<parentStoryId>04</parentStoryId>
</task>
Teaching Old Services New Tricks – Olga Liskin, Leif Singer, Kurt Schneider 28.03.2011 4
5. Motivation
Example:
Service response with HATEOAS:
HTTP/1.1 200 OK
Last-Modified: Wed, 01 Dec 2010 17:36:02 GMT Control elements
Content-Type: application/xml directly present in
Link: <stories/04/tasks/208/finish>; rel=“finish” response message.
Link: <stories/04/tasks/208/block>; rel=“block”
<task>
<id>208</id> Now client can see
<name>create GUI</name> following requests
<status>inprogress</status> and how to make
them
<parentStory>/stories/04</parentStory>
</task>
…and also indicate
this
Teaching Old Services New Tricks – Olga Liskin, Leif Singer, Kurt Schneider 28.03.2011 5
6. Main Goals
Create HATEOAS support using state charts
– Automatically generate a wrapper
Service
Information
Generator/
Wrapper
Interpreter
Developer
Client Wrapper Server
Prerequisite: Clear way to model network-based applications
– State Charts
– Terminology
Teaching Old Services New Tricks – Olga Liskin, Leif Singer, Kurt Schneider 28.03.2011 6
7. Service Example
Backlog service: support agile development projects
Backlog
– contains story cards
Story Card
– One particular topic
– Different states
„definde“, „in progress“, „blocked“,…
Depend on included tasks
Task
– Story Card divided into tasks
– Different states
Changed by user
Teaching Old Services New Tricks – Olga Liskin, Leif Singer, Kurt Schneider 28.03.2011 7
9. Terminology
Valid requests depend on current application state
What exactly is application state?
Relevant terminology:
– application
„representation of the business-aware functionality of a system“ (Fielding)
– resource state
Values of a resource‘s attributes
– application state
Requests, responses and the processing of those
E.g.: „process detail view of a story card“
Teaching Old Services New Tricks – Olga Liskin, Leif Singer, Kurt Schneider 28.03.2011 9
10. Terminology
31
finished
Backlog 08
24
blocked
New idea: Story
– Equivalence classes of application states
Combine „similar“ states
Determined by resource class and resource state
Teaching Old Services New Tricks – Olga Liskin, Leif Singer, Kurt Schneider 28.03.2011 10
11. State Chart
States
– Equivalence classes of application states
– Composite States combine states with same resource class
Teaching Old Services New Tricks – Olga Liskin, Leif Singer, Kurt Schneider 28.03.2011 11
12. State Chart
Transitions
– Possible change of application state
triggered by new client request
– Target state reached in case of success
Transitions between Simple States
Teaching Old Services New Tricks – Olga Liskin, Leif Singer, Kurt Schneider 28.03.2011 12
13. State Chart
Transitions between Composite States
– More precise information about control flow
necessary
– Outgoing transition:
Transition possible from all sub-states
– Incoming transition:
Client requests a resource of
particular class
Sub-state can only be determined
at runtime
choice-pseudostate
Teaching Old Services New Tricks – Olga Liskin, Leif Singer, Kurt Schneider 28.03.2011 13
14. State Chart
Simplified notation
– Remove end vertex
– Remove choice pseudostate construct
Teaching Old Services New Tricks – Olga Liskin, Leif Singer, Kurt Schneider 28.03.2011 14
15. State Chart
Use State Chart as a static map
Teaching Old Services New Tricks – Olga Liskin, Leif Singer, Kurt Schneider 28.03.2011 15
16. 2 Constructing A Wrapper
Teaching Old Services New Tricks – Olga Liskin, Leif Singer, Kurt Schneider 28.03.2011 16
17. Wrapper - Conception
Top-Down view
– Wrapper at first as black-box
Insert wrapper between client and server
Request Request
Client Wrapper Server
HATEOAS-
Response Response
Response
– Request forwarded
– Response enriched with transitions
But not changed further
Teaching Old Services New Tricks – Olga Liskin, Leif Singer, Kurt Schneider 28.03.2011 17
18. Wrapper - Conception
Main process
Request Wrapper Request
Forward
request
1
Request Request
Enrich response Response
Calculate
application
state 2
application
state
<<datastore>> transitions Look up
Transition
model transitions
HATEOAS- 3
valid
Response
HATEOAS- transitions Response
Response
Construct
links
4
Teaching Old Services New Tricks – Olga Liskin, Leif Singer, Kurt Schneider 28.03.2011 18
19. Wrapper - Concrete Process Steps
Full process cycle
HTTP/1.1 200 OK
Last-Modified: Wed, 01 Dec 2010
Local-name(/*[1]) = task
Content-Type: application/xml
/task/status/text() = defined
<task>
<id>04</id>
<name>Update Database</name>
<status>defined</status>
<parentStory>08</parentStory>
</task>
HTTP/1.1 200 OK
/task/id/text() = 04
Last-Modified: Wed, 01 Dec 2010
URI-Templates /task/parentStory/text() = 08
Content-Type: application/xml
Link: </stories/08/tasks/04/block>;rel=”Task.block”
Link: </stories/08/tasks/04/begin>;rel=”Task.begin”
Link: </stories/08/tasks>; rel=”Task.allTasks”
Link: </stories/08>; rel=”belongs_to_story”
Task.block: </stories/08/tasks/04/block>
<task>
Task.begin: </stories/08/tasks/04/begin>
<id>04</id>
Task.allTasks: </stories/08/tasks>
<name>Update Database</name>
Belongs_To_Story: </stories/08>
<status>defined</status>
<parentStory>08</parentStory>
</task>
Teaching Old Services New Tricks – Olga Liskin, Leif Singer, Kurt Schneider 28.03.2011 19
20. Comparison
Implementation of backlog service
Automated generation of wrapper (from transition model)
Develop 2 clients to test concepts
– With wrapper <-> without wrapper
List links = if(story.getStatus().equals(StoryStatus
response.getHeaders().get("Link"); .Defined)){
for(String link : links){ this.startButton.setEnabled(true);
if(link.contains("story.start")){ this.startButton.setUri("/stories/"+
String uri = extractUri(link); story.getId() + "/start");
this.startButton.setUri(uri); this.blockButton.setEnabled(true);
this.startButton.setEnabled(true); this.blockButton.setUri("/stories/"+
}//... story.getId() + "/block")
} }
Teaching Old Services New Tricks – Olga Liskin, Leif Singer, Kurt Schneider 28.03.2011 20
21. Conclusions
Creation of theoretical concepts
Development of wrapper process
Check the concept
Is working
Generic
Improves development and maintainance of clients
Errors in model lead to invalid/missing links
Input data is complex
Teaching Old Services New Tricks – Olga Liskin, Leif Singer, Kurt Schneider 28.03.2011 21
22. Outlook
Further research on input of data
– Project environment
– Interface descriptions (e.g. WADL) as additional source
Allow changes of whole service API
– Can improve more REST aspects
Use state charts for creation of services (not only wrappers)
Teaching Old Services New Tricks – Olga Liskin, Leif Singer, Kurt Schneider 28.03.2011 22
23. Content
Motivation
Main Goals
Service Example
Terminology
Notation for Application Models
Conception of Wrapper Component
Comparison
Conclusions & Outlook
Questions?
Teaching Old Services New Tricks – Olga Liskin, Leif Singer, Kurt Schneider 28.03.2011 23