Presentation is loading. Please wait.

Presentation is loading. Please wait.

Co-funded by the European Union Semantic CMS Community Designing Semantic CMS – Part II Copyright IKS Consortium 1 Lecturer Organization Date of presentation.

Similar presentations

Presentation on theme: "Co-funded by the European Union Semantic CMS Community Designing Semantic CMS – Part II Copyright IKS Consortium 1 Lecturer Organization Date of presentation."— Presentation transcript:

1 Co-funded by the European Union Semantic CMS Community Designing Semantic CMS – Part II Copyright IKS Consortium 1 Lecturer Organization Date of presentation

2 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)

3 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)

4 Page: How to design a semantic CMS? Copyright IKS Consortium 4 Conceptual Reference Architecture Technical Architectural Style Technical Architectural Style Part 1 IKS Reference Architecture Part 1 IKS Reference Architecture Part 2 REST Architecture Part 2 REST Architecture What does the architecture of a semantic CMS look like? How can a semantic CMS be realized?

5 Page: REST Architecture Stateless server are easy to replicate – scalable architecture Caches are only possible in stateless communication Copyright IKS Consortium 5 Clients Origin Server http Gateway, Load Balancer C + Cache C C Proxy http C

6 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, 2000

7 Page: REST Applied to Web Technologies Resource identification by applying REST to Universal Resource Identifiers (URIs) Self-descriptive messages and resource representation by using HTML, XML and JSON Resource manipulation through representations by applying REST to HTTP HTTP POST to to create a new posting Code-on-demand by using JavaScript Include JavaScript in HTML Copyright IKS Consortium 7

8 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

9 Page: ROA applied to URI Bank All clients of the bank Single client identified by client number All accounts of client 815 Single account number of client 815 Balance of account of client 815 Copyright IKS Consortium 9 Bank Client Account Balance * * 1 clients accounts balance

10 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 services Copyright IKS Consortium 10 HTTP Message HTTP Header Name = Value HTTP Body

11 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/0815 Host: Accept: text/html Accept-Language: de, en Returns a HTML representation of the client Preferred languages are first German then English. GET /clients/0815 Host: Accept: application/json Accept-Language: en, de Returns a JSON representation of the client Preferred languages are first English then German.

12 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:

13 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. format rfc-822 model/ * for data with multidimensional structure, e.g. vrml Copyright IKS Consortium 13

14 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

15 Page: Example REST Call Request Response Copyright IKS Consortium 15 POST HTTP-Header: Accept: application/json HTTP-Body:{ amount : -100 } HTTP-Header: Content-type: application/json HTTP-Body:{ balance : -500 } Resource identified by URI HTTP Operation Parameter Return value Format

16 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

17 Page: REST from the Command Line cURL tool available for all major platforms On Windows you may need Microsoft Visual C 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 curl –H "Accept: application/xml" curl -d "name=Smith" Download at

18 Page: HTTP OPTIONS Reponses are not cacheable Example: Check OPTIONS of Copyright IKS Consortium 18 curl –i –X OPTIONS HTTP/ OK Date: Thu, 10 Nov :50:12 GMT Server: Apache/ dev (Unix) Allow: GET,HEAD,POST,OPTIONS,TRACE Cache-Control: max-age=3600 Expires: Thu, 10 Nov :50:12 GMT Content-Length: 0 Content-Type: text/html; charset=utf-8 Supported HTTP methods no side-effects Source:RFC-2616

19 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, :30 pm Copyright IKS Consortium 19 idempotent curl -i -H "If-Modified-Since: Thu, 10 Nov :30:00 GMT" \ HTTP/ Not Modified Source:RFC-2616

20 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/ OK Server: Apache Set-Cookie: fe_typo_user=cdb2bbfa6be0c06c41c2d050d2492bb4; curl -i –X HEAD HTTP/ Moved Permanently Location: Expires: Sat, 10 Dec :07:42 GMT Cache-Control: public, max-age= Server: gws Source:RFC-2616

21 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

22 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" \ URL encoded string Source:RFC-2616

23 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 idempotent curl -i –X DELETE HTTP/ Method Not Allowed Server: GFE/2.0

24 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 dont allow this. Copyright IKS Consortium 24 no side-effects Source:RFC-2616

25 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

26 Page: WADL – Web Application Description Language GET Describing REST Interfaces Copyright IKS Consortium 26 Source and further reading: Resource Operation Supported response formats Parameter type Parameter

27 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: ServerResource Format Format: Should use HTTP content negotiation instead.

28 Page: REST API Example: Twitter II Request: GET Response: { "previous_cursor": 0, "ids": [ , , ], "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 use: GET /users/lookup.json?user_id=

29 Page: Hands-On RESTful Services in Java Java API defined by JSR 311 called JAX-RS: The Java API for RESTful Web Services Stable version 1.0 Version 2.0 in progress (started Jan 2011) Implementations Jersey - Apache Wink - JBoss Resteasy - Download example Jersey demo webapp from started.html started.html Copyright IKS Consortium 29 JAX-RS Source:

30 Page: Jersey JAX-RS Preparations Download and install Eclipse Download and install Apache Maven Download hello world web app world-webapp&v=1.10&c=project&e=zip 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

31 Page: Jersey JAX-RS: Step 1 Create a class that extends Application Copyright IKS Consortium public class MyApplication extends Application public Set > getClasses() { final Set > classes = new HashSet >(); classes.add(HelloWorldResource.class); return classes; } Must return the resource classes of the application. Create a set of resource classes. Add resource class. Return resource classes.

32 Page: Jersey JAX-RS: Step 2 Create HelloWorldResource class Copyright IKS Consortium public class public String getHelloWorldMessage() { return "Hello World"; } Class is a Plain-Old-Java-Object (POJO) HTTP method. Could 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.

33 Page: Jersey JAX-RS: Step 3 Test HelloWorld RESTful Service Copyright IKS Consortium 33 curl -i Host:PortWebapp name Resource path HTTP/ OK Content-Type: text/plain Transfer-Encoding: chunked Server: Jetty(6.1.24) Hello World The content. The content format. HTTP response code.

34 Page: Jersey JAX-RS: Another response code Change the response code from 200 OK to 500 Internal Server Error Copyright IKS Consortium public class public Response getHelloWorldMessage() { // Some error return Response.status(Status.INTERNAL_SERVER_ERROR).entity("Ups.").build(); } Set response code. Set entity (content) sent with the response. HTTP/ Internal Server Error Content-Type: text/plain Ups. Service response.

35 Page: Jersey JAX-RS: Return HTML Return HTML instead of plain text. Copyright IKS Consortium public class public Response getHelloWorldMessage() { StringBuilder html = new StringBuilder(); html.append(" "); html.append(" Hello World! "); html.append(" "); 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.

36 Page: Jersey JAX-RS: Test HTML Service via cURL via Web Browser Copyright IKS Consortium 36 HTTP/ OK Content-Type: text/html Hello World! curl –i

37 Page: Jersey JAX-RS: Use Path Parameters Return HTML instead of plain text. Copyright IKS Consortium public class public Response String msg) { StringBuilder html = new StringBuilder(); html.append(" "); html.append(" Hello ").append(msg).append(" "); html.append(" "); return Response.ok(html.toString()).build(); } Path parameter msg. Insert message. Return OK with HTML as content. msg is mapped from the placeholder.

38 Page: Jersey JAX-RS: Test Path Parameter webapp/hello/Paderborn webapp/hello/Paderborn Copyright IKS Consortium 38

39 Page: Jersey JAX-RS: Return JSON Object Return data about a person in JSON format. Copyright IKS Consortium public class 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 persons name. Create and return the JSON object. HTTP/ OK {"name":"john","age":44,"height":1.85} Response with name = john

40 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 HTTP Request HTML, XML, JSON User Interface JavaScript

41 Page: What is JavaScript? Official name is ECMAScript according 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: 41 Copyright IKS Consortium

42 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. OReilly, 2006

43 Page: JavaScript for typical tasks JavaScript gives web engineers a programming tool to create interactive web sites. JavaScript can react to user events … 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

44 Page: JavaScript Short Overview Compute table of factorials: Copyright IKS Consortium 44 Table of Factorials var fact=1; for (i=1; i < 10; i++) { fact = fact*i; document.write(i + "! = " + fact + " "); } 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

45 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: Demo … jQuery is defined and included here as a separate JavaScript file.

46 Page: Call RESTful Web Service with jQuery Copyright IKS Consortium 46 function getData() { jQuery.ajax({ type: "GET", url: "http://localhost:8080/helloworld-webapp/person/jim", dataType: "json", success: function(data, textStatus, jqXHR) { alert( + " is + " data.age + " years old."); }, error: function(jqXHR, textStatus, errorThrown) { alert("Ups."); } }); } Perform HTTP REST call using jQuerys ajax() operation. Specify type, resource URI, and format of REST service. On success show persons data received in JSON format. On error show a message.

47 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!

48 Page: REST and AJAX Asynchronous JavaScript And 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 be JSON, HTML, Text, … Copyright IKS Consortium 48 Client Browser User Interface JavaScript AJAX Engine JavaScript Call HTML, CSS HTTP Request HTML, XML, JSON Server RESTful Service

49 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

Download ppt "Co-funded by the European Union Semantic CMS Community Designing Semantic CMS – Part II Copyright IKS Consortium 1 Lecturer Organization Date of presentation."

Similar presentations

Ads by Google