Distributed Systems 2014 Assignment 2 Leyna Sadamori - - PowerPoint PPT Presentation

distributed systems 2014 assignment 2
SMART_READER_LITE
LIVE PREVIEW

Distributed Systems 2014 Assignment 2 Leyna Sadamori - - PowerPoint PPT Presentation

Distributed Systems 2014 Assignment 2 Leyna Sadamori leyna.sadamori@inf.ethz.ch Distributed Sysyems Introduction Assignment 2 Leyna Sadamori | October 6, 2014 | 1 Web Services Distributed Sysyems Introduction Assignment 2


slide-1
SLIDE 1

| | Distributed Sysyems – Introduction Assignment 2 Leyna Sadamori October 6, 2014

Leyna Sadamori

leyna.sadamori@inf.ethz.ch

Distributed Systems 2014 – Assignment 2

1

slide-2
SLIDE 2

| | Distributed Sysyems – Introduction Assignment 2 Leyna Sadamori October 6, 2014 2

Web Services

slide-3
SLIDE 3

| | Distributed Sysyems – Introduction Assignment 2 Leyna Sadamori October 6, 2014

§ Quick walkthrough of Web application architectures

§ WS-* Web Services § Representational State Transfer (REST)

§ Exercise 2

§ Overview § Tasks § Hints & Anchors

Overview

3

slide-4
SLIDE 4

| | Distributed Sysyems – Introduction Assignment 2 Leyna Sadamori October 6, 2014

§ Definition:

“ A Web service is an application component accessible over open protocols”

Web Services

4

Server Client

Offer Services Invoke calls

slide-5
SLIDE 5

| | Distributed Sysyems – Introduction Assignment 2 Leyna Sadamori October 6, 2014

Web Services in a Nutshell

5

Lookup-Service UDDI WSDL WSDL SOAP lookup request/reply publish Server Client

slide-6
SLIDE 6

| | Distributed Sysyems – Introduction Assignment 2 Leyna Sadamori October 6, 2014

§ For the exercise, we let the service publish its WSDL without going through a UDDI...

Web Services in a Nutshell

6

SOAP lookup request/reply WSDL Server Client

slide-7
SLIDE 7

| | Distributed Sysyems – Introduction Assignment 2 Leyna Sadamori October 6, 2014

§ WSDL: Web Services Description Language describes:

§ What a Web service can do § Where it resides § How to invoke it

§ Explore WSDL

§ Example: http://vslab.inf.ethz.ch:8080/SunSPOTWebServices/SayHello?Tester

Types, Messages, PortType, Binding, Service, Port, Definition

Web Services - WSDL Overview

7

slide-8
SLIDE 8

| | Distributed Sysyems – Introduction Assignment 2 Leyna Sadamori October 6, 2014

[http://www.innoq.com/soa/ws-standards/poster/innoQ%20WS-Standards%20Poster%202007-02.pdf]

8

slide-9
SLIDE 9

| | Distributed Sysyems – Introduction Assignment 2 Leyna Sadamori October 6, 2014

§ Most IDEs provide code generators § Server-side

§ Java annotations § Automatic generation of WSDL file

§ Client-side

§ Parsing of WSDL file § Automatic generation of client stubs

Programming WS-* Clients

9

slide-10
SLIDE 10

| | Distributed Sysyems – Introduction Assignment 2 Leyna Sadamori October 6, 2014

§ REST is a lightweight architectural style for designing networked applications

§ HTTP 1.1 implements the REST architectural style § It uses HTTP for CRUD (Create/Read/Update/Delete) operations

§ Platform independent § Language independent § Open standard-based

REST: Representational State Transfer

10 10

[http://geekandpoke.typepad.com/]

slide-11
SLIDE 11

| | Distributed Sysyems – Introduction Assignment 2 Leyna Sadamori October 6, 2014

§ Resources: Identified by logical URIs

§ State and functionality are represented using resources

§ A web of resources: Resources are linked

§ Similar to the interconnection of Web pages in the WWW § When relevant, resources should link to additional information

§ Resources should be kept simple

§ Stateless communication protocol:

§ Each new request must carry all the information required to complete it

REST Architecture

11

e.g., a sensor node: http://vslab.inf.ethz.ch:8081/sunspots/Spot1

[http://code.google.com/p/hcsfsp/]

slide-12
SLIDE 12

| | Distributed Sysyems – Introduction Assignment 2 Leyna Sadamori October 6, 2014

§ Objectives:

§ Learn to develop distributed Web applications § Use the two different paradigms seen in the lecture:

§ Representational State Transfer (REST) § Web Services (WS-*)

§ Dates:

§ Exercise begins: Now (October 6, 2014) § Exercise is due: 9:00 am, October 20, 2014

Assignment 2 – Overview

12

[http://code.google.com/p/ hcsfsp/]

slide-13
SLIDE 13

| | Distributed Sysyems – Introduction Assignment 2 Leyna Sadamori October 6, 2014

§ Access Sun SPOTs through WS-* and REST § Sun SPOTs: Wireless sensor nodes (temp, acc, light,...)

Assignment 2 – System Setup

13

[http://code.google.com/p/hcsfsp/] Mobile Phone

  • 2. SOAP Request

Basestation2: WS-* APP Server Spot4 Spot3 WS-* Spots

  • 1. HTTP Request

Basestation1: Web Server Spot2 Spot1 RESTful Spots WS HTTP VSLAB Server

slide-14
SLIDE 14

| | Distributed Sysyems – Introduction Assignment 2 Leyna Sadamori October 6, 2014

Experimenting with RESTful Web Services (2P)

§ Create an HTTP request

a) “manually” (i.e., without the use of an HTTP library) b) using org.apache.http.*

§ Use HTTP content negotiation to get machine-readable data § Connect to a Sun SPOT and retrieve the temperature value

§ Hint: Use AsyncTask to do network operations (be careful with accessing UI Elements!) § Hint: Use the HTTP header “Connection: close” to avoid blocking behavior

Assignment 2 – Task 1

14

slide-15
SLIDE 15

| | Distributed Sysyems – Introduction Assignment 2 Leyna Sadamori October 6, 2014

Experimenting with WS-* Web Services (2P)

§ Explore WSDL, create SOAP requests § Connect to a Sun SPOT and retrieve the temperature value. § Hint: Apply hints from Task 1 § Hint: Use the Android verion of the kSOAP2 library

§ http://code.google.com/p/ksoap2-android/

§ Hint: Important classes are: SoapObject, SoapSerializationEnvelope § Hint: You do not have to implement the decoding of the WSDL file

Assignment 2 – Task 2

15

slide-16
SLIDE 16

| | Distributed Sysyems – Introduction Assignment 2 Leyna Sadamori October 6, 2014

§ Interfaces for Sensors

§ Separate UI from logic § Increase of code reuse § Each subtask is a new class that implements the Sensor interface

Code Skeleton

16

slide-17
SLIDE 17

| | Distributed Sysyems – Introduction Assignment 2 Leyna Sadamori October 6, 2014

Network Traffic Analysis (1P)

§ Learn how to use tools for network traffic analysis (e.g. Wireshark) § Debugging tool for distributed software

Assignment 2 – Task 3

17

slide-18
SLIDE 18

| | Distributed Sysyems – Introduction Assignment 2 Leyna Sadamori October 6, 2014

Your Phone as a Server (3P)

§ Implement a Web server on your phone that allows to access the sensors and actuators of the phone § Hint: Use a Service to implement the server § Hint: Use Intents and BroadcastReceiver, or Bound Services, to communicate between Service and Activity § Hint: When you are using an existing WiFi network, make sure the ports you are using are not blocked!

Task 5: Mini-Test (2P)

Assignment 2 – Task 4, 5

18

slide-19
SLIDE 19

| | Distributed Sysyems – Introduction Assignment 2 Leyna Sadamori October 6, 2014

§ See exercise sheet for details

§ code.zip § answers.zip § wireshark.zip

Deliverables

19

slide-20
SLIDE 20

| | Distributed Sysyems – Introduction Assignment 2 Leyna Sadamori October 6, 2014

§ Internet Media Types

§ text/html, text/xml § application/xml, application/json

§ ROA – Resource-Oriented Architecture § REST – Representational State Transfer § SOA – Service-oriented Architecture § SOAP – Simple Object Access Protocol § WSDL – Web Services Description Language

Assignment 2 Hints - Relevant Terminology

20

slide-21
SLIDE 21

| | Distributed Sysyems – Introduction Assignment 2 Leyna Sadamori October 6, 2014

§ http://www.infoq.com/articles/rest-introduction § RESTful Web Services (Leonard Richardson und Sam Ruby)

§ Available at D-INFK library

§ Apache HTTP library (simplest sample code alive... J)

§ http://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk/httpclient/ src/examples/org/apache/http/examples/client/ ClientWithResponseHandler.java

REST Hints

21

slide-22
SLIDE 22

| | Distributed Sysyems – Introduction Assignment 2 Leyna Sadamori October 6, 2014

§ Firefox extensions

§ HttpRequester § Poster § RESTClient § SOA Client

§ Chrome extensions

§ Simple REST client

Noteworthy Tools

22

slide-23
SLIDE 23

| | Distributed Sysyems – Introduction Assignment 2 Leyna Sadamori October 6, 2014

§ Android Debug Bridge (adb tool)

§ You can find the adb tool in <sdk>/platform-tools/ § http://developer.android.com/tools/help/adb.html

§ Android Emulator

§ http://developer.android.com/tools/devices/emulator.html

§ Setting up a port forwarding

§ adb forward tcp:port1 tcp:port2

§ forwards the local port port1 on the machine to port2 on the emulator. § Example: adb forward tcp:12345 tcp:8088

Noteworthy Tools

23