1 / 89

Web Service Programming and Cloud Computing

Web Service Programming and Cloud Computing. Bigger view of programming. What we learnt are mostly small, standalone programming tasks In real world an application involves several tiers and languages RPC Client/server architecture Browser, http server Browser, http server, DB

Télécharger la présentation

Web Service Programming and Cloud Computing

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Web Service Programming andCloud Computing

  2. Bigger view of programming • What we learnt are mostly small, standalone programming tasks • In real world an application involves several tiers and languages • RPC • Client/server architecture • Browser, http server • Browser, http server, DB • Browser, http server, application server, DB • … … • Languages involved • Client side: Html, javascript, xml, css, xslt; • Server side: php, java, python, map/reduce, J2EE, sql, …

  3. Web Service

  4. Discovery agency Provider Requester Service Oriented Architecture publish find interact

  5. A concrete SOA Registry Points to description WSDL publish Finds Service Describes Service Service Consumer Web Service Provider SOAP Communicates with XML Messages

  6. Web Service definition • “encapsulated, loosely coupled, contracted software objects offered via standard protocols” --ZapThink Research • Encapsulated • Web Service implementation is invisible to entities outside the service • Exposes an interface but hides details • Loosely Coupled • Service and consumer software can be redesigned independently

  7. History of Interface Definition Languages (IDLs) • IDL has a long history in distributed computing • DCE (Distributed Computing Environment) • CORBA IDL, OMG (Object Management Group) • COM IDL, Microsoft • WSDL • Traditional IDLs • Specifying what to call: the operation names, their signatures, exceptions. This is the job of IDL. • Agreeing on how to make an invocation: the mechanism of naming, activation, data encoding. This is what distributed standards such as CORBA or COM do. • WSDL needs to specify the both: the operation provided by the service, and the mechanism to access the service.

  8. Web Service Description Language • WSDL defines • What the service is: the operations the service provides, including the signature of the operation –- what • Access specification: details of the data format and protocol necessary to access the service’s operation–- how • Location of the service: details of the network address, such as a URL –- where

  9. Legend: • What • how • where WSDL functionality view Interface Supports Port Type Operation How to invoke Formats & Protocols Input & Output Binding Message How to encode Implements Provides Port Service Endpoints In WSDL 2.0, portType is changed to interface.

  10. WSDL specification abstract part types messages operations port types concrete part bindings services and ports WSDL document structure view

  11. <?xml version="1.0"?> <definitions name="Procurement" targetNamespace="http://example.com/procurement/definitions" xmlns:tns="http://example.com/procurement/definitions" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns="http://schemas.xmlsoap.org/wsdl/" > <message name="OrderMsg"> <part name="productName" type="xs:string"/> <part name="quantity" type="xs:integer"/> </message> <portType name="procurementPortType"> <operation name="orderGoods"> <input message = "OrderMsg"/> </operation> </portType> <binding name="ProcurementSoapBinding" type="tns:procurementPortType"> <soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/> <operation name="orderGoods"> <soap:operation soapAction="http://example.com/orderGoods"/> <input> <soap:body use="literal"/> </input> <output> <soap:body use="literal"/> </output> </operation> </binding> <service name="ProcurementService"> <port name="ProcurementPort" binding="tns:ProcurementSoapBinding"> <soap:address location="http://example.com/procurement"/> </port> </service> </definitions> abstract part messages operation and port type concrete part binding port and service

  12. <definitions … name="BNQuoteService"> <message name="getPriceRequest"><part name="isbn" type="xsd:string"/></message> <message name="getPriceResponse"><part name="return" type="xsd:float"/> </message> <portType name="BNQuotePortType"> <operation name="getPrice"> <input name="getPrice" message="tns:getPriceRequest"/> <output name="getPriceResponse" message="tns:getPriceResponse"/> </operation> </portType> <binding name="BNQuoteBinding" type="tns:BNQuotePortType"> <soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/> <operation name="getPrice"><soap:operation/> <input><soap:body use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="urn:xmethods-BNPriceCheck"/> </input> <output> <soap:body use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="urn:xmethods-BNPriceCheck"/> </output> </operation> </binding> <service name="BNQuoteService"> <documentation>Returns price of a book at BN.com given an ISBN number</documentation> <port name="BNQuotePort" binding="tns:BNQuoteBinding"> <soap:address location="http://services.xmethods.net:80/soap/servlet/rpcrouter"/> </port> </service> </definitions>

  13. Visual representation

  14. WSDL structure—interconnection view WSDL document Types (type information for the document, e.g., XML Schema) Message 1 Message 2 Message 3 Message 4 Message 5 Abstract description of the service Operation 1 Operation 2 Operation 3 Interface (abstract service) binding 1 binding 2 binding 3 binding 4 endpoint 1 endpoint 2 endpoint 3 endpoint 4 Concrete description of the service Service (the interface in all its available implementations) By Gustavo Alonso and Cesare Pautasso

  15. A WSDL example <?xml version="1.0"?> <definitions name="PriceCheck" targetNamespace="http://www.skatestown.com/services/PriceCheck" xmlns:pc="http://www.skatestown.com/services/PriceCheck" xmlns:avail="http://www.skatestown.com/ns/availability" xmlns:wsi="http://ws-i.org/schemas/conformanceClaim/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns="http://schemas.xmlsoap.org/wsdl/"> <types> …</types> <message> …</message> <message> … </message> <portType> … </portType> <binding> … </binding> <service> … </service> </definitions> This example is from Steve Graham et al: Building Web Services with Java

  16. PortType <portType name="PriceCheckPortType"> <operation name="checkPrice"> <input message="pc:PriceCheckRequest"/> <output message="pc:PriceCheckResponse"/> </operation> </portType> • <portType> defines the interface of web service. Just as Java Interface declaration; • Will change the name to <interface> in WSDL 2.0. • It consists of a sequence of operation declarations. • WSDL can have zero or more <portType>s. Typically just one. • It has a name attribute, must be unique. • The binding will refer the portType by its name

  17. Operation • Operation defines a method signature; • Name, input, output, and fault • Input and output elements are associated with messages; • Different combinations of input/output define different operations types. <operation name="checkPrice"> <input message="pc:PriceCheckRequest"/> <output message="pc:PriceCheckResponse"/> </operation>

  18. Operation Types • The request-response type is the most common operation type, but WSDL defines four types: • Request-response: The operation can receive a request and will return a response <operation name="checkPrice"> <input message="pc:PriceCheckRequest"/> <output message="pc:PriceCheckResponse"/> </operation> • One-way: The operation can receive a message but will not return a response. <operation name=“cancellation”> <input message=“tns:orderCancellation”/> </operation> • Notification:The operation can send a message but will not wait for a response <operation name=“notification”> <output message=“tns:promotionNotification”/> </operation> • Solicit-response:The operation can send a request and will wait for a response <operation name=“cancellation”> <output message=“tns:pushThis”/> <input message=“tns:reponseToPush”/> </operation> • Different types are decided by the order/occurrences of input and output.

  19. Messages <message name="PriceCheckRequest"> <part name="sku" element="avail:sku"/> </message> <message name="PriceCheckResponse"> <part name="result" element="avail:StockAvailability"/> </message> • Describe the abstract form of input, output, or fault. • A WSDL file can have zero or more messages. • Each message has a name, which is unique within the document. • Each message has a collection of <part> elements.

  20. Part <part name="sku" element="avail:sku"/> <part name="result" element="avail:StockAvailability"/> • A <part> element can be compared to a parameter in a method. • A part element has two properties: one is name, the other is its kind. • Kind can be a type or an element • Element refers to an element defined in XML Schema • Type refers to a simpleType or a complexType in XSD • In corresponding sku definition is: <xsd:element name="sku" type="xsd:string" />

  21. Types in WSDL <types> <xsd:schema targetNamespace="http://www.skatestown.com/ns/availability" > <xsd:element name="sku" type="xsd:string" /> <xsd:complexType name="availabilityType"> <xsd:sequence> <xsd:element ref="avail:sku"/> <xsd:element name="price" type="xsd:double"/> <xsd:element name="quantityAvailable" type="xsd:integer"/> </xsd:sequence> </xsd:complexType> <xsd:element name="StockAvailability" type="avail:availabilityType" /> </xsd:schema> </types> • The default type system is XML Schema; • Theoretically you can use any type system, such as Java types. • To be used in<part> element; • We can also import XML Schemas

  22. SOAP request message <soapenv:Envelope xmlns:soapenv=“http://schema.xmlsoap.org/soap/evelope/” xmlns:xsd=“http://www.w3.org/2001/XMLSchema” xmlns:xsi=“http://www.w3.org/2001/XMLSchema-instance”> <soapenv:Body> <sku xmlns=“http://www.skatestown.com/ns/availability”>123</sku> </soapenv:Body> </soapenv:Envelope> • Relevant part of the WSDL file: <xsd:element name="sku" type="xsd:string" /> <message name="PriceCheckRequest"> <part name="sku" element="avail:sku"/> </message> <operation name="checkPrice"> <input message="pc:PriceCheckRequest"/> <output message="pc:PriceCheckResponse"/> </operation> Envelope Header #0 Header #1 Body Message Payload

  23. <soapenv:Envelope xmlns:soapenv= … xmlns:xsd=… xmlns:xsi=… > <soapenv:Body> <StockAvailability xmlns= … > <sku> 123 </sku> <price xmlns=“”>100.00</price> <quantityAvailable xmlns=“”> 12 </quantityAvailable> </StockAvailability> </soapenv:Body> </soapenv:Envelope> Relevant part of the WSDL file: <xsd:complexType name="availabilityType"> <xsd:sequence> <xsd:element ref="avail:sku"/> <xsd:element name="price" type="xsd:double"/> <xsd:element name="quantityAvailable" type="xsd:integer"/> </xsd:sequence> </xsd:complexType> <message name="PriceCheckResponse"> <part name="result" element="avail:StockAvailability"/> </message> <operation name="checkPrice"> <input message="pc:PriceCheckRequest"/> <output message="pc:PriceCheckResponse"/> </operation> SOAP response message

  24. Binding <binding name="PriceCheckSOAPBinding" type="pc:PriceCheckPortType"> <soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http" /> <operation name="checkPrice"> <soap:operation soapAction = "http://www.skatestown.com/services/PriceCheck/checkPrice" /> <input> <soap:body use="literal" /> </input> <output> <soap:body use="literal" / </output> </operation> </binding> • Name of the binding should be unique; • Link to the portType is achieved by the portType name • This explains why portType name should be unique. • Typically, there is only one <binding> element; • Defines: • Invocation style: rpc vs. document • SOAPAction • Input message appearance: literal or encoded • Output message appearance

  25. Service <service name="PriceCheck"> <port name="Pricecheck" binding="pc:PriceCheckSOAPBinding"> <documentation> <wsi:Claim conformsTo="http://ws-i.org/profiles/basic/1.0" /> </documentation> <soap:address location ="http://www.skatestown.com/services/PriceCheck"/> </port> </service> • Contains a set of <port> elements; • <port> combines the interface binding with a network address specified by a URI; • A web service can be available in different web addresses;

  26. Tools • WSDL parser: WSDL4J • Apache Axis • Invoking SOAP web service; • Translate WSDL to Java, and vice versa; • Mapping Java into XML Schema, and vice versa; • Host web service; • API for manipulating SOAP;

  27. Mapping between Java and WSDL in JAX-RPC • A simple example <message name="fooRequest"> <part name="para1" type="xs:string"/> </message> <message name="fooResponse"> <part name="para2" type="xs:float"/> </message> <portType name="FooBar"> <operation name="foo"> <input message="y:fooRequest"/> <output message="y:fooResponse"/> </operation> </portType> public interface FooBar extends java.rmi.Remote{ public float foo(java.lang.String para1) throws java.rmi.RemoteException; }

  28. Multiple input parameters <message name="fooRequest"> <part name="param1" type="xs:string"/> <part name="param2" type="xs:int"/> <part name="param3" type="xs:boolean"/> </message> <message name="fooResponse"> <part name="para2" type="xs:float"/> </message> <portType name="FooBar"> <operation name="foo"> <input message="y:fooRequest"/> <output message="y:fooResponse"/> </operation> </portType> public interface FooBar extends java.rmi.Remote{ public float foo(String param1, int param2, boolean param3) throws java.rmi.RemoteException; }

  29. Multiple output parameters <message name="fooRequest"> <part name="param1" type="xs:string"/> </message> <message name="fooResponse"> <part name="param2" type="xs:int"/> <part name="param3" type="xs:boolean"/> <part name="param4" type="xs:float"/> </message> <portType name="FooBar"> <operation name="foo"> <input message="y:fooRequest"/> <output message="y:fooResponse"/> </operation> </portType> public interface FooBar extends java.rmi.Remote{ public void foo(String param1, javax.xml.rpc.holders.IntHolder param2, javax.xml.rpc.holders.BooleanHolder param3, javax.xml.rpc.holders.FloatHolder param4, ) throws java.rmi.RemoteException; }

  30. Mapping XML Schema to Java public class Address { private String street; private String city; public String getCity(){return city; } public void setCity(String c){city=c; } … … } <complexType name="Address"> <sequence> <element name="city" nillable="true" type="xsd:string"/> <element name="street" nillable="true" type="xsd:string"/> </sequence> </complexType> • Class has to have correct getters and setters; • In axis, you can use WSDL2Java and Java2WSDL to do the mapping.

  31. 60-440 03-60-440 Mashups

  32. 60-440 03-60-440 Mashups

  33. 60-440 Mashups • From Wikipedia • Mashup (music), a musical genre of songs that consist entirely of parts of other songs • Mashup (video), a video that is edited from more than one source to appear as one • Mashup (web application hybrid), a web application that combines data and/or functionality from more than one source • Combine data from multiple sources. • Mostly the data sources lay outside of the organizational boundaries • Create a new and distinct web service that was not originally provided by either source. • Content is typically sourced via a web API or a RSS Feed Mashup

  34. 60-440 Mashup example • The ChicagoCrime.org Web site • A mapping mashup • One of the first popular mashups • Mashes crime data from the Chicago Police Department’s online database with cartography from Google Maps • The concept and the presentation are simple and the composition of crime and map data is visually powerful Mashup The following slides are borrowed from Umut Orhan

  35. 60-440 Why mashup • Everybody needs customized applications, tailored to his/her own requirements, taste, style. • DIY in software/web application construction • There are many building blocks (web APIs, web services) • there are also some tools to assemble the building blocks • It is like end-user programming

  36. 60-440 Mashup flavours • Presentation mashups: e.g. Google Maps apps, with emphasis on presentation • This is the shallowest form of mashup in the sense that underlying data and functionality don’t meet.  Information and layout is retrieved and either remix or just placed next to each other.  Many of the Ajax desktops today fall into this category and so do portals and other presentation mashup techniques. • Data mashups: merging data from different sources • Business mashup: combination of above. combines data integration, presentation plus addition functionality, such as collaboration features Mashup

  37. 60-440 Map mashups • Locational information presented graphically using maps in a specified context • Google Maps API opened the floodgates • mash all sort of data from nuclear disasters to Boston’s CowParade cows onto maps • Other APIs • Microsoft (Virtual Earth) • Yahoo (Yahoo Maps) • AOL (MapQuest) Mashup Genres

  38. 60-440 Photo and Video • Photo/video hosting and social networking sites resulted interesting mashups. • Flickr • YouTube • Facebook • Metadata associated with the hosted images and videos • Who took the picture • What it is a picture of • Where and when it was taken • So on… Mashup Genres

  39. 60-440 Search and shopping • Exist long before the term Mashup was coined • Combinations of B2B technologies or screen-scraping to aggregate comparative price data • eBay • Amazon • … Mashup Genres

  40. 60-440 News • News sources such as BBC and Reuters have used syndication technologies like RSS and Atom since 2002. • Personalized newspaper by Syndication feed mashups • Doggdot.us, combines feeds from the techie-oriented news sources Digg.com, Slashdot.org and Del.icio.us Mashup Genres

  41. 60-440 Content provider • Web Protocols • REST Services • SOAP Web Services • RSS/Atom • Screen Scraping • Scraping is the process of using software tools to parse and analyze content that was originally written for human consumption in order to extract semantic data structures representative of that information that can be used and manipulated programmatically.

  42. 60-440 Mashup platforms • IGoogle • Yahoo Pipes • Openkapow • IBM QedWiki • Microsoft popfly • Google Mashup Editor (migrated to Google App Engine) • … … Mashup platforms

  43. 60-440 Yahoo! pipes • Visual development environment for generating data-oriented mashups • Development is based on: • Dragging gadgets (pipes) from a toolbox and dropping them in work zone • Specifying data input • Interconnecting gadgets through pipes • Specifying data output format Mashup platforms

  44. 60-440 Ajax • AJAX (Asynchronous JavaScriptand XML) • Ajax and AJAX • Characteristic: increased responsiveness and interactiveness of web pages • exchanging small amounts of data with the server • entire web page does not have to be reloaded each time the user performs an action. • Not a technology itself, but a term refer to the use of a group of technologies • The "core" and defining element of Ajax is the XMLHttpRequest object, which gives browsers the ability to make dynamic and asynchronous data requests without having to reload a page, eliminating the need for page refreshes. Web 2.0 The following slides are from Jimmy Lin The iSchool University of Maryland

  45. 60-440 “Old-School” Web Applications server generates Web page as a response to the request browser sends request to server user does something 1 3 2 4 5 data is returned in response to the request browser replaces view with data sent from server server-side systems browser HTTP request Web server backend database Interface HTTP response

  46. 60-440 Characteristics User-driven: Things only happen when the user does something (e.g., clicks on a link or button) Views defined by URLs: You can bookmark something and come back to it; use the forward/backward button Simple user interaction model: Not that many things you can do in browser Synchronous Interaction: System responses are synchronized with user-driven events

  47. 60-440 Synchronous Interactions 1 5 2 4 3 server-side systems browser 1 2 HTTP request 4 HTTP response 3 5 browser user activity user activity user activity Time Response  Response  Request  Request  server-side server processing server processing

  48. 60-440 So what do you run on the server side? L A M P Linux Apache MySQL PHP/Python/Perl

  49. 60-440 From “Old-School” to Ajax Ajax “engine” data management interaction management Ajax intermediates between the interface and the server. browser server-side systems request Web server backend database Interface response

  50. 60-440 Inside the Browser browser HTTP request HTML / CSS data Interface Rendering Engine other data(e.g. images) HTTP response

More Related