Types of Cloud Computing (SaaS)Software as a Service XaaS (PaaS) Platform as a Service (IaaS) Infrastructure as a Service
Access to Cloud computing Service Web URL (standard HTTP methods) web brower HTTP IaaS PaaS SaaS Rest,XML-RPC,etc HTTP Application Programmatic Service Access (many methods) A service is delivered through two access points: Standard web browsing (HTTP) and Programmatic access (Rest,XML-RPC,SOAP, etc. over HTTP)
What is a service? Technology A SERVICE INTERFACE Technology B -------- -------- -------- -------- Technology C Interface definition (e.g., WSDL)
Web services Represent an established and common medium for sophisticated, web-based service logic. The technologies exploited in a WS are WSDL (Web Service Definition Language) Markup language used to define the API of the WS XML Schema Define the structure of the data being exchanged SOAP Request/Reply protocol for message exchange UDDI (Universal Description,Discovery,Integration) Register where WSDL description can be published and retrived
Web Service XML Schema define types and payload structure for SOAP WSDL Enable discovery of UDDI
Web service, main functional layers SOAP messages can be used to represent either single documents or pairs of request and reply messages. But it is the synchronous HTTP protocol that is used to relate each Reply to the corresponding Request. Web Services Service Description (WSDL) SOAP URIs(URLs or URNs) XML HTTP,SMTP or other transport Web services are accessed by URIs by clients using messages formatted in XML. SOAP is used to express Request and Reply messages in XML and to transport them over HTTP.
Characteristic of a web service A web service consists of a single remote object it is not possible to instantiate additional remote objects during the running of a web service and remote object references are not used. The details of SOAP and XML can be hidden from client and server programmer, for example, by the Java web services API (JAX-RPC). Web services use service descriptions which are written in an XML based language called WSDL. Service descriptions are more general than interface definitions in that they also specify the endpoints (URIs) of a service and the protocols used (e.g. SOAP and HTTP) to communicate the messages. WSDL documents are accessed via their URIs, which can be used by, for example, the JAX-RPC system to generate client proxies.
SOAP message
Message exchange patterns Name Messages sent by Client Server Delivery Fault message In-Out In-Only Robust In-Only Out-In Out-Only Robust Out-Only Request Reply may replace Reply Request no fault message Request guaranteed may be sent Reply Request may replace Reply Request no fault message Request guaranteed may send fault
SOAP Message Processing SOAP message travels along a path of nodes One-way transmission; like a Unix pipeline Request-Response treated as 2 messages: Message Exchange Pattern (MEP) Routing is not specified by SOAP SOAP nodes Initial sender, intermediaries, ultimate receiver Process and/or relay message Assume a SOAP role towards message
SOAP Message Processing Header blocks control processing Every header block is targeted at a SOAP role A node in that role must perform message processing implied by header block, and delete header block before relaying onward Header blocks may be used to: Authenticate Route the message Indicate preference to service broker
MEP=Message Exchange Pattern
Example: calculator
Coordination of WS flight booking a flight booking b Client Travel Agent Service hire car booking a hotel booking a hotel bookingb hire car booking b
Web Services and mobile apps SOAP introduces some significant overhead for web services that may be problematic for mobile devices. If one has full control over the client and the server, a simple REST / JSON based architecture may be more adequate (see next slide) Libraries are available for SOAP/Android
Web API (aka API as a Service) Delivering basic building blocks as services for other programs Services can be offered via simpler protocols JSON, JSON-RPC, REST, JSONP,
Web API (aka API as a Service) sniping
Web Api directory Mash-up
Web-API Based of RPC/HTTP Two main data representations JSON XML Protocols XML-RPC JSON-RPC SOAP REST
Web API: RPC over Internet RPC calls mapped onto HTTP (GET or POST) Synchronous call Asynchronous call with callbacks External data representation JSON (Java Simple Object Notation) http://www.json.org/json-it.html XML Protocols REST, SOAP, JSONP, JSON-RPC, XML-RPC,
JSON
JSON Two fundamental structures: See JSON Lint (validator)
XML in a nutshell XML (extensible Markup Language) is a language derived from SGML (Standard Generalized Markup Language), from which HTML also derives. The key notion in the markup language familty is a markup, something that describes some aspect of the data In HTML markups define the appearance of the document, whereas in XML they define the meaning of the data
XML in a nutshell An XML document is a tree Data appear inside elements An element not only contains the data itself but also information describing the meaning of the data
Example Title Author Il Signore degli Anelli, di John Ronald Reuel Tolkien, Bompiani. Editor
Example Book Title Author Editor Elements <book> <title> Il Signore degli Anelli </title> <author> John R. R. Tolkien </author> <editor> Bompiani </editor> </book> Tips : Browser allows to see the structure of the document
<title> Il Signore degli Anelli </title> Elements and attribute Data Tag Attribute (key/value pair) <title pages= 345 > Il Signore degli Anelli </title>
Well formed document
Valid document Document that follows composition rules about the its structure Two solutions Document Type Definition Easier, less powerfull XML Schema More complex, more powerfull
WFD and validation XML Document Syntax check Grammar Semantic check
XML-RPC
Overview of XML-RPC Data Model Scalar Struct Array Messages Request message Response message Error message
Scalar types Tag Type Example <i4> or <int> four-byte signed integer -12 <boolean> 0 (false) or 1 (true) 1 <string> string hello world <double> double-precision signed floating point number -12.214 <datetime.iso8601> date/time 20101504T09:30:00 <base64> base64-encoded binary ew91ignhbid0ihjlywqgdghpcye=
Struct type <struct> <member> <name>lowerbound</name> <value><i4>18</i4></value> </member> <member> <name>upperbound</name> <value><i4>139</i4></value> </member> </struct>
Array type <array> <data> <value><i4>12</i4></value> <value><string>egypt</string></value> <value><boolean>0</boolean></value> <value><i4>-31</i4></value> </data> </array>
Request message Root element: methodcall contains a MethodName element and a params element MethodName contains the name of the procedure being called Params is a list of values for the parameters
Example <?xml version="1.0"?> <methodcall> <methodname>xxx</methodname> <params> <param> <value><i4>123</i4></value> </param> <param> <value><double>12.3</double></value> </param> </params> </methodcall>
Example <?xml version="1.0"?> <methodcall> <methodname> XXX</methodName> <params> <param> <value><i4>123</i4></value> </param> <param> </param> </params> </methodcall> <value><double>12.3</double></value> methodcall methodname XXX params param value i4 123 param value double 12.3
Example <?xml version="1.0"?> <methodcall> <methodname>scuola XXX</methodName> <params> <param> <value><i4>123</i4></value> </param> <param> </param> </params> </methodcall> <value><double>12.3</double></value> methodcall methodname XXX params param value i4 123 param value double 12.3 methodcall methodname params param i4 param double
Complete request message POST /xmlrpc HTTP 1.0 User-Agent: Host: Content-type: text/xml Content-length:.. <?xml version= 1.0?> <methodcall> <methodname>circle_area</methodname> <params><param><value><double>12.2</double></value><param><params> </methodcall>
Reply message <?xml version="1.0"?> <methodresponse> <params> <param> </params> <value><i4>1</i4></value> </param> </methodresponse>
Fault message <?xml version="1.0"?> <methodresponse> <fault> <value> <struct> <member> <name>faultcode</name> <value><int>4</int></value> </member> <member> <name>faultstring</name> <value><string>too many parameters.</string></value> </member> </struct> </value> </fault> </methodresponse>
JSON-RPC 2.0 JSON-RPC is a stateless, transport agnostic, light-weight remote procedure call (RPC) protocol Much like XML-RPC No formal grammar Definition of request object and reply object New feature: batch requests, notification
Some example --> {"jsonrpc": "2.0", "method": "subtract", "params": [42, 23], "id": 1} <-- {"jsonrpc": "2.0", "result": 19, "id": 1} -->{"jsonrpc": "2.0", "method": "subtract", "params": [23, 42], "id": 2} <-- {"jsonrpc": "2.0", "result": -19, "id": 2} -->{"jsonrpc": "2.0", "method": "subtract", "params": {"subtrahend": 23, "minuend": 42}, "id": 3} <-- {"jsonrpc": "2.0", "result": 19, "id": 3} --> {"jsonrpc": "2.0", "method": "subtract", "params": {"minuend": 42, "subtrahend": 23}, "id": 4} <-- {"jsonrpc": "2.0", "result": 19, "id": 4}
JSON-RPC call batch --> [ {"jsonrpc": "2.0", "method": "sum", "params": [1,2,4], "id": "1"}, {"jsonrpc": "2.0", "method": "notify_hello", "params": [7]}, {"jsonrpc": "2.0", "method": "subtract", "params": [42,23], "id": "2"}, {"foo": "boo"}, {"jsonrpc": "2.0", "method": "foo.get", "params": {"name": "myself"}, "id": "5"}, {"jsonrpc": "2.0", "method": "get_data", "id": "9"} ] <-- [ {"jsonrpc": "2.0", "result": 7, "id": "1"}, {"jsonrpc": "2.0", "result": 19, "id": "2"}, {"jsonrpc": "2.0", "error": {"code": -32600, "message": "Invalid Request."}, "id": null}, {"jsonrpc": "2.0", "error": {"code": -32601, "message": "Method not found."}, "id": "5"}, {"jsonrpc": "2.0", "result": ["hello", 5], "id": "9"} ]
JSONP (JSON with Padding) GET f(json data). <javasxcript scr=xxx&callback=f>. Used in JavaScript Allows to overcome the crossdomain problem Uses a callback function
REST Method calls are mapped to HTTP request (Get, Post) Method name is a parameter of the call Reply is usually formatted as JSON or XML
SOAP It s by far the most verbose protocol Service is described in WSDL file Messages as XML documents formatted according to a specific schema
Useful debugging tools
RPC over Internet: example types= JSON, XML Features geolookup conditions forecast http://api.wunderground.com/api/key KEY/FEATURE FEATURE/[ /[FEATURE FEATURE ]/q/ ]/q/query QUERY.FORMAT
Example http://api.wunderground.com/api/[api_key]/conditions/q/rome.json location ID JSONP. http://api.wunderground.com/api/[api_key]/conditions/q/rome.json?callback=f
Example of XML reply http://api.wunderground.com/api/[apikey]/conditions/q/zmw:00000.1.16240.xml
Chrome Developer tool Interoperability
WebView Allows to host a web page The page can be loaded from internet or stored locally Requires INTERNET permission in the manifest It is based on WebKit engine Navigate back and forward Zoom in and out Load data, etc.. It may execute javascript code By default it is disabled
Using web view
Using web view An interesting point is that data can be loaded from a local file (or even passed as a string) browser.loaddata ( <html> <body> Hello!</body></html>, UTF-8 ); browser.loadurl ("file:///android_asset/my_local_webpage1.html");
Binding JavaScript code to Android code It is possible to create interfaces between JavaScript code and client-side Android code. In other words, JavaScript code can call a method in the Android code This is very powerful but it s also a source of risk One can write application using JS and HTML (this is what PhoneGap does)
Binding JavaScript code to Android code Add Interface (C, Android ) HTML + JS.. Android.test() Android Code Class C test public method Public methods are seen as JS function The object that is bound to your JavaScript runs in another thread and not in the thread in which it was constructed. Only simple data can be passed Android.test(); JSON can be useful in this respect
Example my_local_webpage1.html
Navigation functions
Static call Using JS src you can make a call and display results on the screen
Static call
Dynamic Call
Dynamic call 1. Dynamically create a HTML element and append in the head section 2. Call the URL with callback function
Dynamic call Show the current temperature on the screen
Using jquery
Additional example
Additional example
Example: Geocoding API
Example: Geocoding API (json)
Example: Geocoding API (xml)
Example: reverse Geocoding (json)
Example: Reverse geocoding (xml)
Google s JavaScript API (vers. 3)
Example
Example:
Geolocation in HTML5
Example: Flickr
Flickr: request, reply message format http://api.flickr.com/services/rest/ http://api.flickr.com/services/xmlrpc/ WEB-API http://api.flickr.com/services/soap/
Example: rest call
Example json format Reply is wrapped through jsonflickrapi callback name To avoid this, set nojsoncallback=1 option
Asynchronous RPC: AJAX Security: Cross domain not allowed
Example: using AJAX
Example: using AJAX
Example: searching photos
Example: searching photos
Example: searching data Key photo contains photo details
Example: searching photo Every photo has a link [mstzb] defines the size
Example: searching photos
Other example http://api.wordreference.com/{api_version}/{api_key}/{dictionary}/{term} http://api.wordreference.com/{api_version}/{api_key}/json/{dictionary}/{term}
Example
Example
Example: Twitter API
Exercise Write a simple JS program for the TTT game Hint: use a table for button formatting Use a single handler to make modification
Other web API http://openweathermap.org/api EditGrid
Dropbox is a free (up to 2GB), web-based cloud storage mechanism file backup service data sharing Data sync among different clients Mobile applications Windows STorage as a Service Linux.mp3.avi.jpg iphone ipad MAC REST / JSON Blackberry Android
Questions?