Actually, you need to set the security manager at both ends. The tricky
part to all of this, which the RMI docs I've seen don't explain, is that
you have to have a .java.policy file in your home directory granting
permissions to the "untrusted" codebase (any code that's not in the
bootstrap classpath is "untrusted"). Otherwise, you get all manner of
access exceptions.

I had tons of problems with RMI until I had a chat with Simon Roberts
about it - he explained to me about the policy file business.

--Jeff


Nick Lawson wrote:
> 
> Hi,
> 
> Two points:
> 
> (1) You shouldn't exit main() ! One way is just to sleep
> forever.
> Another way is to wait for stdin after the rebind(),
> something
> like:
> 
>         LineNumberReader in = new LineNumberReader( new
> InputStreamReader( System.in
> ));
>         while( true ) {
>             try {
>                 StreamTokenizer tokens = new
> StreamTokenizer( new StringReader(
> in.readLine()));
>                 int tt = tokens.nextToken();
>                 switch( tt ) {
>                     case tokens.TT_EOF:
>                         System.err.println( "TestRMI
> running" );
>                         break;
>                     case tokens.TT_WORD:
>                         // parse the tokens and do
> something, like shutdown
>                         ......
>                         break;
>                     default:
>                         System.err.println( "??" );
>                 }
>             }
>             catch( IOException e ) {
>             }
>         }
> 
> (2) Dont set the security manager - you'll probably get all
> sorts of access
> exceptions.
> RMISecurityManager lives at the client end (if I remember
> correctly).
> I think there must be an example in the rmi docs which shows
> this
> being used as you have, because I did the same thing once.
> You
> can get away with it in 1.1.x, but not 1.2, where security
> is changed.
> 
> Nick.
> 
> Pratip Kar wrote:
> 
> > Hi,
> >
> > Thanks for your reply. This is the code snippet for my server.
> >
> > public class TestRMI extends UnicastRemoteObject implements ITestRMI
> > {
> >         public static void main(String args[])
> >         {
> >                 System.setSecurityManager(new RMISecurityManager() );
> >                 try
> >                 {
> >                         TestRMI test = new TestRMI();
> >                         Naming.rebind( "TestRMI", test );
> >                         System.out.println( "TestRMI object bound to registry" );
> >                 }
> >                 catch(Exception e)
> >                 {
> >                         e.printStackTrace();
> >                 }
> >         }
> > }
> >
> > With that, when I run the server, I get the println() on the screen, and after
> > that the server exits.
> >
> >     % java -green -Djava.security.policy=./policy TestRMI
> >     TestRMI object bound to registry
> >     %
> >
> > Pratip
> >
> > Nick Lawson wrote:
> >
> > > Hi,
> > >
> > > Would it help to add some println()s to your rmi server
> > > so you could see where it falls out ? Or does the jvm
> > > exit from within the rebind() call ?
> > >
> > > Nick
> > >
> > > Pratip Kar wrote:
> > >
> > > > Hi,
> > > >
> > > > I am running a simple RMI test application. But after doing the
> > > > "Naming.rebind(....)" the server simply comes out. There is no exception
> > > > or anything. But instead of waiting for the Client connection, it exits
> > > > normally after binding to rmiregistry.
> > > >
> > > > My system has RH6.0 with glibc2.1. I am not able to run the native
> > > > thread executables, so I was trying with the green thread ones. Can that
> > > > be a problem ?
> > > >
> > > > Pratip
> > > >
> 
> ----------------------------------------------------------------------
> To UNSUBSCRIBE, email to [EMAIL PROTECTED]
> with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]

-- 
Jeff Galyan
http://www.anamorphic.com
http://www.sun.com
jeffrey dot galyan at sun dot com
talisman at anamorphic dot com
Sun Certified Java(TM) Programmer
======================================================================
Linus Torvalds on Microsoft and software development:
"... if it's a hobby for me and a job for you, why are you doing such a
shoddy job of it?"

The views expressed herein do not necessarily reflect those of my
employer.

Sun Microsystems, Inc., has no connection to my involvement with the
Mozilla Organization.


----------------------------------------------------------------------
To UNSUBSCRIBE, email to [EMAIL PROTECTED]
with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]

Reply via email to