Presentation is loading. Please wait.

Presentation is loading. Please wait.

Design of Distributed Software 2.7 Web Services 1.Introduction : Service Oriented Architectures 2.Technology building blocks 3.Java Web Services.

Similar presentations


Presentation on theme: "Design of Distributed Software 2.7 Web Services 1.Introduction : Service Oriented Architectures 2.Technology building blocks 3.Java Web Services."— Presentation transcript:

1 Design of Distributed Software 2.7 Web Services 1.Introduction : Service Oriented Architectures 2.Technology building blocks 3.Java Web Services

2 Design of Distributed Software2 Web Service 1. Introduction “A Web service is a software application identified by a URI whose interfaces and binding are capable of being defined, described, and discovered by XML artifacts, and supports direct interactions with other software applications using XML-based messages via Internet-based protocols.” Service interface Service implementation Service implementation : -any application - any programming language - any platform - remotely available through web service provider Service definition/interface : - defines the service - in XML-syntax - not necessarily on same machine as service implementation - includes : - data types involved - supported method calls - network location WEB SERVICE XML- message

3 Design of Distributed Software3 Service-Oriented Architectures 1. Introduction Vision Services should be dynamically discoverable, Separation between service description and implementation Assemble application “ad hoc” based on discovered services “Service-oriented architectures” provider requestor registry broker owner of the service runs the service remotely offers XML-description of service manages info repository on providers and services white pages : business info on provider (name, description, …) green pages : info how to use the service (policies, software bindings, …) yellow pages : key-word based search engine for services discovers and invokes service can be person/application/service

4 Design of Distributed Software4 Service-Oriented Architectures 1. Introduction provider requestor registry 1 : publish 2 : find Alternative : no registry - direct publishing : offline mechanism to locate service - use HTTP GET request on service provider webserver Dynamic publishing Query public/private registry Specifies service type Can include QoS requirements 3 : bind retrieve service description (how to access service ?) default : from provider alternative : from broker access the service

5 Design of Distributed Software5 Web Service Technology 2. Technology “Simple Object Access Protocol” RPC-protocol for web services used to access remote service “Web Services Description Language” description of how to access web service used to access remote service “Representational State Transfer” XML directly over HTTP URI per method

6 Design of Distributed Software6 Web Service Technology 2. Technology Servlet JSP/ASP Web service CORBA RMI HTTP SOAP over HTTP/SMTP IIOP binary protocol object oriented text protocol not object oriented text protocol object oriented

7 Design of Distributed Software7 SOAP : philosophy and architecture 2. Technology text-oriented protocol (XML-messages) messages can have attachments object oriented (descendant from XML-RPC) specifies object attributes methods to call easy access : on top of HTTP or SMTP (no blocking, clear text) Layered approach SOAP RPC Encoding Rules Messaging Framework HTTP Binding SMTP Binding HTTPSMTP Syntax of SOAP-messages “Envelopes” Mapping to transport protocol Map RPC request To message (data-type -> XML) Rules for SOAP-RPC

8 Design of Distributed Software8 SOAP messages 2. Technology SOAP envelope SOAP header SOAP body SOAP block … … Container for SOAP message Defines relevant xml namespaces, encodings Directives to SOAP-processor Not always forwarded by intermediary SOAP-nodes Header content standardized by SOAP Payload, message data To be processed by ultimate receiver SOAP-processor = environment receiving/processing/forwarding SOAP-message (e.g. J2EE application server,.NET server, …)

9 Design of Distributed Software9 SOAP message : request example 2. Technology POST /InStock HTTP/1.1 Host: www.stock.org Content-Type: application/soap+xml; charset=utf-8 Content-Length: nnn <soap:Envelope xmlns:soap="http://www.w3.org/2001/12/soap-envelope" soap:encodingStyle="http://www.w3.org/2001/12/soap-encoding"> IBM HTTP protocol binding Specify namespaces And encoding rules RPC-specification SOAP RPC request stock.GetStockPrice(“IBM”)

10 Design of Distributed Software10 SOAP message : reply example 2. Technology HTTP/1.1 200 OK Content-Type: application/soap; charset=utf-8 Content-Length: nnn <soap:Envelope xmlns:soap="http://www.w3.org/2001/12/soap-envelope" soap:encodingStyle="http://www.w3.org/2001/12/soap-encoding"> 34.5 “return 34.5” SOAP RPC reply

11 Design of Distributed Software11 SOAP message : parameters 2. Technology <ns1:getPrice xmlns:ns1=http://mydomain/pricehttp://mydomain SOAP-ENV:encodingStyle=http://schemas.xmlsoap.org/soap/encoding/>http://schemas.xmlsoap.org/soap/encoding/ 0103785920 SOAP and Web Services Method declared as : getPrice(String, String) Invoked through : price.getPrice(“0103785920”,” SOAP and Web Services”) Native Soap types : string base64Binary(binary formatted objects, e.g. JavaBeans) integer, byte, short, int, long decimal, float, double boolean dateTime, time, date, duration

12 Design of Distributed Software12 WSDL1.1 2. Technology XML grammar to specify collection of “access end points” (1 URL specifies a single access end point) designed to automate application-to-application interaction (or B2B interaction) defines the communication protocol to be used at runtime message format methods to be invoked parameter lists, return types … WSDL descriptions can be automatically generated for existing code stub classes can be generated from WSDL descriptions Web Services Description Language

13 Design of Distributed Software13 A simple Web Service JAX-RPC package random; import java.rmi.Remote; import java.rmi.RemoteException; public interface RandomServiceIF extends Remote { public String sayHello(String s) throws RemoteException; public int getRandomNumber(int max) throws RemoteException; } RandomServiceIF.java interface MUST extend java.rmi.Remote each method MUST throw java.rmi.RemoteException can NOT be in default package method arguments must obey to special rules (map to SOAP-types) 2. Technology

14 Design of Distributed Software14 A simple Web Service JAX-RPC <definitions name="RandomService" targetNamespace="urn:RandomService" xmlns:tns="urn:RandomService" xmlns="http://schemas.xmlsoap.org/wsdl/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"> RandomService.wsdl Automatically generated 2. Technology

15 Design of Distributed Software15 A simple Web Service JAX-RPC <soap:body encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" use="encoded" namespace="urn:RandomService"/> <soap:body encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" use="encoded" namespace="urn:RandomService"/> <soap:body encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" use="encoded" namespace="urn:RandomService"/> <soap:body encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" use="encoded" namespace="urn:RandomService"/> RandomService.wsdl Automatically generated 2. Technology

16 Design of Distributed Software16 A simple Web Service JAX-RPC http://localhost:8080/random/rs?wsdl After deployment to server 2. Technology

17 Design of Distributed Software17 A simple Web Service JAX-RPC http://localhost:8080/random/rs?wsdl After deployment to server 2. Technology

18 Design of Distributed Software18 WSDL1.1 : document structure 2. Technology * * * * * * * container for service description global declaration of document scope namespaces similar to java-import (modularization of WSDL docs) include of namespaces (not file itself !) contains definition of all datatypes used in messages currently : XSD (XML Schema Definitions) defines message structure (for each part : type and name are defined) specifies legal operations for web service endpoint (=group of actions) : method definition specifies method name input message output message error message

19 Design of Distributed Software19 WSDL1.1 : document structure 2. Technology * * * * * * * concrete protocol & data format spec for portType standard soap-bindings available defines URL for service endpoint = single access point for webservice each port specifies name binding info URL of webservice ( element)

20 Design of Distributed Software20 WSDL1.1 : supported interactions 2. Technology Request – response before clientserver 1 2 Solicit - response before clientserver 1 2 One-way (asynchronous) only clientserver 1 Notification only clientserver 1

21 Design of Distributed Software21 WSDL1.1: different styles RPC/encoded RPC/literal Document/encoded (not used) Document/literal 2. Technology

22 Design of Distributed Software22 RPC/encoded 2. Technology 5 5.0 public void myMethod(int x, float y); -XSI types usually overhead - no easy validation - not WS-I compliant (WS-I defines interoperability rules)

23 Design of Distributed Software23 RPC/literal 2. Technology ; 5 5.0 public void myMethod(int x, float y); - no overhead from XSI types - still no easy validation -WS-I compliant

24 Design of Distributed Software24 Document/literal 2. Technology 5 5.0 public void myMethod(int x, float y); - no operation name (difficult dispatching) - easy validation (soap:body can be defined in a schema) - not WS-I compliant

25 Design of Distributed Software25 Document/literal wrapped 2. Technology 5 5.0 public void myMethod(int x, float y); - operation name is available - easy validation (soap:body can be defined in a schema) - WS-I compliant

26 Design of Distributed Software26 Summary WSDL styles Use document/literal wrapped except: when overloaded operations then: use document/literal unwrapped however: when several methods have same signature then: use RPC/literal in case of data graphs (e.g. binary trees), literal style is not an option, prefer RPC/encoded public void myMethod(int x, float y); public void myMethod(int x); public void myMethod(int x, float y); public void myMethod(int x); public void myOtherMethod(int x, float y); 2. Technology

27 Design of Distributed Software27 WS-Addressing WS-Addressing defines standard ways to route a message over multiple transports or direct a response to a third party. Without WS-Addressing: a standard SOAP request is sent over HTTP, the URI of the HTTP request serves as the message's destination. The message response is packaged in the HTTP response and received by the client over the HTTP connection. For example, a client application might send a request over JMS and ask to receive the response through e-mail or SMS. To enable these kinds of applications, WS- Addressing incorporates delivery, reply-to, and fault handler addressing information into a SOAP envelope. 2. Technology

28 Design of Distributed Software28 WS-Addressing example <S:Envelope xmlns:S="http://www.w3.org/2003/05/soap-envelope" xmlns:wsa="http://www.w3.org/2004/12/addressing"> http://... http://… http://… http://… 2. Technology

29 Design of Distributed Software29 WSDL2.0 W3C working draft since 2004, recommendation since july 2007 rarely used for the moment: WSDL 1.1 still widely used support for WS-Addressing interface type instead of port type no operation overloading allowed 2. Technology

30 Design of Distributed Software Web Services 1.Introduction : Service Oriented Architectures 2.Technology building blocks 3.Java Web Services 4.Netbeans support for Web Services

31 Design of Distributed Software31 Java Web Services 3. Java WS Web service front-end implemented through Servlet Application server Servlet EJBs Other resources e.g. JCA-adapters (Java Connector Architecture) JMS-resources (Java Message Service) SOAP/HTTP Servlet responsibilitiet : SOAP Parsing Resource lookup Behaviour handling

32 Design of Distributed Software32 JAX WS Java EE 5 provides a robust platform on which web services can be built and deployed (previous JAX-RPC) Web service can be built either as: Option 1: regular Java class Option 2: EJB 3 stateless session bean Option 2 allows for use of declarative transactions and security. Advantage Option 1: can be run in a web container, no need for application container. Both options can use annotations, definition of life cycle methods. Option 1 requires annotation processing in an external Annotation Processing Tool (APT) 3. Java WS

33 Design of Distributed Software33 EJB as a Web Service example @WebService @SOAPBinding(style = SOAPBinding.Style.DOCUMENT) @Stateless public class eBayBean implements eBayInterface { @PersistenceContext private EntityManager em; public eBayBean() { } @WebMethod @WebResult(name = "bidNumber") public Long addBid( @WebParam(name = "User") String userId, @WebParam(name = "Item") Long itemId, @WebParam(name = "Price") Double bidPrice) { return persistBid(userId, itemId, bidPrice); } private Long persistBid(String userId, Long itemId, Double bidPrice) { } 3. Java WS

34 Design of Distributed Software34 @WebService annotation options @ WebService { String name() default ""; String targetNamespace() default ""; String serviceName() default ""; String wsdlLocation() default ""; String endpointInterface() default ""; String portName() default ""; }; 3. Java WS

35 Design of Distributed Software35 annotation options @SOAPBinding annotation options @ SOAPBinding { public enum Style { DOCUMENT, RPC }; public enum Use { LITERAL, ENCODED }; public enum ParameterStyle { BARE, WRAPPED }; Style style() default Style.DOCUMENT; Use use() default Use.LITERAL; ParameterStyle parameterStyle() default ParameterStyle.WRAPPED; } 3. Java WS

36 Design of Distributed Software36 annotation @WebMethod annotation @WebService @Stateless public class eBayBean { public Long addBid(..) { } @WebMethod(exclude = "true") public Long persistBid(..) { } 3. Java WS

37 Design of Distributed Software37 annotation options @WebMethod annotation options @WebMethod { String operationName() default ""; String action() default "" ; boolean exclude() default false; }; 3. Java WS

38 Design of Distributed Software38 annotation @WebParam annotation @WebMethod public Long addBid( @WebParam(name = "user", mode = WebParam.Mode.IN) String userId,...) {... } 3. Java WS

39 Design of Distributed Software39 annotation options @WebParam annotation options @WebParam { public enum Mode { IN, OUT, INOUT }; String name() default ""; String targetNamespace() default ""; Mode mode() default Mode.IN; boolean header() default false; String partName() default ""; }; 3. Java WS

40 Design of Distributed Software40 @WebResult annotation + options @WebMethod @WebResult(name = "bidNumber") public Long addBid(...){} Options: @WebResult { String name() default "return"; String targetNamespace() default ""; boolean header() default false; String partName() default ""; }; 3. Java WS

41 Design of Distributed Software41 Accessing a web service from an EJB The client for the EJB web service can be any of the following types: Java application client Dynamic proxy Dynamic Invocation Interface (DII) import javax.xml.ws.WebServiceRef ; @WebServiceRef(wsdlLocation= "http://localhost:8080/eBayService/eBayBean?WSDL") private static eBayService ebs; public static void main(String [] args) { try { eBayBean ebay = ebs.geteBayBeanPort(); System.out.println("Bid Successful, BidId Received is:“ +ebay.addBid(“test", 1001, 185,0 )); } catch (Exception ex) { ex.printStackTrace(); } 3. Java WS

42 Design of Distributed Software42 EJB as a web service client @Stateless public class AmazonOrderBean implements AmazonOrder { @WebServiceRef(AmazonDeliveryService.class) private AmazonDeliverySEI deliveryService; public String checkOrderDeliverStatus(String shipId) {... String deliveryStatus = deliveryService.checkDeliveryStatus(shipId);... } 3. Java WS


Download ppt "Design of Distributed Software 2.7 Web Services 1.Introduction : Service Oriented Architectures 2.Technology building blocks 3.Java Web Services."

Similar presentations


Ads by Google