1 Lecture 12 George Koutsogiannakis/ Summer 2011 CS441 CURRENT TOPICS IN PROGRAMMING LANGUAGES.

Slides:



Advertisements
Similar presentations
1 Chapter 9 Network Programming. 2 Overview Java has rich class libraries to support network programming at various levels. There are standard classes.
Advertisements

Remote Method Invocation CS587x Lecture Department of Computer Science Iowa State University.
15-May-15 RMI Remote Method Invocation. 2 “The network is the computer” Consider the following program organization: If the network is the computer, we.
Advanced Programming Rabie A. Ramadan Lecture 4. A Simple Use of Java Remote Method Invocation (RMI) 2.
Java Remote Method Invocation (RMI) In Java we implement object systems: O1O2 O3 thread 1thread 2 execution scheme JVM 1JVM 2 distribution scheme.
Java Remote Object Invocation (RMI) Overview of RMI Java RMI allowed programmer to execute remote function class using the same semantics as local functions.
Remote Method Invocation
J2ME RMI 1 Java 2 Platform, Micro Edition Implementation of J2ME RMI Application Farooq Sheikh.
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.
DISTRIBUTED FILE SYSTEM USING RMI
Java RMI. What is RMI? RMI is an RPC system for an object based language. Objects provide a natural granularity for the binding of functions. –RMI allows.
1 HANDOUT 14 Remote Method Invocation (RMI) BY GEORGE KOUTSOGIANNAKIS THIS DOCUMENT CAN NOT BE REPRODUCED OR DISTRIBUTED WITHOUT TH E WRITTEN PERMISSION.
Sockets  Defined as an “endpoint for communication.”  Concatenation of IP address + port.  Used for server-client communication.  Server waits for.
EEC-681/781 Distributed Computing Systems Lecture 5 Wenbing Zhao Department of Electrical and Computer Engineering Cleveland State University
Introduction to Remote Method Invocation (RMI)
Java Remote Object Invocation (RMI) Overview of RMI Java RMI allowed programmer to execute remote function class using the same semantics as local functions.
How Does Remote Method Invocation Work? –Systems that use RMI for communication typically are divided into two categories: clients and servers. A server.
1 Lecture 13 George Koutsogiannakis/Summer 2011 CS441 CURRENT TOPICS IN PROGRAMMING LANGUAGES.
Java RMI RMI = Remote Method Invocation. Allows Java programs to invoke methods of remote objects. Only between Java programs. Several versions (JDK-1.1,
1 Java Programming II Java Network II (Distributed Objects in Java)
CS 584 Lecture 18 l Assignment » Glenda assignment extended to the Java RMI Deadline » No Java RMI Assignment l Test » Friday, Saturday, Monday.
15 - RMI. Java RMI Architecture Example Deployment RMI is a part of J2SE (standard edition), but is used by J2EE) A J2EE server is not nessesary for using.
LAB 1CSIS04021 Briefing on Assignment One & RMI Programming February 13, 2007.
Java RMI: Remote Method Invocation January 2000 Nancy McCracken Syracuse University.
1 Java RMI G53ACC Chris Greenhalgh. 2 Contents l Java RMI overview l A Java RMI example –Overview –Walk-through l Implementation notes –Argument passing.
Spring/2002 Distributed Software Engineering C:\unocourses\4350\slides\DefiningThreads 1 RMI.
RMI RMI is the java API that facilitate distributed computing by allowing remote method calls. A remote method call represents a method invocation between.
RMI-IIOP.  RMI-IIOP combines RMI-style ease of use with CORBA cross-language interoperability  Java™ Remote Method Invocation (RMI) provides a simple.
Silberschatz, Galvin, and Gagne  1999 Applied Operating System Concepts Chapter 15: Distributed Communication Sockets Remote Procedure Calls (RPCs) Remote.
Java Remote Method Invocation RMI. Idea If objects communicate with each other on one JVM why not do the same on several JVM’s? If objects communicate.
1 Lecture 11 George Koutsogiannakis / Summer 2011 CS441 CURRENT TOPICS IN PROGRAMMING LANGUAGES.
RMI Continued IS Outline  Review of RMI  Programming example.
RMI remote method invocation. Traditional network programming The client program sends data to the server in some intermediary format and the server has.
RMI Remote Method Invocation Distributed Object-based System and RPC Together 2-Jun-16.
Presentation: RMI Continued 2 Using The Registry & Callbacks.
Java Remote Object Invocation (RMI) Overview of RMI Java RMI allowed programmer to execute remote function class using the same semantics as local functions.
Example: RMI Program How to write it.
 Remote Method Invocation  A true distributed computing application interface for Java, written to provide easy access to objects existing on remote.
Fall 2007cs4251 Distributed Computing Umar Kalim Dept. of Communication Systems Engineering 17/10/2007.
Li Tak Sing COMPS311F. RMI callbacks In previous example, only the client can initiate a communication with the server. The server can only response to.
Java Remote Method Invocation (RMI) Overview of RMI Java RMI allowed programmer to execute remote function class using the same semantics as local functions.
1 Java Remote Method Invocation java.rmi.* java.rmi.registry.* java.rmi.server.*
 Java RMI Distributed Systems IT332. Outline  Introduction to RMI  RMI Architecture  RMI Programming and a Sample Example:  Server-Side RMI programming.
RMI Example. Compilation: /home2/fccheng/temp/RMI2> javac MyObject.java /home2/fccheng/temp/RMI2> javac RemoteServer.java /home2/fccheng/temp/RMI2> javac.
Remote Method Invocation A Client Server Approach.
UMBC Distributed Computing with Objects RMI/Corba CMSC 432 Shon Vick.
Remote Method Invocation RMI architecture stubs and skeletons for remote services RMI server and client in Java Creating an RMI Application step-by- step.
Java RMI. RMI Any object whose methods can be invoked from another Java VM is called a remote object.
Khoa CNTT 1/37 PHẠM VĂN TÍNH   Java RMI (Remote Method Invocation)
1 Lecture 15 Remote Method Invocation Instructors: Fu-Chiung Cheng ( 鄭福炯 ) Associate Professor Computer Science & Engineering Tatung Institute of Technology.
CSC 480 Software Engineering Lab 6 – RMI Nov 8, 2002.
Netprog Java RMI1 Remote Method Invocation.
Using RMI The Example of A Remote Calculator 1. Parts of A Working RMI System A working RMI system is composed of several parts. –Interface definitions.
RMI1 Remote Method Invocation Adapted from “Core Java 2” by Cay Horstmann.
Principles of Software Development
Java Remote Method Invocation (RMI)
Remote Method Invocation
What is RMI? Remote Method Invocation
Remote Method Invocation
Advanced Remote Method Invocations
Java RMI (more) CS-328 Internet Programming.
Knowledge Byte In this section, you will learn about:
Network and Distributed Programming in Java
Creating a Distributed System with RMI
Creating a Distributed System with RMI
Creating a Distributed System with RMI
CS 584 Lecture 18 Assignment Glenda assignment extended to the Java RMI Deadline No Java RMI Assignment Test Friday, Saturday, Monday.
Java Remote Method Invocation
Creating a Distributed System with RMI
Java Chapter 5 (Estifanos Tilahun Mihret--Tech with Estif)
Presentation transcript:

1 Lecture 12 George Koutsogiannakis/ Summer 2011 CS441 CURRENT TOPICS IN PROGRAMMING LANGUAGES

Topics Servlets used as RMI Client. –RMI Security needed for Servlet to RMI server Communications. 2

Servlet as RMI client The Servlet will implement the doGet or doPost method as normally. Within the method (doGet or doPost): –You need to catch Exceprion (create try/catch) –Do a lookup on the registry: ReverseInterface r= (ReverseInterface) Naming.lookup ("//localhost:1099/Reverse"); 3

Servlet as RMI client –Where we assume that: The server has registered a remote object for its instance called “Reverse”. The server’s Remote Interface that defines its service is ReverseInterface. The registry is at port –Then go ahead and do the remote invocation and capture the output (still within try block): String str=r.reverseString(qr); 4

Servlet as RMI client –Where r is the reference received from the registry –The argument in the remote method is the data type that the method accepts (i.e qr is of String data type in the example). –The returned value from the server is captured by variable str (assuming that the remote method returns a String data type in this example). 5

Servlet as RMI client –Process the captured data by the servlet using the proper stream and the response object: PrintWriter out=response.getWriter(); out.println(str); out.close(); 6

RMI server. Create RMI server as it is done normally. import java.rmi.Remote; import java.rmi.RemoteException; public interface ReverseInterface extends Remote { String reverseString(String originalstring) throws RemoteException; } IN THE SERVER ReserveInterfaceImpl: public static void main(String[] args){ String name="//localhost/Reverse"; try { ReverseInterfaceImpl r= new ReverseInterfaceImpl(); Naming.rebind(name, r); etc…………… 7

RMI server. IMPLEMENT THE REMOTE METHOD (SERVICE) public String reverseString(String originalstring) throws RemoteException { int length=originalstring.length(); StringBuffer temp=new StringBuffer(length); for (int i=length; i>0; i-- ) { temp.append(originalstring.substring(i-1,i)); } return temp.toString(); } 8

SET UP OF THE APPLICATION C reate the applications web site outside of Tomcat (NEVER DEVELOP THE APPLICATION INSIDE TOMCAT). Do NOT Include the required files for the RMI server in the application’s deployment. Place all RMI client related files in the same directory as the servlet. Deploy using a WAR file approach. –Remember that with the servlet you will need the stub from the server and a copy of the interface file also. 9

SET UP OF THE APPLICATION You will need the certificate applied like you did in the assignment 1 with respect to a signed applet –We assume that the servlet uses an applet as a client!! You may need a policy file like (optional): grant { permission java.security.AllPermission; }; 10

SET UP OF THE APPLICATION To allow communications between the Web Server (the servlet acting as RMI client) and the RMI Server: –Modify the java.policy file in the System’s security directory (jdk installation) as follows: // allows anyone to listen on un-privileged ports permission java.net.SocketPermission "localhost: ", "connect, accept, listen, resolve"; 11

Servlet as RMI Over IIOP Client. In either the doGet or doPost method: –We will need a Hashtable structure to place the call to registry as a name/value attributes ReverseInterface r; Hashtable env=new Hashtable(); env.put("java.naming.factory.initial", "com.sun.jndi.cosnaming.CNCtxFactory"); env.put("java.naming.provider.url", "iiop://localhost:900"); We assume that the IIOP Naming Service is listening at port

Servlet as RMI Over IIOP Client –In try block contact the Naming Service (IIOP registry): Context initialNamingContext=new InitialContext(env); out.println("obtained InitialContext"); r=(ReverseInterface)PortableRemoteObject.narrow(initialNami ngContext.lookup("Reverse"), ReverseInterface.class); –Now do the remote invocation using the reference r received from the Naming Service String str=r. reverseString(qr); WHERE reverseString is the remote method defined in the Interface created by the Server. 13

Servlet as RMI Over IIOP Client –Process the data captured by using the proper stream with the response object. 14

RMI Over IIOP Server Need additional import statements: import java.rmi.*; import java.rmi.server.*; //add the lines below import javax.rmi.PortableRemoteObject; import javax.naming.*; import java.net.*; import javax.naming.Context; import javax.naming.InitialContext; import javax.naming.NamingException; 15

RMI Over IIOP Server –public class ReverseInterfaceImpl extends PortableRemoteObject implements ReverseInterface –Registration in try block in main method: ReverseInterfaceImpl r= new ReverseInterfaceImpl(); //add the follwoing lines Context initialNamingContext=new InitialContext(); System.out.println("Binding server to registry.."); initialNamingContext.rebind("Reverse", r); System.out.println("Object was registered"); –Implement the remote method. 16

SET UP OF THE APPLICATION Set up is similar to RMI description in previous files. Compiling should be as described in the RMI over IIOP presentation (lecture 11). 17

RMI SECURITY RMI has its own Security Manager. –Automatic downloading of stub files and interface file by the client is strictly cntrolled by security. Secured Class Loaded java.policy file java.security file Security Policy controlled by RMISecurityManager object 18

RMI SECURITY RMISecurityManager creates a sandbox similar to what the applets have to encounter. Default RMISecurityManager uses the default java.policy and java.security system files. We can create our own RMISecurityManager and remove some of the restrictions. We can also change for demonstration reasons some of the restrictions by modifying the java.policy and java.security files and let the default RMISecurityManager object operate. 19

Study Guide See examples posted on the course’ s web site –ServletRMI.zip and –ServletRMIoverIIOP.zip 20