Java RMI, JAX-RPC and JWSDP

Slides:



Advertisements
Similar presentations
Message Passing Vs Distributed Objects
Advertisements

Web Service Ahmed Gamal Ahmed Nile University Bioinformatics Group
RPC Robert Grimm New York University Remote Procedure Calls.
Web Services Darshan R. Kapadia Gregor von Laszewski 1http://grid.rit.edu.
Distributed Objects and Remote Invocation
Copyright © 2001 Qusay H. Mahmoud RMI – Remote Method Invocation Introduction What is RMI? RMI System Architecture How does RMI work? Distributed Garbage.
Distributed Object & Remote Invocation Vidya Satyanarayanan.
5/15/2015B.Ramamurthy1 Creating a Distributed System with RMI B.Ramamurthy.
Remote Method Invocation
Presentation 7 part 2: SOAP & WSDL. Ingeniørhøjskolen i Århus Slide 2 Outline Building blocks in Web Services SOA SOAP WSDL (UDDI)
6/11/2015Page 1 Web Services-based Distributed System B. Ramamurthy.
Remote Method Invocation Chin-Chih Chang. Java Remote Object Invocation In Java, the object is serialized before being passed as a parameter to an RMI.
Copyright © George Coulouris, Jean Dollimore, Tim Kindberg This material is made available for private study and for direct.
Lecture 10: Web Services. Outline Overview of Web Services Create a Web Service with Sun J2EE (JAX-RPC)
Java RMI and WS B. Ramamurthy.
Java RMI, JAX-RPC and JWSDP
Introduction to Remote Method Invocation (RMI)
OCT 1 Master of Information System Management Organizational Communications and Distributed Object Technologies Lecture 5: Distributed Objects.
WSDL Web Services Description Language Neet Wadhwani University of Colorado 3 rd October, 2001.
B. RAMAMURTHY Web services. Topics What is a web service? From OO to WS WS and the cloud WS code.
From Coulouris, Dollimore, Kindberg and Blair Distributed Systems: Concepts and Design Edition 5, © Addison-Wesley 2012 Slides for Chapter 9 Web Services.
Chapter 19 Web Services. Web services infrastructure and components Security Service descriptions (in WSDL) Applications Directory service Web Services.
1 Lecture 22 George Koutsogiannakis Summer 2011 CS441 CURRENT TOPICS IN PROGRAMMING LANGUAGES.
1 3. Implementing Web Services 1.Create SOAP proxy interfaces and WSDL based service descriptions 2.Register/publish services 3.Stores service descriptions.
T Network Application Frameworks and XML Web Services and WSDL Sasu Tarkoma Based on slides by Pekka Nikander.
James Holladay, Mario Sweeney, Vu Tran. Web Services Presentation Web Services Theory James Holladay Tools – Visual Studio Vu Tran Tools – Net Beans Mario.
Information Management NTU Interprocess Communication and Middleware.
11 September 2008CIS 340 # 1 Topics To examine the variety of approaches to handle the middle- interaction (continued) 1.RPC-based systems 2.TP monitors.
Spring/2002 Distributed Software Engineering C:\unocourses\4350\slides\DefiningThreads 1 RMI.
Distributed Programming CSCI 201L Jeffrey Miller, Ph.D. HTTP :// WWW - SCF. USC. EDU /~ CSCI 201 USC CSCI 201L.
RMI remote method invocation. Traditional network programming The client program sends data to the server in some intermediary format and the server has.
 Remote Method Invocation  A true distributed computing application interface for Java, written to provide easy access to objects existing on remote.
1 Web Services Web and Database Management System.
IS473 Distributed Systems CHAPTER 5 Distributed Objects & Remote Invocation.
WEB SERVICES 1 From Chapter 19 of Distributed Systems Concepts and Design,4 th Edition, By G. Coulouris, J. Dollimore and T. Kindberg Published by Addison.
Distributed Objects & Remote Invocation
Kemal Baykal Rasim Ismayilov
Remote Method Invocation A Client Server Approach.
1 G52IWS: Web Services Description Language (WSDL) Chris Greenhalgh
Distributed objects and remote invocation Pages
UMBC Distributed Computing with Objects RMI/Corba CMSC 432 Shon Vick.
DEVELOPING WEB SERVICES WITH JAVA DESIGN WEB SERVICE ENDPOINT.
Distributed Computing & Embedded Systems Chapter 4: Remote Method Invocation Dr. Umair Ali Khan.
Software Architecture Patterns (3) Service Oriented & Web Oriented Architecture source: microsoft.
Topic 4: Distributed Objects Dr. Ayman Srour Faculty of Applied Engineering and Urban Planning University of Palestine.
Distributed Web Systems Distributed Objects and Remote Method Invocation Lecturer Department University.
Object Interaction: RMI and RPC 1. Overview 2 Distributed applications programming - distributed objects model - RMI, invocation semantics - RPC Products.
Chapter 4 Remote Method Invocation
An Introduction to Web Services
Sabri Kızanlık Ural Emekçi
WEB SERVICES From Chapter 19 of Distributed Systems Concepts and Design,4th Edition, By G. Coulouris, J. Dollimore and T. Kindberg Published by Addison.
Chapter 5 Remote Procedure Call
T Network Application Frameworks and XML Web Services and WSDL Sasu Tarkoma Based on slides by Pekka Nikander.
Slides for Chapter 19 Web Services
Distributed Systems Course Topics in distributed objects
Programming Models for Distributed Application
Slides for Chapter 19 Web Services
Lecture 4: RPC Remote Procedure Call Coulouris et al: Chapter 5
Introduction to Web Services
Lecture 4: RPC Remote Procedure Call CDK: Chapter 5
Introduction to Web Services
Creating a Distributed System with RMI
Remote method invocation (RMI)
Creating a Distributed System with Remote Procedure Calls and Web Services Ch.5 B.Ramamurthy 2/17/2019 B.Ramamurthy.
Distribution Infrastructures
WebServices Using JAX-RPC
Introduction to Web Services
Distributed System using Web Services
WEB SERVICES From Chapter 19, Distributed Systems
Distributed System using Web Services
Presentation transcript:

Java RMI, JAX-RPC and JWSDP B. Ramamurthy

Inside RMI http://java.sun.com/j2se/1.5.0/docs/index.html Basic RMI classes: /usr/java1.1/src/java/rmi java.rmi.registry.* java.rmi.Naming class (static/class methods) java.rmi.Remote interface (marker interface) java.rmi.server.* Default RMI port 1099 Both lookup from local and remote are acceptable.

Implementation of RMI (5.2.5)

The role of proxy and skeleton in remote method invocation server client remote skeleton object B object A proxy for B Request & dispatcher for B’s class Reply servant Communication Communication Remote reference Remote module reference module module module Object A invokes a remote object in Object B for which it holds a remote object reference. “System Model”

RMI Internals: Communication Module Carries out request-reply protocol; On the client side {message type, message id, remote reference to object} are gathered and sent out. At most once invocation semantics; On the server side, it gets local reference for remote reference from remote reference module, invokes a dispatcher with this reference. See UnicastRemote (implements UnicastRemote)

RMi Internals: Remote Reference module Responsible for translating between local and remote object references and for creating remote object references. A remote object table has a mapping between local and remote references. A table at server (entry for object ref for B) and a table at client (entry for object ref for proxy B).

RMI Internals: Remote References Action of remote reference module: See RemoteRef.java interface When a remote object is to be passed as argument or result for the first time, the remote ref is asked to create a remote ref object which is added to the table. When a remote object reference arrives in a request or reply, the remote ref module is asked for corresponding local object ref, which may either a proxy or remote object. If it is not in the table RMI runtime creates it and asks remote ref module to add it to the table.

RMI Internals: RMI software Layer of software between application level objects and communication and remote reference modules: “Middleware” Proxy: provides remote access transparency. One proxy for every remote object in the client. Dispatcher: A server has one dispatcher and skeleton for each class representing a remote object. It receives request message from comm. Module It used MessageId to select appropriate method in skeleton. Proxy and dispatcher use same MessageId. Skeleton: A class of remote object has a skeleton that implements of the remote interface. All the access dependencies are hidden in this class. A remote object has a servant that directly implements the methods. Java 5 creates this dynamically. Proxies, dispatcher and skeleton are automatically generated by interface compiler. Binder: binds textual names to remote object references. RMiRegistry is a binder; Naming class; see fig.5.13 Server Threads: one thread per invocation Distributed garbage collection: See Andrew Birell’s paper [1995].

RMI Internals: Distributed Garbage Collection Based on reference counts. Local garbage collectors and a distributed support. Each server holds the list of processes that hold remote object references: for example, B.Holders When a client C first receives a remote reference to a particular remote object, say B, it makes a addRef(B) invocation to server of that remote object and then creates proxy; server adds C to B.Holders. When client C’s garbage collector finds that proxy is no longer reachable (ref count), it makes a removeRef(B) invocation to server and then deletes proxy; the server removes C from B.Holders. When B.Holders is empty, server’s local garbage collector will reclaim the space occupied B unless there are any local holders. These extra calls for updates occur during proxy creation and deletion and do not affect normal opertion. Tolerates communication failures: addRef() and removeRef() are idempotent: effects of N > 0 identical requests is the same as for a single request. If addRef() fails with an exception, proxy is not created, removeRef() is transmitted; removeRef() failures are dealt with by “leases” (Jini kind).

RMI Internals: Use of Reflection What is reflection? See Reflection package Reflection enables Java code to discover information about the fields, methods and constructors of loaded classes, and To use reflected fields, methods, and constructors to operate on their underlying counterparts on objects, within security restrictions. http://java.sun.com/docs/books/tutorial/reflect/class/index.html Reflection feature allowed for dynamic creation of skeleton and proxy in Java 2 version onwards. Skeleton has been deprecated since JDk1.4.x Read more about reflection model of computing.

A Little bit of Reflection Method class, invoke method Invoke method requires two parameters: first the object to receive invocation, second an array of Object parameters. Invoke executes the method on the object and returns result as Object. Method m; Object result = m.invoke(String, Args);

Using Reflection in RMI Proxy has to marshal info. about a method and its arguments into a request message. For a method it marshals an object of class Method into the request. It then adds an array of objects for the method’s arguments. The dispatcher unmarshals the Method object and its arguments from request message. The remote object reference is obtained from remote ref. table. The dispatcher then calls the “invoke” method on the object reference and array of arguments values. After the method execution the dispatcher marshals the result or any exceptions into the reply message.

Putting it all together Server side: Write a an interface and implement it. Implements Remote, Inside code publishes the object by (exporting to runtime) and by registering it. Client Side: Code: look up server object name from the registry {host,port}; Invoke opertions.

Lifecycle of a remote call First time, an operation is invoked, remote object reference is obtained from remote registry, addRef() is sent to remote server, an entry made in the local ref table and proxy is created. Proxy has message ids while the client’s ref table has remote object reference. Remote ref, method id and arguments are marshaled into a message and sent across via the communication module.

Lifecycle of a remote call (contd.) On the server side RMI runtime maps the remote reference to a local object. Unmarshalls the operation and parameters and uses reflection to “invoke” the method on the object reference. The result is marshaled back into the response and sent back to the caller. “Skeleton” that includes the “dispatch” is subsumed into the RMI runtime in the latest versions of Java.

Critique of RMI (Sun Java’s) /RPC (Microsoft’s) Performs very well for single-platform limited distributed system. Platform dependent Tightly coupled Inherently synchronous (No chance for eventing or notification) Object-oriented: Objects not deployable units Non-standard Not scalable, location dependent, no global registry/discovery Object reference passed as parameter and/or returned as result.

Web Services Web Services is a technology that allows for applications to communicate with each other in a standard format. A Web Service exposes an interface that can be accessed through messaging. Deployable unit. A Web service uses protocol to describe an operation and the data exchange with another web service. Ex: SOAP Platform independent, say, through WSDL. Publishable, discoverable, searchable, queryable Scalability issues: A group of web services collaborating accomplish the tasks of a large-scale application. The architecture of such an application is called Service-Oriented Architecture (SOA).

A Little bit of History: XML to SOAP Simple xml can facilitate sending message to receive information. The message could be operations to be performed on objects. Standardize the tags for object access. Simple Object Access Protocol (SOAP).

SOAP Request (Not WS request) <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"> <soap:Body> <getProductDetails xmlns="http://warehouse.example.com/ws"> <productId>827635</productId> </getProductDetails> </soap:Body> </soap:Envelope>

SOAP Reply <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"> <soap:Body> <getProductDetailsResponse xmlns="http://warehouse.example.com/ws"> <getProductDetailsResult> <productName>Toptimate 3-Piece Set</productName> <productId>827635</productId> <description>3-Piece luggage set. Black Polyester.</description> <price>96.50</price> <inStock>true</inStock> </getProductDetailsResult> </getProductDetailsResponse> </soap:Body> </soap:Envelope>

SOAPWeb Services (WS) Take a look at 1. http://www.w3.org/DesignIssues/WebServices.html 2. O’Reilly book on Web Services: Kim Topley’s Webservices in a Nutshell: http://www.oreilly.com/catalog/javawsian/index.html This link has a sample chapter (SAAJ) and zip of all examples in the book.

Web Services (Colouris) A web service provides a service interface enabling clients to interact with servers in a more general way than web browsers do. Clients access operations in the interface usually by XML messages over http. However other architectural models such as REST and CORBA could access WS. WSDL provides additional details than for standard operation: for encoding, security, communication and location.

Web services infrastructure and components Security Service descriptions (in WSDL) Applications Directory service Web Services XML Choreography SOAP URIs (URLs or URNs) HTTP, SMTP or other transport

SOAP message in an envelope header header element header element body body element body element

Example of a simple request without headers env:envelope xmlns:env =namespace URI for SOAP envelopes env:body m:exchange xmlns:m = namespace URI of the service description m:arg1 m:arg2 Hello World In this figure and the next, each XML element is represented by a shaded box with its name in italic followed by any attributes and its content

Example of a reply corresponding to the request in env:envelope xmlns:env = namespace URI for SOAP envelope env:body m:exchangeResponse xmlns:m = namespace URI for the service description m:res1 m:res2 World Hello

Use of HTTP POST Request in SOAP client-server communication POST /examples/stringer endpoint address HTTP header Host: www.cdk4.net Content-Type: application/soap+xml Action: http://www.cdk4.net/examples/stringer#exchange action <env:envelope xmlns:env= namespace URI for SOAP envelope > <env:header> </env:header> Soap message <env:body> </env:body> </env:Envelope>

Services, ports and bindings Service endpoint interface (SEI) or service endpoint that defines one or more operations that the web service offers. Access to an endpoint is provided by binding it to a protocol stack through a port. A port has an address that the client can use to communicate with the service and invoke its operations. An endpoint can be bound to different ports each offering a different suite of protocols for interaction.

Endpoint, Port and binding Web service endpoint Port1 port2 port3 Web services Client SOAP1.1 Over http SOAP 1.1 over https Other. Ex: ebXML over SMTP https 1.1 transport soap1.1 messages

WS Interoperability Infrastructure Service Description WSDL XML Messaging SOAP Network HTTP

JAX-RPC JAX-RPC (The Java API for XML-based RPC) is designed to provide a simple way for developers to create Web services server and Web services client. Based on remote procedure calls; so the programming model is familiar to Java developers who have used RMI or CORBA. Major difference between RMI and JAX-RPC is that messages exchanged are encoded in XML based protocol and can be carried over a variety of transport protocols such as HTTP, SMTP etc. You can use JAX-RPC without having to be an expert in XML, SOAP, or HTTP.

The JAX-RPC Programming Model Services, ports and bindings JAX-RPC web service servers and clients JAX-RPC service creation JAX-RPC client and server programming environments Stubs and ties Client invocation modes Static and dynamic stubs and invocation

JAX-RPC Runtime Server Impl. Client Appl. Ties Stub JAX-RPC JAX-RPC SOAP over HTTP Read the semantics of exchanges in your text book pages 798, 799: You will observe very similar semantics for stub and ties as proxy and skeleton in RMI. Exception: no object ref is passed but request, response go through XML format and are extracted and dispatched.

Stubs and Ties Client Side: Stub object has the same methods as the service implementation class. Client application is linked with the stub. When it invokes a method stub delegates the call to the JAX-RPC runtime so that appropriate SOAP message can be sent to the server. On completion the result return back in the reverse path as above. Server side: Message received must be converted into a method call on actual service implementation. This functionality is provided by another piece of glue called tie. Tie extracts method name and parameter from SOAP message. Tie also converts the result of the method call back into a response message to be returned to client JAX-RPC runtime. JAX-RPC comes with tools to generate these.

Web Service Clients and Servers JAX-RPC maps a web service operation to a java method call. service endpoint to a Java Interface. Thus one way to begin implementation of a web service in JAX-RPC is to define a Java interface with a method for each operation of the service along with a class that implements the interface. Of course, following the rules of remote invocation etc. Now visualize client/server invocation in the same address space and lets compare it with remote invocation.

Local Date Service //server public class DataService { public Data getDate() { return new Date();} //client Public class Appln { public static void main (..) { DateService instance = new DateService(); Date date = instance.getDate(); System.out.println (“ The date is” + date); } In the case of the remote call a layer of software is used to convey the method call from client to server. This layer of software is provided by JAX-RPC runtime.

Java web service interface ShapeList import java.rmi.*; public interface ShapeList extends Remote { int newShape(GraphicalObject g) throws RemoteException; int numberOfShapes()throws RemoteException; int getVersion() throws RemoteException; int getGOVersion(int i)throws RemoteException; GraphicalObject getAllState(int i) throws RemoteException; }

Java implementation of the ShapeList server import java.util.Vector; public class ShapeListImpl implements ShapeList { private Vector theList = new Vector(); private int version = 0; private Vector theVersions = new Vector(); public int newShape(GraphicalObject g) throws RemoteException{ version++; theList.addElement(g); theVersions.addElement(new Integer(version)); return theList.size(); } public int numberOfShapes(){} public int getVersion() {} public int getGOVersion(int i){ } public GraphicalObject getAllState(int i) {}

Java implementation of the ShapeList client package staticstub; import javax.xml.rpc.Stub; public class ShapeListClient { public static void main(String[] args) { /* pass URL of service */ try { Stub proxy = createProxy(); proxy._setProperty (javax.xml.rpc.Stub.ENDPOINT_ADDRESS_PROPERTY, args[0]); ShapeList aShapeList = (ShapeList)proxy; GraphicalObject g = aShapeList.getAllState(0); } catch (Exception ex) { ex.printStackTrace(); } } private static Stub createProxy() { return (Stub) (new MyShapeListService_Impl().getShapeListPort());

SEI Invocation Code Service End Point (SEI) invocation code: Stub stub = (Stub)(new MyHelloService_Impl().getHelloIFPort()); stub._setProperty(javax.xml.rpc.Stub.ENDPOINT_ADDRESS_PROPERTY, "http://localhost:8080/hello-jaxrpc/hello"); HelloIF hello = (HelloIF)stub; resp = hello.sayHello(request.getParameter("username"));

SOAP binding and service definitions name = " ShapeListBinding " name = " MyShapeListService " type = " tns:ShapeList " soap:binding transport = URI endpoint for schemas for soap/http style= rpc name = " ShapeListPort " " " binding = " tns:ShapeListBinding " operation name= " newShape " soap:address input location = service URI soap:body encoding, namespace output soap:body encoding, namespace the service URI is: soap:operation soapAction “http://localhost:8080/ShapeList-jaxrpc/ShapeList”

The main elements in a WSDL description definitions interface/ (porttype) bindings services types message target namespace request-reply style how where document style abstract concrete

Message exchange patterns for WSDL operations Name Messages sent by Client Server Delivery Fault message Request Reply may replace Reply In-Out Request no fault message In-Only Request guaranteed Robust In-Only may be sent Reply Request Out-In may replace Reply Out-Only Request no fault message Robust Out-Only Request guaranteed may send fault