Solved

Using RMI - Urgent

Posted on 2002-05-30
4
258 Views
Last Modified: 2013-12-29
Just been arse-raped by a lecturer, and now have two assignments due on monday where previously only one of them was.

One of these assignments involves a partial (yet functional) re-write of a program we write using sockets, into RMI.

Basically, I'm after every bit of info on getting an RMI program to work that you can possibly throw at me. I have no shortage of question points and will happily give away a lot of them for rapid responses to this.

I am just about to go finish coding my sockets implementation. After that I'm going to bed. Ideally, I'd like to get up in the morning with enough information sitting in this thread that I can sit down tomorrow and code the RMI up, without wasting half the day figuring out how to make it work.

Main points of interest: security. I know I need a txt file of some sort with the security policy. Security isn't a big deal, but I do need a policy of some sort for it to work at all. How do I go about setting up this? Basically I just want to make ports 5100 to 5105 open and accessible to all and sundry (this will all be running behind a phat uni firewall, and for no longer than 5 minutes at a time, so there's little risk). I doubt I'll need more than one open, but having 6 there gives me some maneuverability without needing to be editing it later. How do I set this file up? How do I make the RMI program recognise it as a security policy and adhere to it? RMI wasn't covered in much detail in the lectures. The sample assignment code doesn't contain a policy file (and thus doesn't work), and at the time we covered it (oh so briefly) in classes, there were other assignments to be thinking about.

My other main point of interest: something about stub files. What are these? Apparently I need to use rmic to compile an RMI program (or just to create the stub files? I know not). Assuming I have fully functionaly, syntactically, and logically correct code, how do I go about compiling it so it will run, connect, and operate? I am writing both client and server software (very simplistic implementations thereof though; 5 hours coding tops once I know how to make it compile and run properly).

Any other information/tips/anecdotes/whatever you can provide to someone who has a basic understanding of the principles of RMI coding but no actual experience doing it would be much appreciated and well rewarded.

300 points for now, to attract attention. Expect more.
0
Comment
Question by:Subhuman
  • 2
4 Comments
 
LVL 16

Expert Comment

by:heyhey_
ID: 7044775
tutorial on how to build the simplest HelloWorld RMI app

http://java.sun.com/products/jdk/1.2/docs/guide/rmi/getstart.doc.html
0
 
LVL 35

Accepted Solution

by:
girionis earned 300 total points
ID: 7045232
 Basically RMI is Java's implementation for remote procedure calls for Java-to-Java distributed object communication. A Java object can register itself as being remotely accessible, bind it to an RMI registry and a client can look-up for this object, receive a reference to this object and access it as if it were local.

  Since the client and the server object can reside on different machines a mechanism for communication between client and server is needed. The first step to this is to define the remote interface (that describes the methods with which the client can use to interact with the server object through RMI). Once the remote interface is defined you simply write the implementation class and use the rmiregistry (it is included with the J2SDK) to register the object.

  Both server and client classes must first be compiled with the javac. After this the remote implementation class must be compiled using the rmic (it comes with the J2SDK as well) to produce the stub class. The stub class allows the client to invoke the server object's remote methods. The stub receives each remote call and passes it to the Java RMI systems that performs the networking that allows the client to connect to the server and interact with the remote server object.

  To compile the server class you simply need to do: rmic -v1.2 <classfilename>

  The -v1.2 indicates that the classes will be used by the J2SE vm and not by any earlier. The reason we need it, is because in the pro-java 2 systems two classes were needed in order for the RMI to run; the stub and the skeleton. Once you are done start the rmiregistry by simply typing; rmiregistry. That's more or less it. You have the server up and running.

  With regards to security issues you might want to restrict the acitons performed by remotely loaded classes. This can be done by installing a security manager because by default an RMI programme does not have a security manager (and therefore there are no restrictions placed on rempotely loaded loaded objects). The java.rmi provides a default manager security implementation that you can install using:

if(System.getSecurityManager() == null)
{
     System.setSecurityManager(new RMISecurityManager());
}

 If you would like to use your own security manager implementation you will need to specify (in Java 2) a security policy file at run-time. A sample policy file that grants full access permissions to everyone will look like:

grant
{
  permission java.security.AllPermission;
}

  and you can use it by defining a value for the java.security.policy property:

java -Djava.security.policy=policyfilename

  For more information/tutorials on rmi take a look here:

http://www.execpc.com/~gopalan/java/java_tutorial.html
http://www.ccs.neu.edu/home/kenb/com3337/rmi_tut.html
http://developer.java.sun.com/developer/onlineTraining/rmi/

  and on rmi security/permissions

http://java.sun.com/docs/books/tutorial/rmi/running.html
http://patriot.net/~tvalesky/easyrmi.html
http://gethelp.devx.com/techtips/java_pro/10MinuteSolutions/10min0500.asp

  Hope it helps.
0
 
LVL 1

Author Comment

by:Subhuman
ID: 7046577
Thanks very much. I was expecting more responses but yours sufficed, so it's all good.
0
 
LVL 35

Expert Comment

by:girionis
ID: 7046595
 Thank you for the points. I am glad I helped :-)
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

For customizing the look of your lightweight component and making it look lucid like it was made of glass. Or: how to make your component more Apple-ish ;) This tip assumes your component to be of rectangular shape and completely opaque. (COD…
INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…

759 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now