Presentation is loading. Please wait.

Presentation is loading. Please wait.

Designing Semantic CMS – Part II

Similar presentations


Presentation on theme: "Designing Semantic CMS – Part II"— Presentation transcript:

1 Designing Semantic CMS – Part II
Lecturer Organization Date of presentation Copyright IKS Consortium

2 (1) (2) (3) (7) (4) (8) (5) (9) (6) (10) Part I: Foundations
Introduction of Content Management Foundations of Semantic Web Technologies (1) (2) Part II: Semantic Content Management Part III: Methodologies Knowledge Interaction and Presentation Requirements Engineering for Semantic CMS (3) (7) Knowledge Representation and Reasoning Designing Semantic CMS (4) (8) Semantic Lifting Semantifying your CMS (5) (9) Storing and Accessing Semantic Data Designing Interactive Ubiquitous IS (6) (10)

3 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 Part III: Methodologies Requirements Engineering for Semantic CMS (7) Designing Semantic CMS (8) Semantifying your CMS (9) Designing Interactive Ubiquitous IS (10) Copyright IKS Consortium

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

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

6 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 Roy Thomas Fielding, Architectural Styles and the Design of Network-based Software Architectures, PhD Thesis, 2000 Copyright IKS Consortium

7 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

8 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

9 ROA applied to URI Bank All clients of the 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 Bank clients * Client accounts * Account balance 1 Balance Copyright IKS Consortium

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

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

12 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 For further reading have a look at the Internet Engineering Task Force (IETF) “httpbis” working group page: Copyright IKS Consortium

13 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

14 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

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

16 Idempotent HTTP Methods
Source: RFC-2616 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

17 REST from the Command Line
Download at 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 curl curl –H "Accept: application/xml" curl -d "name=Smith" Copyright IKS Consortium

18 HTTP OPTIONS Reponses are not cacheable
Source: RFC-2616 HTTP OPTIONS no side-effects Reponses are not cacheable Example: Check OPTIONS of 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 Copyright IKS Consortium

19 Source: RFC-2616 http://www.w3.org/Protocols/rfc2616/rfc2616.html
HTTP GET idempotent 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 curl -i -H "If-Modified-Since: Thu, 10 Nov :30:00 GMT" \ HTTP/ Not Modified Copyright IKS Consortium

20 Source: RFC-2616 http://www.w3.org/Protocols/rfc2616/rfc2616.html
HTTP HEAD idempotent 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. 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 Copyright IKS Consortium

21 HTTP PUT Use PUT to create a resource at a given URI
Source: RFC-2616 HTTP PUT idempotent 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

22 Source: RFC-2616 http://www.w3.org/Protocols/rfc2616/rfc2616.html
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”: URL encoded string curl -d "topic=Test&text=Hello%20World" \ Copyright IKS Consortium

23 Source: RFC-2616 http://www.w3.org/Protocols/rfc2616/rfc2616.html
HTTP DELETE idempotent 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) curl -i –X DELETE HTTP/ Method Not Allowed Server: GFE/2.0 Copyright IKS Consortium

24 Source: RFC-2616 http://www.w3.org/Protocols/rfc2616/rfc2616.html
HTTP TRACE no side-effects 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

25 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

26 Describing REST Interfaces
Source and further reading: Describing REST Interfaces WADL – Web Application Description Language GET <?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 Parameter Parameter type Operation Supported response formats Copyright IKS Consortium

27 REST API Example: Twitter
Source and further reading: https://dev.twitter.com/docs/api 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 Format: Should use HTTP content negotiation instead. Server Resource Format Copyright IKS Consortium

28 REST API Example: Twitter II
REST API Example: Twitter II Request: GET Response: { "previous_cursor": 0, "ids": [ , , 777925 ], "previous_cursor_str": "0", "next_cursor": 0, "next_cursor_str": "0" } To get information about user use: GET /users/lookup.json?user_id= Note: The service needs authentication that is not part of this example. For more information see Twitter API doc and the OAuth protocol. Copyright IKS Consortium Copyright IKS Consortium

29 Hands-On RESTful Services in Java
JAX-RS Source: 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 Copyright IKS Consortium

30 Jersey JAX-RS Preparations
Download and install Eclipse Download and install Apache Maven Download hello world web app https://maven.java.net/service/local/artifact/maven/redirect?r=releases&g=com.sun.jersey.samples&a=helloworld-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 $ mvn eclipse:eclipse $ mvn clean package jetty:run Copyright IKS Consortium

31 Jersey JAX-RS: Step 1 Create a class that extends Application
javax.ws.rs.core.Application @ApplicationPath("/") public class MyApplication extends Application { @Override public Set<Class<?>> getClasses() { final Set<Class<?>> classes = new HashSet<Class<?>>(); 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. Copyright IKS Consortium

32 Jersey JAX-RS: Step 2 Create HelloWorldResource class
Request URI path of this resource. Class is a Plain-Old-Java-Object (POJO) @Path("/helloworld") public class HelloWorldResource { @GET @Produces("text/plain") public String getHelloWorldMessage() { return "Hello World"; } HTTP method. Could etc. Format (media type) of data sent in response. Any method name. Return the plain text as a String. Copyright IKS Consortium

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

34 Jersey JAX-RS: Another response code
Jersey JAX-RS: Another response code Change the response code from 200 OK to 500 Internal Server Error @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/ Internal Server Error Content-Type: text/plain Ups. Service response. Copyright IKS Consortium Copyright IKS Consortium

35 Jersey JAX-RS: Return HTML
Return HTML instead of plain text. Note: Instead of generating HTML code like this, modern web frameworks use a template engine. @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. Copyright IKS Consortium

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

37 Jersey JAX-RS: Use Path Parameters
Return HTML instead of plain text. Path parameter ‘msg’. @Path("/hello/{msg}") public class HelloWorldResource { @GET @Produces(MediaType.TEXT_HTML) public Response 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(); } ‘msg’ is mapped from the placeholder. Insert message. Return OK with HTML as content. Copyright IKS Consortium

38 Jersey JAX-RS: Test Path Parameter
Copyright IKS Consortium

39 Jersey JAX-RS: Return JSON Object
Return data about a person in JSON format. Resource URI is now a person’s name. @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” Create and return the JSON object. HTTP/ OK {"name":"john","age":44,"height":1.85} Response with name = john Copyright IKS Consortium

40 RESTful Service and 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. Client User Interface JavaScript HTML, XML, JSON HTTP Request Server RESTful Service Copyright IKS Consortium Copyright IKS Consortium

41 Web Engineering WT 2006/07 Chapter 3: Architecture of Web Applications - Part 2
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: Copyright IKS Consortium © Gregor Engels University of Paderborn

42 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. Source: David Flanagan, JavaScript – The Definitive Guide. O’Reilly, 2006 Copyright IKS Consortium

43 JavaScript for typical tasks
Web Engineering WT 2006/07 Chapter 3: Architecture of Web Applications - Part 2 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: var h1Element = document.createElement("h1"); var headText = document.createTextNode("Hello"); h1Element.appendChild(headText); Document.appendChild(h1Element); Create Elements Append Elements Copyright IKS Consortium © Gregor Engels University of Paderborn

44 JavaScript Short Overview
Compute table of factorials: HTML code <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. Copyright IKS Consortium 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. Copyright IKS Consortium.", "width": "800" }

45 jQuery is defined and included here as a separate JavaScript file.
Source and further reading: 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: jQuery is defined and included here as a separate JavaScript file. <html> <head> <title>Demo</title> <script src="jquery.js" type="text/javascript"></script> </head> <body> </body> </html> Copyright IKS Consortium … Copyright IKS Consortium.", "width": "800" }

46 Call RESTful Web Service with jQuery
Perform HTTP REST call using jQuery’s ajax() operation. <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> Specify type, resource URI, and format of REST service. On success show person’s data received in JSON format. On error show a message. Copyright IKS Consortium Specify type, resource URI, and format of REST service. On success show person’s data received in JSON format. On error show a message. Copyright IKS Consortium.", "width": "800" }

47 REST for Interactive Web Applications
Message box with data retrieved from the server. No page reload! Click RESTful services are a key technology for dynamic and interactive web applications. Copyright IKS Consortium

48 JavaScript AJAX Engine
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, … Client Browser User Interface JavaScript Call HTML, CSS JavaScript AJAX Engine HTML, XML, JSON HTTP Request RESTful Service Server Copyright IKS Consortium Copyright IKS Consortium

49 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


Download ppt "Designing Semantic CMS – Part II"

Similar presentations


Ads by Google