• Keine Ergebnisse gefunden

Ü Ü bung 6 bung 6

N/A
N/A
Protected

Academic year: 2022

Aktie "Ü Ü bung 6 bung 6"

Copied!
49
0
0

Wird geladen.... (Jetzt Volltext ansehen)

Volltext

(1)

Ü Ü bung 6 - bung 6 - SOAP SOAP

Dr. Malgorzata Mochol Freie Universität Berlin Institut für Informatik

Netzbasierte Informationssysteme mochol@inf.fu-berlin.de

(2)

Ü Ü bung 6 bung 6

ƒ SOAP + XSLT

ƒ Musterfragen zu SOAP

ƒ Web APIs

ƒ XML In Use: Flickr APIs

(3)

AG Netzbasierte Informationssysteme http://www.ag-nbi.de

3 Web Services

Web Services

Web Service WSDL

Beschreibt Service UDDI

Verzeichnis

Sucht nach Service

Verweist auf

die Service-Beschreibung

Verw eist a

uf de

n Ser vice Service Nutzer SOAP

(Service Consumer)

(4)

SOAP + XSLT

SOAP + XSLT

(5)

AG Netzbasierte Informationssysteme http://www.ag-nbi.de

5

Why Why SOAP + XSLT? SOAP + XSLT?

ƒ SOAP messages are XML and hence can be manipulated by XML tools

ƒ XQuery

ƒ XPath

ƒ XSLT

ƒ Why?

ƒ SOAP-to-SOAP: generate a new request from a response

ƒ SOAP-to-XML: generate some data out of a response

ƒ SOAP-to-HTML: present the content of a response

(6)

SOAP + XSLT:

SOAP + XSLT: Generic Generic SOAP Web Service SOAP Web Service

(7)

AG Netzbasierte Informationssysteme http://www.ag-nbi.de

7

Example Example

response with 2 elements:

result : string (some result data) error : string (an error message if something went wrong)

data type elements:

id : string (Customer Identification) password : string (Password)

version : string (current Version of the Customer-Schema)

data : string (XML-Data or something else)

(8)

Problem Problem

• customer Web Service Client - standard implementation for every B2B connection in the extranet

• customer does not want to modify it to fit our needs

• data scattered around in the SOAP-Envelope:

id, password and version - in the SOAP-Header

data - in the SOAP-Body.

(9)

AG Netzbasierte Informationssysteme http://www.ag-nbi.de

9

Possible

Possible Solutions Solutions

Solution A

• to develop a special Web Service for this customer Æ and for each upcoming customer in the future

Solution B

• to modify the current Web Service to handle this issues Æ modification of the SOAP-Message with XSL

Transformations

(10)

Solution B Solution B

• identificatin of any incoming message (XPath to determine the sender)

• infomations about the locations of the 4 data type

elements for every specific customer request in

database

(11)

AG Netzbasierte Informationssysteme http://www.ag-nbi.de

11

XPath XPath

• using XSLT to transform the specific customer request to our Web Service Schema

• Response – same procedure

id : /soapenv:Envelope/soapenv:Header/Username/text()

password : /soapenv:Envelope/soapenv:Header/Password/text() version : /soapenv:Envelope/soapenv:Header/SchemaVersion/text()

data : /soapenv:Envelope/soapenv:Body/soap:processOperation/data/text()

(12)

Conclusions Conclusions

• configuration of every customer from the database

• no changes in the code

• just create/modify XPath- and XSLT files and add this information to the database

Example from: http://blog.jdevelop.eu/2008/03/16/creating-generic-soap-web-services/

(13)

Musterfragen

Musterfragen

(14)

Musterfragen Musterfragen

• Which elements are NOT part of the SOAP-message?

1. soap:Content

2. soap:Head

3. soap:Header

4. soap:Body

(15)

AG Netzbasierte Informationssysteme http://www.ag-nbi.de

15

Musterfragen Musterfragen

• Which SOAP element is the root element?

1. soap:Fault

2. soap:Envelope

3. soap:Header

4. soap:Body

(16)

Musterfragen Musterfragen

• Which SOAP version is it?

1. SOAP 1.0 2. SOAP 1.1

3. SOAP 1.2

4. SOAP 2.0

<?xml version="1.0"?>

<soap:Envelope

xmlns:soap="http://www.w3.org/2001/12/soap-envelope"

soap:encodingStyle="http://www.w3.org/2001/12/soap-encoding">

...

Message information goes here ...

</soap:Envelope>

(17)

AG Netzbasierte Informationssysteme http://www.ag-nbi.de

17

ƒ Which SOAP attribute is used to indicate if processing a header entry must be possible?

1. actor

2. mustUnderstand

3. required

4. encodingStyle Musterfragen

Musterfragen

(18)

Musterfragen Musterfragen

• Which Elements of a SOAP-message must the ultimate receiver understand?

1. Header Blocks with mustUnderstand="true"

2. Header Blocks without mustUnderstand-Attribute

3. Header Blocks with mustUnderstand="false"

4. none of them

(19)

AG Netzbasierte Informationssysteme http://www.ag-nbi.de

19

Musterfragen Musterfragen

In SOAP-RPC, all input and output parameters are

returned. What is the name of the element which indicates the principle output parameter?

1. <rpc:response>m:Parameter-i</rpc:response>

2. <rpc:result>m:Parameter-i</rpc:result>

3. <rpc:answer>m:Parameter-i</rpc:answer>

4. <rpc:value>m:Parameter-i</rpc:value>

(20)

Musterfragen Musterfragen

• In SOAP error reporting, which two elements must env:Fault contain?

1. env:error and env:explanation

2. env:error and env:reason

3. env:code and env:explanation

4. env:code and env:reason

(21)

AG Netzbasierte Informationssysteme http://www.ag-nbi.de

21

Musterfragen Musterfragen

• How to encode in SOAP an array of type double [] [3]?

(assuming xmlns:enc=

„http://www.w3.org/2003/05/soap-encoding“ ) 1. <numbers enc:itemType="xsd:double"

enc:array1=" " enc:array2="3">… </numbers>

2. <numbers enc:schemaType="xsd:double"

enc:arraySize="* 3">… </numbers>

3. <numbers enc:itemType="xsd:double"

enc:arraySize="* 3">… </numbers>

4. <numbers enc:schemaType="xsd:double"

enc:array1=" " enc:array2="3">… </numbers>

(22)

Musterfragen Musterfragen

• What is allowed?

1. enc:arraySize="* *"

2. enc:arraySize="* 4"

3. enc:arraySize="4 *"

4. enc:arraySize=" "

(23)

AG Netzbasierte Informationssysteme http://www.ag-nbi.de

23

Musterfragen Musterfragen

• How can you specify the encoding-Style?

1. use="literal"

2. use="encoded" encodingStyle="…"

3. use="encoded"

4. use="coded" encodingStyle="…"

(24)

Web Web APIs APIs

(25)

AG Netzbasierte Informationssysteme http://www.ag-nbi.de

25

Web 2.0 Web 2.0

• SOA and Web Services are terms used generally with respect to enterprise computing

• A similar shift in computing on the Web is part of what is being termed Web 2.0

• Represents the evolution of web sites from isolated „information silos“ to interlinked „computing platforms“ (Web as platform)

• For the producer: more reach for their data

• For the consumer: more value from others‘ data

(26)

From From static static to to dynamic dynamic data data

Web 1.0 meant generally a Web resource was some self- contained content that couldn‘t be changed

Web 2.0 decouples the data, metadata and interfaces in a

resource, allowing their separation and re-use

(27)

AG Netzbasierte Informationssysteme http://www.ag-nbi.de

27

Web 2.0 Web 2.0

„Web 1.0 was all about connecting people. It was an interactive space, and I think Web 2.0 is of

course a piece of jargon, nobody even knows what it means. If Web 2.0 for you is blogs and wikis, then that is people to people. But that was what the Web was supposed to be all along .“

Tim Berners-Lee

(28)

Web Web APIs APIs

• Interfaces to the data in websites accessible by other programs on the Web

• Often used by server-side code to integrate others‘ data into Web pages

• Also used in client-side programming to retrieve and re-use data on the Web in a form other than HTML

• Usually provided in different programming languages, including usual Web languages – JavaScript, PHP, Ruby

• API interaction based on one of two Web models

• REST – use of URIs encoding the call and HTTP to transport it (simple and lightweight, each interaction can be uniquely defined)

• SOAP – use of XML-based messages POSTed to the server (can

capture more complex requests and responses)

(29)

AG Netzbasierte Informationssysteme http://www.ag-nbi.de

29

Programmable

Programmable Web Web

(30)

Top APIs for Mashups

(31)

AG Netzbasierte Informationssysteme http://www.ag-nbi.de

31

Request

Request : REST : REST

• Most APIs provide for RESTful access, e.g. method calls by HTTP GET to an URL constructed thus:

[base URL for the API]/[method]

?param1=value1&param2=value2

• The response from this URL can be programmatically retrieved

using JavaScript and XMLHttpRequest

(32)

Response: JSON Response: JSON

• Return format has usually been XML, due to verbosity more lightweight structures are proposed

• JSON (JavaScript Object Notation) has been specified (RFC4627) and used in Web APIs such as from Yahoo

• Despite the name it is intended to be language independent (json.org provides bindings)

• Formally, it is a subset of JavaScripts object literal notation hence a JavaScript object can be retrieved through eval()

Parsed to a JavaScript object,

var p = eval(„(„+ JSON_text + „)“);

fields such as p.firstName, p.address.city and p.phoneNumbers[0] are now

accessible

(33)

AG Netzbasierte Informationssysteme http://www.ag-nbi.de

33

(34)

Another

Another request request : XML : XML - - RPC RPC

• REST and SOAP you already know

• The other common Web Service interface is XML-RPC

• What is XML-RPC?

• Remote Procedure Calling over the Web

• HTTP as transport and XML as the encoding

• XML encoded request and response

• Only a handful of defined datatypes and commands

• Simple, compared to classically complex RPC systems

• Preferred to SOAP due to its minimalism and ease of use

(35)

AG Netzbasierte Informationssysteme http://www.ag-nbi.de

35

Another

Another request request : XML : XML - - RPC (II) RPC (II)

• simple structure

• no namespaces

• no encoding

• fast parsers that DO NOT need:

• namespaces

• attributes

• DTDs

Æ quite high

performance

(36)

Another

Another response response : PHP : PHP

• XML processing can be quite resourceful (needs parsing)

• One advantage of Web APIs is direct binding into other webpages

• Requires a directer, lighter inclusion of API responses into Web- based programs

• PHP is a programming language used mainly in server-side scripting

• Used to create dynamic webpages, potentially based on content from other pages retrieved over Web APIs

• Service response can be provided as a serialized data structure to

a PHP program

(37)

XML in

XML in Use Use: : Flickr API Flickr API

(38)

• A photo-sharing application

• the centre of a big distributed system

• An open set of APIs at: flickr.com/services/

• It supports various message types

• Request-formats

• REST

• XML-RPC

• SOAP

• Respons formats

• REST

• XML-RÜS

• SOAP

• JSON

• PHP

(39)

AG Netzbasierte Informationssysteme http://www.ag-nbi.de

39

Another

Another SOAP SOAP Example Example : API : API

• Flickr makes available a public API for applications to acquire information about the photos it has

• Two message structures

• SOAP Request

• SOAP Response

(40)

SOAP Request SOAP Request

• The SOAP-Server-Endpoint is http://api.flickr.com/services/soap/

• To use the service "flickr.test.echo" send the following SOAP request:

• no authentication needed

<s:Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope"

xmlns:xsi=http://www.w3.org/1999/XMLSchema-instance xmlns:xsd="http://www.w3.org/1999/XMLSchema" >

<s:Body>

<x:FlickrRequest xmlns:x="urn:flickr">

<method>flickr.test.echo</method>

<name>value</name>

</x:FlickrRequest>

</s:Body>

</s:Envelope>

(41)

AG Netzbasierte Informationssysteme http://www.ag-nbi.de

41

SOAP Response SOAP Response

• A simple call to the echo service will give the following SOAP response:

<?xml version="1.0" encoding="utf-8" ?>

<s:Envelope xmlns:s=http://www.w3.org/2003/05/soap-envelope

xmlns:xsi=http://www.w3.org/1999/XMLSchema-instance xmlns:xsd="http://www.w3.org/1999/XMLSchema" >

<s:Body>

<x:FlickrResponse xmlns:x="urn:flickr">

[escaped-xml-payload]

</x:FlickrResponse>

</s:Body>

</s:Envelope>

(42)

SOAP Fault SOAP Fault

<?xml version="1.0" encoding="utf-8" ?>

<s:Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope">

<s:Body>

<s:Fault>

<faultcode>flickr.error.[error-code]</faultcode>

<faultstring>[error-message]</faultstring>

<faultactor> http://www.flickr.com/services/soap/</faultactor>

<details> Please see http://www.flickr.com/services/docs/ for more details</details>

</s:Fault>

</s:Body>

</s:Envelope>

(43)

AG Netzbasierte Informationssysteme http://www.ag-nbi.de

43 API: REST

API: REST

• The REST Endpoint URL is http://api.flickr.com/services/rest/

• To request the flickr.test.echo service, invoke like this:

• The REST response is a simple XML block like this

• The fault-answer is also a simple XML block:

<?xml version="1.0" encoding="utf-8" ?>

<rsp stat="ok">

[xml-payload-here]

</rsp>

http://api.flickr.com/services/rest/?method=flickr.test.echo&name=value

<?xml version="1.0" encoding="utf-8" ?>

<rsp stat="fail">

<err code="[error-code]" msg="[error-message]" />

</rsp>

(44)

• The XML-RPC Server Endpoint URL is http://api.flickr.com/services/xmlrpc/

• To request the flickr.test.echo service, send a request like this:

<methodCall>

<methodName>flickr.test.echo</methodName>

<params>

<param>

<value>

<struct>

<member>

<name>name</name>

<value><string>value</string></value>

</member>

<member>

<name>name2</name>

<value><string>value2</string></value>

</member>

</struct>

</value>

</param>

</params>

</methodCall>

API: XML

API: XML- -RPC ( RPC ( Request Request ) )

(45)

AG Netzbasierte Informationssysteme http://www.ag-nbi.de

45

• XML-RPC response looks like this:

<?xml version="1.0" encoding="utf-8" ?>

<methodResponse>

<params>

<param>

<value>

<string> [escaped-xml-payload] </string>

</value>

</param>

</params>

</methodResponse>

API: XML

API: XML- -RPC (Response) RPC (Response)

(46)

API: PHP API: PHP

• You can make REST requests to Flickr in PHP

• With the response format set to serialized PHP you get a string which PHP can unserialize()

• In the case something went wrong

a:3:{s:4:"stat";s:4:"fail";s:4:"code";i:99;s:7:"message";

s:72:"Insufficient permissions. Method requires read privileges; none granted.";}

$url = "http://api.flickr.com/services/rest/?".implode('&', $encoded_params);

$rsp = file_get_contents($url);

$rsp_obj = unserialize($rsp);

a:4:{s:6:"method";a:1:{s:8:"_content";s:16:"flickr.test.echo";}

s:6:"format";a:1:{s:8:"_content";s:10:"php_serial";}s:7:"api_key";

a:1:{s:8:"_content";s:32:"16f702af86639e58aca80bda7b6b0175";}

s:4:"stat";s:2:"ok";}

(47)

AG Netzbasierte Informationssysteme http://www.ag-nbi.de

47 Use Use the the API for API for photo photo search search

http://www.flickr.com/services/api/explore/

(48)

How are How are people people using using the the API? API?

(49)

AG Netzbasierte Informationssysteme http://www.ag-nbi.de

49

Wie geht es weiter?

Wie geht es weiter?

heutige

heutige Ü Ü bung bung

; SOAP

; Übungsblatt 6 online

Ü Ü bung n bung n ä ä chste Woche chste Woche – – letzte letzte Ü Ü bung bung

ƒ WSDL

ƒ Musterlösungen zu Übungsblatt 5 & 6

ƒ Kleinigkeiten zur Klausur

In diesen Übungsfolien wurden Folien von K. Schild & L. Nixon benutzt.

Referenzen

ÄHNLICHE DOKUMENTE

Universal Description, Discovery, and Integration (UDDI) Business Process Execution.

 Benennen Sie anhand der vorgestellten Anwendungen des Semantic Web, wo Mehrwert durch diese Technologien entsteht, den man nicht mehr. herkömmlichen Informationssystemen

Write a rule program in Prova syntax (http://prova.ws; ISO Prolog synax) to compute the entrance price, The program should implement the following rules:.. • Couples receives

Als Ergebnis sollen sie dann drei Lucene Indexes erhalten, in dem man durch Eingabe eines Suchtextes Ihre HTML Daten, XML Daten und (f nf) Bilder finden kann.. Aufgabe 23:

In der Nutch Web Anwendung soll es dann möglich sein, eine (gerankte) Liste von Seiten zu bekommen, die Outlinks zu einer genannten Seite haben (die URL der Seite kann benutzt

Nehmen Sie den Text BNegativ1.xml aus dem Korpus vom 8.Übungsblatt und erstellen Sie für den Artikelinhalt eine Textaufschlüsselung ähnlich zu OpenCalais unter Verwendung von

Implementieren sie ein grafisches User Interface, das die NASA World Wind 3D Engine API (http://worldwind.arc.nasa.gov/index.html) nutzt, um die vom ACM Literatur Portal extrahierten

Prinzipien, Beschränkungen und Gute Praxis. • Prinzip: