Co-funded by the European Union Semantic CMS Community Designing Semantic CMS – Part II Copyright...
-
Upload
bryana-ramsell -
Category
Documents
-
view
217 -
download
0
Transcript of Co-funded by the European Union Semantic CMS Community Designing Semantic CMS – Part II Copyright...
Co-funded by the European Union
Semantic CMS Community
Designing Semantic CMS – Part II
Copyright IKS Consortium1
LecturerOrganization
Date of presentation
www.iks-project.eu
Page:
Introduction of Content Management
Foundations of Semantic Web Technologies
Storing and Accessing Semantic Data
Knowledge Interaction and Presentation
Knowledge Representation and Reasoning
Semantic Lifting
Designing Interactive Ubiquitous IS
Requirements Engineering for Semantic CMS
Designing Semantic CMS
Semantifying your CMS
Part I: Foundations
Part II: Semantic Content Management
Part III: Methodologies
(2) (1)
(3)
(4)
(5)
(6)
(7)
(8)
(9)
(10)
www.iks-project.eu
Page:
What is this Lecture about?
We have seen ... ... how requirements for
semantic content management are defined in a systematic way.
... a list of industry needs.
What is missing? An efficient way to design an
architecture for a semantic CMS that meets the defined requirements
Copyright IKS Consortium
3
Designing Interactive Ubiquitous IS
Requirements Engineering for Semantic CMS
Designing Semantic CMS
Semantifying your CMS
Part III: Methodologies
(7)
(8)
(9)
(10)
www.iks-project.eu
Page:
How to design a semantic CMS?
Copyright IKS Consortium
4
Conceptual Reference
Architecture
Technical Architectural
Style
Part 1IKS Reference
Architecture
Part 2REST Architecture
What does the architecture of a
semantic CMS look like?
How can a semantic CMS be realized?
www.iks-project.eu
Page:
REST Architecture
Stateless server are easy to replicate – scalable architecture Caches are only possible in stateless communication
Copyright IKS Consortium
5
ClientsOriginServer
http
Gateway, Load
Balancer
C
+ Cache
C
C
Proxy
http
http
C
http
www.iks-project.eu
Page:
RESTful Interfaces
REST is based on uniform interfaces between the components of the architecture.
A RESTful interface has to fulfill the following constraints: Identification of resources Manipulation of resources through representations Self-descriptive messages Hypermedia as the engine of application state
Copyright IKS Consortium
6
Roy Thomas Fielding, Architectural Styles and the Design of Network-based Software Architectures, PhD Thesis, http://www.ics.uci.edu/~fielding/pubs/dissertation/top.htm, 2000
www.iks-project.eu
Page:
REST Applied to Web Technologies
Resource identification by applying REST toUniversal Resource Identifiers (URIs) http://upb.de
Self-descriptive messages and resource representation by using HTML, XML and JSON
Resource manipulation through representations by applying REST to HTTP HTTP POST to http://upb.de/news to create a new posting
Code-on-demand by using JavaScript Include JavaScript in HTML
Copyright IKS Consortium
7
www.iks-project.eu
Page:
Resource Oriented Architecture (ROA)
One fundamental concept of REST are resources Design web applications by focusing on resources and
applying ROA design principles A web service is a resource Each entity that is part of the web application is a resource
ROA applied to URI Each resource has a stable URI Map hierarchies of resources by using sub paths in URIs Use URI parameters to specify additional constraints on
the resource, for example:
/path/to/resource?param1=value1¶m2=value2 Copyright IKS Consortium
8
www.iks-project.eu
Page:
ROA applied to URI Bank
http://www.bank.de/ All clients of the bank
http://www.bank.de/clients Single client identified by client number
http://www.bank.de/clients/815 All accounts of client 815
http://www.bank.de/clients/815/accounts Single account number 4538734 of client 815
http://www.bank.de/clients/0815/accounts/4538734 Balance of account 4538734 of client 815
http://www.bank.de/clients/815/accounts/4538734/balance
Copyright IKS Consortium
9
Bank
Client
Account
Balance
*
*
1
clients
accounts
balance
www.iks-project.eu
Page:
REST applied to HTTP Meta-data are stored in the header as
name-value pairs, for example Language information Data format Cache control User name, security token
Payload is transported in the HTTP
body, for example a SOAP message when using standard
web services a JSON string in case of lightweight
web servicesCopyright IKS Consortium
10
HTTP Message
HTTP Header
Name = ValueName = Value
HTTP Body
0101010101010
www.iks-project.eu
Page:
Representation of Resources Each resource has its URI By accessing the URI the resource can be retrieved in
different representations (formats) HTTP uses content negotiation with the accept-*
header for this, for example
Copyright IKS Consortium
11
GET /clients/0815Host: bank.deAccept: text/htmlAccept-Language: de, en
Returns a HTML representation of the client 0815. Preferred languages are first German then English.
GET /clients/0815Host: bank.deAccept: application/jsonAccept-Language: en, de
Returns a JSON representation of the client 0815. Preferred languages are first English then German.
www.iks-project.eu
Page:
HTTP Content Negotiation A HTTP Request supports four Accept-* fields
Accept: List of accepted media types Accept-Charset: List of accepted character sets and
character encodings, respectively. Accept-Encoding: List of accepted encodings of the
content. Accept-Language: List of accepted languages.
The values are comma separated lists of weighted properties, for example Accept-Language: de, en;q=0.5, fr;q=0.2 Client accepts German, English, and French with
German weighted as 1, English 0.5, and French 0.2
Copyright IKS Consortium
12
For further reading have a look at the Internet Engineering Task Force (IETF)“httpbis” working group page: http://datatracker.ietf.org/wg/httpbis/
www.iks-project.eu
Page:
HTTP Media Types
text/* for text data, e.g. html image/* for image data, e.g. gif video/* for video files, e.g. mpeg audio/* for audio files, e.g. mp3 application/* for not interpreted binary data, e.g. xml, json
application/vnd.* for vendor specific formats, e.g. ms-excel
application/x-* for non-standard files, e.g. latex application/x-pkcs* for (public key) cryptographic files
multipart/* for data in multiple parts, e.g. form-data message/* for messages, e.g. e-mail format rfc-822 model/* for data with multidimensional structure, e.g. vrml
Copyright IKS Consortium
13
www.iks-project.eu
Page:
Manipulation of Resources via HTTP
Use HTTP methods to access and manipulate resources.
Standard web services only use HTTP POST and GET to send SOAP messages, but there is more OPTIONS – to request information about the communication
options available to a given URI HEAD – is identical to GET but the server must not return a
message-body in the response PUT – to store the enclosed resource under the request URI DELETE – to delete the resource identified by the request URI TRACE – to see what is being received at the other end of the
request chain and use that e.g. for testing
Copyright IKS Consortium
14
www.iks-project.eu
Page:
Example REST Call
Request
Response
Copyright IKS Consortium
15
POST http://www.bank.de/clients/815/accounts/4538734/balance
HTTP-Header:Accept: application/json
HTTP-Body: { “amount” : -100}
HTTP-Header:Content-type: application/json
HTTP-Body: { “balance” : -500}
Resource identified by URIHTTP Operation
Parameter
Return value
Format
Format
www.iks-project.eu
Page:
Idempotent HTTP Methods
Idempotence:The side-effects of N > 0 identical requests is the same as for a single request.
Idempotent HTTP methods are GET, HEAD, PUT, DELETE
Methods that must not have any side effects, and so are inherently idempotent OPTIONS and TRACE
Note, a sequence of requests may not be idempotent even if all used methods in that sequence are idempotent
Copyright IKS Consortium
16
Source: RFC-2616 http://www.w3.org/Protocols/rfc2616/rfc2616.html
www.iks-project.eu
Page:
REST from the Command Line
cURL tool available for all major platforms On Windows you may need Microsoft Visual C++ 2010
Redistributable Package cURL is a command line tool for transferring data with
URL syntax Examples:
GET a resource
GET resource as XML
POST to a resource
Copyright IKS Consortium
17
curl http://host.de/path/to/resource
curl –H "Accept: application/xml" http://host.de/resource
curl -d "name=Smith" http://host.de/resource
Download at http://curl.haxx.se/
www.iks-project.eu
Page:
HTTP OPTIONS
Reponses are not cacheable Example: Check OPTIONS of http://apache.org
Copyright IKS Consortium
18
curl –i –X OPTIONS http://apache.org
HTTP/1.1 200 OKDate: Thu, 10 Nov 2011 12:50:12 GMTServer: Apache/2.3.15-dev (Unix)Allow: GET,HEAD,POST,OPTIONS,TRACECache-Control: max-age=3600Expires: Thu, 10 Nov 2011 13:50:12 GMTContent-Length: 0Content-Type: text/html; charset=utf-8
Supported HTTP methods
no side-effects
Source: RFC-2616 http://www.w3.org/Protocols/rfc2616/rfc2616.html
www.iks-project.eu
Page:
HTTP GET
Retrieve whatever information (in the form of an entity) is identified by the request URI.
If the URI refers to a data-producing process (service), the returned information is the produced data (not the service).
Cacheable Possibility of conditional GET by header
If-Modified-Since, If-Unmodified-Since, If-Match, …
Example: Get website if modified since November 10, 2011 - 2:30 pm
Copyright IKS Consortium
19
idempotent
curl -i -H "If-Modified-Since: Thu, 10 Nov 2011 14:30:00 GMT" \http://apache.orgHTTP/1.1 304 Not Modified
Source: RFC-2616 http://www.w3.org/Protocols/rfc2616/rfc2616.html
www.iks-project.eu
Page:
HTTP HEAD
The HEAD method is identical to GET except that the server MUST NOT return a message-body in the response.
Often used for testing hypertext links for validity, accessibility, and recent modification.
Copyright IKS Consortium
20
idempotent
curl -i –X HEAD http://www.uni-paderborn.de
HTTP/1.1 200 OKServer: ApacheSet-Cookie: fe_typo_user=cdb2bbfa6be0c06c41c2d050d2492bb4;curl -i –X HEAD http://google.de
HTTP/1.1 301 Moved PermanentlyLocation: http://www.google.de/Expires: Sat, 10 Dec 2011 15:07:42 GMTCache-Control: public, max-age=2592000Server: gws
Source: RFC-2616 http://www.w3.org/Protocols/rfc2616/rfc2616.html
www.iks-project.eu
Page:
HTTP PUT
Use PUT to create a resource at a given URI The PUT method requests that the enclosed entity be
stored under the supplied Request-URI. Different meaning of URI in POST and PUT
POST: URI identifies resource to handle the request PUT: URI identifies entity enclosed with the request
Return codes: New resource created (201 Created) Existing resource modified (200 OK or 204 No Content) Request applied to different URI than specified by the
Request-URI (301 Moved Permanently)Copyright IKS Consortium
21
idempotent
Source: RFC-2616 http://www.w3.org/Protocols/rfc2616/rfc2616.html
www.iks-project.eu
Page:
HTTP POST
Accept an entity as a new subordinate of the resource identified by the URI. Use to cover the following functions: Annotation of existing resources Posting a message to a bulletin board, newsgroup, mailing list,
or similar group of articles Providing a block of data, such as the result of submitting a
form, to a data-handling process Extending a database through an append operation.
Example to post a message with topic “Test” and text “Hello World”:
Copyright IKS Consortium
22
curl -d "topic=Test&text=Hello%20World" \http://some.host.com/messages
URL encoded string
Source: RFC-2616 http://www.w3.org/Protocols/rfc2616/rfc2616.html
www.iks-project.eu
Page:
HTTP DELETE
The DELETE method requests that the origin server delete the resource identified by the Request-URI.
Deletion can mean to move the resource to inaccessible location.
Responses are not cacheable. Return codes Delete successful (200 OK) Delete accepted but not enacted yet (202 Accepted) Delete enacted but no entity in response (204 No Content)
Copyright IKS Consortium
23
Source: RFC-2616 http://www.w3.org/Protocols/rfc2616/rfc2616.html
idempotent
curl -i –X DELETE http://google.de
HTTP/1.1 405 Method Not AllowedServer: GFE/2.0
www.iks-project.eu
Page:
HTTP TRACE
The TRACE method is used to invoke a remote, application-layer loop-back of the request message.
A TRACE request MUST NOT include an entity. The final recipient is either the origin server or the first
proxy or gateway TRACE allows the client to see what is being received
at the other end of the request chain and use that data for testing or diagnostic information.
For security reasons most web servers don’t allow this.
Copyright IKS Consortium
24
no side-effects
Source: RFC-2616 http://www.w3.org/Protocols/rfc2616/rfc2616.html
www.iks-project.eu
Page:
Mismatches between REST and HTTP
Cookies Back-button confusion if application state is stored in cookie. Allow data to be passed without sufficiently identifying its
semantics. Becoming a concern for both security and privacy. Possibility to track users as they browse between sites.
Mandatory Extensions HTTP header field names can be extended at will, but only when
the information they contain is not required for proper understanding of the message.
By extending the header with mandatory fields that need to be interpreted to understand the message – the REST concept is broken.
Copyright IKS Consortium
25
www.iks-project.eu
Page:
WADL – Web Application Description Language GET http://www.bank.de/application.wadl
Describing REST Interfaces
Copyright IKS Consortium
26
Source and further reading: http://www.w3.org/Submission/wadl/
<?xml version="1.0" encoding="UTF-8"?><application xmlns="http://wadl.dev.java.net/2009/02"> <resources base="http://www.bank.de/"> <resource path="/clients/{cid}"> <param name="cid" style="template" type="xsd:int" /> <method name="GET"> <response> <representation mediaType="application/xml"/> <representation mediaType="application/json"/> </response> </method> </resource> </resources></application>
Resource
Operation
Supported response formats
Parameter type
Parameter
www.iks-project.eu
Page:
REST API Example: Twitter
Twitter REST API for getting followers GET followers/ids Returns an array of numeric IDs for every user following
the specified user. Resource URL
Parameters: user_id, screen_name, cursor, stringify_ids
Copyright IKS Consortium
27
Source and further reading: https://dev.twitter.com/docs/api
http://api.twitter.com/1/followers/ids.format
Server Resource Format
Format: Should useHTTP contentnegotiation instead.
www.iks-project.eu
Page:
REST API Example: Twitter II
Request:GET http://api.twitter.com/1/followers/ids.json?screen_name=fctwitt
Response:{ "previous_cursor": 0, "ids": [ 143206502, 143201767, 777925 ], "previous_cursor_str": "0", "next_cursor": 0, "next_cursor_str": "0"}
Copyright IKS Consortium
28
Note:The service needs authentication that is not part of this example. For more information see Twitter API doc and the OAuth protocol.
To get information about user 143206502 use:
GET/users/lookup.json?user_id=143206502
www.iks-project.eu
Page:
Hands-On RESTful Services in Java
Java API defined by JSR 311 calledJAX-RS: The Java API for RESTful Web Services Stable version 1.0 Version 2.0 in progress (started Jan 2011)
Implementations Jersey - http://jersey.java.net/ Apache Wink - http://incubator.apache.org/wink/ JBoss Resteasy - http://www.jboss.org/resteasy
Download example Jersey demo webapp from http://jersey.java.net/nonav/documentation/latest/getting-st
arted.html
Copyright IKS Consortium
29
JAX-RS Source: http://jcp.org/en/jsr/summary?id=311
www.iks-project.eu
Page:
Jersey JAX-RS Preparations
Download and install Eclipse http://www.eclipse.org
Download and install Apache Maven http://maven.apache.org/
Download hello world web app https://maven.java.net/service/local/artifact/maven/redirect?r=releases&g=com.sun.jersey.samples&a=hello
world-webapp&v=1.10&c=project&e=zip
Unzip web app. In web app directory do: Create Eclipse project by executing
Compile and run webb app by
Copyright IKS Consortium
30
$ mvn clean package jetty:run
$ mvn eclipse:eclipse
www.iks-project.eu
Page:
Jersey JAX-RS: Step 1
Create a class that extends Application
Copyright IKS Consortium
31
@ApplicationPath("/")public class MyApplication extends Application { @Override public Set<Class<?>> getClasses() { final Set<Class<?>> classes = new HashSet<Class<?>>(); classes.add(HelloWorldResource.class);
return classes; }}
javax.ws.rs.core.Application
Must return the resource classes of the application.
Create a set of resource classes.
Add resource class.
Return resource classes.
www.iks-project.eu
Page:
Jersey JAX-RS: Step 2
Create HelloWorldResource class
Copyright IKS Consortium
32
@Path("/helloworld")public class HelloWorldResource {
@GET @Produces("text/plain") public String getHelloWorldMessage() {
return "Hello World"; }}
Class is a Plain-Old-Java-Object (POJO)
HTTP method. Could also be @POST, @DELETE, etc.
Format (media type) of data sent in response.
Any method name.
Return the plain text as a String.
Request URI path of this resource.
www.iks-project.eu
Page:
Jersey JAX-RS: Step 3
Test HelloWorld RESTful Service
Copyright IKS Consortium
33
curl -i http://localhost:8080/helloworld-webapp/helloworld
Host:Port Webapp name Resource path
HTTP/1.1 200 OKContent-Type: text/plainTransfer-Encoding: chunkedServer: Jetty(6.1.24)
Hello World The content.
The content format.
HTTP response code.
www.iks-project.eu
Page:
Jersey JAX-RS: Another response code
Change the response code from 200 OK to 500 Internal Server Error
Copyright IKS Consortium
34
@Path("/helloworld")public class HelloWorldResource {
@GET @Produces("text/plain") public Response getHelloWorldMessage() { // Some error return Response.status(Status.INTERNAL_SERVER_ERROR) .entity("Ups.") .build(); }}
javax.ws.rs.core.Response
Set response code.
Set entity (content) sent with the response.
HTTP/1.1 500 Internal Server ErrorContent-Type: text/plain
Ups.
Service response.
www.iks-project.eu
Page:
Jersey JAX-RS: Return HTML
Return HTML instead of plain text.
Copyright IKS Consortium
35
@Path("/helloworld")public class HelloWorldResource {
@GET @Produces(MediaType.TEXT_HTML) public Response getHelloWorldMessage() { StringBuilder html = new StringBuilder(); html.append("<html><body>"); html.append("<h1>Hello World!</h1>"); html.append("</body></html>");
return Response.ok(html.toString()).build(); }}
Produces “text/html”
Create HTML document.
Return OK with HTML as content.
Note: Instead of generating HTML code like this, modern
web frameworks use a template engine.
www.iks-project.eu
Page:
Jersey JAX-RS: Test HTML Service
via cURL
via Web Browser
Copyright IKS Consortium
36
HTTP/1.1 200 OKContent-Type: text/html
<html><body><h1>Hello World!</h1></body></html>
curl –i http://localhost:8080/helloworld-webapp/helloworld
www.iks-project.eu
Page:
Jersey JAX-RS: Use Path Parameters
Return HTML instead of plain text.
Copyright IKS Consortium
37
@Path("/hello/{msg}")public class HelloWorldResource {
@GET @Produces(MediaType.TEXT_HTML) public Response getHelloMessage(@PathParam("msg") String msg) { StringBuilder html = new StringBuilder(); html.append("<html><body>"); html.append("<h1>Hello ").append(msg).append("</h1>"); html.append("</body></html>");
return Response.ok(html.toString()).build(); }}
Path parameter ‘msg’.
Insert message.
Return OK with HTML as content.
‘msg’ is mapped from the URI @Path placeholder.
www.iks-project.eu
Page:
Jersey JAX-RS: Test Path Parameter
http://localhost:8080/helloworld-webapp/hello/Uni
http://localhost:8080/helloworld-webapp/hello/Paderborn
Copyright IKS Consortium
38
www.iks-project.eu
Page:
Jersey JAX-RS: Return JSON Object
Return data about a person in JSON format.
Copyright IKS Consortium
39
@Path("/person/{name}")public class PersonResource {
@GET @Produces(MediaType.APPLICATION_JSON) public Response getPerson(String name) throws JSONException { JSONObject jo = new JSONObject(); jo.put("name", name); jo.put("age", 44); jo.put("height", 1.85); return Response.ok(jo).build(); }}
Produces “application/json”
Resource URI is now a person’s name.
Create and return the JSON object.
HTTP/1.1 200 OK
{"name":"john","age":44,"height":1.85}
Response withname = john
www.iks-project.eu
Page:
Client
RESTful Service and Client Clients retrieve data via
HTTP requests to RESTful services.
Clients are web enabled devices like web browsers, smartphones, tablets, …
Requests are often performed in the background.
Often JavaScript is used at client-side.
Copyright IKS Consortium
40
Server
RESTful Service
HTTPRequest
HTML,XML,JSON
User Interface
JavaScript
www.iks-project.eu
Page:
What is JavaScript?
Official name is ECMAScriptaccording to the ECMA-262 standard.
JavaScript refers to the language implementation of ECMA-262 by Netscape and the Mozilla Foundation.
It was designed to add interactivity to HTML pages. JavaScript is a loosely typed scripting language (a scripting
language is a lightweight programming language). JavaScript is an interpreted language (means that scripts are
directly executed without compilation). Client-side JavaScript is usually embedded directly into HTML
pages and interpreted by the browser.
Further reading: http://www.ecma-international.org/publications/standards/
41
Copyright IKS Consortium
www.iks-project.eu
Page:
JavaScript is NOT…
JavaScript is not Java!Java and JavaScript are two completely different languages in both concept and design!
JavaScript is not simple!“JavaScript is a full-featured programming language, as complex as any and more complex than some.Using JavaScript for nontrivial tasks may be frustrating without a solid understanding of the language.”
JavaScript is not object-oriented!JavaScript is an object-based language, i.e. it does not support capabilities of classification, inheritance, encapsulation and information hiding.
Copyright IKS Consortium
42
Source: David Flanagan,JavaScript – The Definitive Guide. O’Reilly, 2006
www.iks-project.eu
Page:
JavaScript for typical tasks JavaScript gives web engineers a programming tool to
create interactive web sites. JavaScript can react to user events
<div onclick="doSomething();">…</div> JavaScript has access to the browser via client objects,
e.g. document: content of current HTML document navigator: information about used web browser
JavaScript can add dynamic content to an HTML page:
Copyright IKS Consortium
43
var h1Element = document.createElement("h1");var headText = document.createTextNode("Hello");h1Element.appendChild(headText);Document.appendChild(h1Element);
Create Elements
Append Elements
www.iks-project.eu
Page:
JavaScript Short Overview
Compute table of factorials:
Copyright IKS Consortium
44
<body> <h2>Table of Factorials</h2>
<script type="text/javascript">
var fact=1; for (i=1; i < 10; i++) { fact = fact*i;
document.write(i + "! = " + fact + "<br>"); } </script></body>
Embedded JavaScript in HTML page
New variable: No static type declaration!
Start loop from 1 to 10
Compute and assign next value
Dynamically write content to HTML page.
HTML code
www.iks-project.eu
Page:
JavaScript and jQuery
jQuery is a fast and concise JavaScript Library for HTML document traversing, event handling, animating, and interactions.
Add jQuery to the page:
Copyright IKS Consortium
45
Source and further reading: http://jquery.com/
<html> <head> <title>Demo</title> <script src="jquery.js" type="text/javascript"></script> </head> <body> … </body></html>
jQuery is defined and included here as a separate JavaScript file.
www.iks-project.eu
Page:
Call RESTful Web Service with jQuery
Copyright IKS Consortium
46
<script type="text/javascript"> function getData() { jQuery.ajax({
type: "GET", url: "http://localhost:8080/helloworld-webapp/person/jim", dataType: "json",
success: function(data, textStatus, jqXHR) { alert(data.name + " is + " data.age + " years old."); },
error: function(jqXHR, textStatus, errorThrown) { alert("Ups."); } }); }</script>
Perform HTTP REST call usingjQuery’s ajax() operation.
Specify type, resource URI, and format of REST service.
On success show person’s data received in JSON format.
On error show a message.
www.iks-project.eu
Page:
REST for Interactive Web Applications
RESTful services are a key technology for dynamic and interactive web applications.
Copyright IKS Consortium
47
Click
Message box with data retrieved from the server. No page reload!
www.iks-project.eu
Page:
REST and AJAX Asynchronous
JavaScriptAnd XML (or JSON, …)
AJAX engine processes HTTP requests asynchronously to the user interface.
RESTful services on the server
AJAX is not bound to XML – may also beJSON, HTML, Text, …
Copyright IKS Consortium
48
Client Browser
User Interface
JavaScript AJAX Engine
JavaScriptCall HTML, CSS
HTTPRequest
HTML,XML,JSON
Server
RESTful Service
www.iks-project.eu
Page:
Lessons Learned ...
Now you should know ... ... the architectural requirements for a semantic CMS. ... the integration concept of two loosely coupled columns. ... the components of the reference architecture ... how the reference architecture model can used to build
a semantic CMS from scratch and how an extended system can be extended
Copyright IKS Consortium
49