Upload
others
View
1
Download
0
Embed Size (px)
Citation preview
ÜÜbung 6 bung 6 -- SOAPSOAP
Dr. Malgorzata Mochol Freie Universität Berlin Institut für Informatik Netzbasierte [email protected]
AG Netzbasierte Informationssysteme http://www.ag-nbi.de 2
ÜÜbung 6bung 6
SOAP + XSLT
Musterfragen zu SOAP
Web APIs
XML In Use: Flickr APIs
AG Netzbasierte Informationssysteme http://www.ag-nbi.de 3
Web ServicesWeb Services
Web Service
WSDL
BeschreibtService
UDDIVerzeichnis
Sucht nachService
Verweist aufdie Service-Beschreibung
Verweist auf den Service
SOAPService Nutzer (Service Consumer)
SOAP + XSLTSOAP + XSLT
AG Netzbasierte Informationssysteme http://www.ag-nbi.de 5
WhyWhy SOAP + XSLT?SOAP + XSLT?
SOAP messages are XML and hence can be manipulatedby 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
SOAP + XSLT: SOAP + XSLT: GenericGeneric SOAP Web ServiceSOAP Web Service
AG Netzbasierte Informationssysteme http://www.ag-nbi.de 7
ExampleExample
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)
AG Netzbasierte Informationssysteme http://www.ag-nbi.de 8
ProblemProblem
• 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.
AG Netzbasierte Informationssysteme http://www.ag-nbi.de 9
PossiblePossible SolutionsSolutions
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
AG Netzbasierte Informationssysteme http://www.ag-nbi.de 10
Solution BSolution 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
AG Netzbasierte Informationssysteme http://www.ag-nbi.de 11
XPathXPath
• 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()
AG Netzbasierte Informationssysteme http://www.ag-nbi.de 12
ConclusionsConclusions
• 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/
MusterfragenMusterfragen
AG Netzbasierte Informationssysteme http://www.ag-nbi.de 14
MusterfragenMusterfragen
• Which elements are NOT part of the SOAP-message?
1. soap:Content
2. soap:Head
3. soap:Header
4. soap:Body
AG Netzbasierte Informationssysteme http://www.ag-nbi.de 15
MusterfragenMusterfragen
• Which SOAP element is the root element?
1. soap:Fault
2. soap:Envelope
3. soap:Header
4. soap:Body
AG Netzbasierte Informationssysteme http://www.ag-nbi.de 16
MusterfragenMusterfragen
• 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>
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
MusterfragenMusterfragen
AG Netzbasierte Informationssysteme http://www.ag-nbi.de 18
MusterfragenMusterfragen
• 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
AG Netzbasierte Informationssysteme http://www.ag-nbi.de 19
MusterfragenMusterfragen
• 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>
AG Netzbasierte Informationssysteme http://www.ag-nbi.de 20
MusterfragenMusterfragen
• 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
AG Netzbasierte Informationssysteme http://www.ag-nbi.de 21
MusterfragenMusterfragen
• 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>
AG Netzbasierte Informationssysteme http://www.ag-nbi.de 22
MusterfragenMusterfragen
• What is allowed?
1. enc:arraySize="* *"
2. enc:arraySize="* 4"
3. enc:arraySize="4 *"
4. enc:arraySize=" "
AG Netzbasierte Informationssysteme http://www.ag-nbi.de 23
MusterfragenMusterfragen
• How can you specify the encoding-Style?
1. use="literal"
2. use="encoded" encodingStyle="…"
3. use="encoded"
4. use="coded" encodingStyle="…"
Web Web APIsAPIs
AG Netzbasierte Informationssysteme http://www.ag-nbi.de 25
Web 2.0Web 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
AG Netzbasierte Informationssysteme http://www.ag-nbi.de 26
FromFrom staticstatic to to dynamicdynamic datadata
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
AG Netzbasierte Informationssysteme http://www.ag-nbi.de 27
Web 2.0Web 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
AG Netzbasierte Informationssysteme http://www.ag-nbi.de 28
Web Web APIsAPIs
• 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)
AG Netzbasierte Informationssysteme http://www.ag-nbi.de 29
ProgrammableProgrammable WebWeb
AG Netzbasierte Informationssysteme http://www.ag-nbi.de 30
Top APIs for Mashups
AG Netzbasierte Informationssysteme http://www.ag-nbi.de 31
RequestRequest: 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¶m2=value2
• The response from this URL can be programmatically retrieved using JavaScript and XMLHttpRequest
AG Netzbasierte Informationssysteme http://www.ag-nbi.de 32
Response: JSONResponse: 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
AG Netzbasierte Informationssysteme http://www.ag-nbi.de 33
AG Netzbasierte Informationssysteme http://www.ag-nbi.de 34
AnotherAnother requestrequest: XML: XML--RPCRPC
• 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
AG Netzbasierte Informationssysteme http://www.ag-nbi.de 35
AnotherAnother requestrequest: XML: XML--RPC (II)RPC (II)
• simple structure• no namespaces• no encoding• fast parsers that DO NOT need:
• namespaces• attributes• DTDs
quite high performance
AG Netzbasierte Informationssysteme http://www.ag-nbi.de 36
AnotherAnother responseresponse: 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
XML in XML in UseUse: : FlickrFlickr APIAPI
AG Netzbasierte Informationssysteme http://www.ag-nbi.de 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
AG Netzbasierte Informationssysteme http://www.ag-nbi.de 39
AnotherAnother SOAP SOAP ExampleExample: 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
AG Netzbasierte Informationssysteme http://www.ag-nbi.de 40
SOAP RequestSOAP 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>
AG Netzbasierte Informationssysteme http://www.ag-nbi.de 41
SOAP ResponseSOAP 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>
AG Netzbasierte Informationssysteme http://www.ag-nbi.de 42
SOAP FaultSOAP 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>
AG Netzbasierte Informationssysteme http://www.ag-nbi.de 43
API: RESTAPI: 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>
AG Netzbasierte Informationssysteme http://www.ag-nbi.de 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: XMLAPI: XML--RPC (RPC (RequestRequest))
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: XMLAPI: XML--RPC (Response)RPC (Response)
AG Netzbasierte Informationssysteme http://www.ag-nbi.de 46
API: PHPAPI: 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";}
AG Netzbasierte Informationssysteme http://www.ag-nbi.de 47
UseUse thethe API API forfor photophoto searchsearch
http://www.flickr.com/services/api/explore/
AG Netzbasierte Informationssysteme http://www.ag-nbi.de 48
HowHow areare peoplepeople usingusing thethe API?API?
AG Netzbasierte Informationssysteme http://www.ag-nbi.de 49
Wie geht es weiter?Wie geht es weiter?
heutige heutige ÜÜbungbungSOAPÜbungsblatt 6 online
ÜÜbung nbung näächste Woche chste Woche –– letzte letzte ÜÜbungbungWSDL Musterlösungen zu Übungsblatt 5 & 6Kleinigkeiten zur Klausur
In diesen Übungsfolien wurden Folien von K. Schild & L. Nixon benutzt.