The Artima Developer Community
Sponsored Link

Legacy Java Answers Forum
July 2000

Advertisement

Advertisement

This page contains an archived post to the Java Answers Forum made prior to February 25, 2002. If you wish to participate in discussions, please visit the new Artima Forums.

Message:

Running RMI

Posted by Robert on July 30, 2001 at 8:44 AM

Hi Rob,

If you want to just test the RMI code and see how it functions then you have to comment on the following inside public static void main() and do the usual stuff of compiling and creating stubs and skeletons.
// System.setSecurityManager(new RMISecurityManager());


This should help you in understanding the basics about RMI.
To run with the above said code you need to change the policy file. Run the policy tool in the bin directory to grant permissions to the files.

Have a nice time coding ..

robert.

> I've tried to compile and run the RMI sample code of "Thinking in Java" ebook. But I always got exceptions while running server,
> here is the exception traces, anybody can tell me, what's wrong with that.

> Thanks
> Robert

> java.security.AccessControlException: access denied (java.net.SocketPermission 127.0.0.1:1099 connect,resolve)
> at java.lang.Throwable.fillInStackTrace(Native Method)
> at java.lang.Throwable.(Throwable.java:94)
> at java.lang.Exception.(Exception.java:42)
> at java.lang.RuntimeException.(RuntimeException.java:47)
> at java.lang.SecurityException.(SecurityException.java:39)
> at java.security.AccessControlException.(AccessControlException.java:57)
> at java.security.AccessControlContext.checkPermission(Compiled Code)
> at java.security.AccessController.checkPermission(Compiled Code)
> at java.lang.SecurityManager.checkPermission(Compiled Code)
> at java.lang.SecurityManager.checkConnect(SecurityManager.java:1021)
> at java.net.Socket.(Socket.java:258)
> at java.net.Socket.(Socket.java:98)
> at sun.rmi.transport.proxy.RMIDirectSocketFactory.createSocket(RMIDirectSocketFactory.java:29)
> at sun.rmi.transport.proxy.RMIMasterSocketFactory.createSocket(Compiled Code)
> at sun.rmi.transport.tcp.TCPEndpoint.newSocket(TCPEndpoint.java:497)
> at sun.rmi.transport.tcp.TCPChannel.createConnection(TCPChannel.java:194)
> at sun.rmi.transport.tcp.TCPChannel.newConnection(Compiled Code)
> at sun.rmi.server.UnicastRef.newCall(UnicastRef.java:322)
> at sun.rmi.registry.RegistryImpl_Stub.rebind(Unknown Source)
> at java.rmi.Naming.rebind(Naming.java:165)
> at PerfectTime.main(PerfectTime.java:19)

> The server code is:
> public class PerfectTime extends UnicastRemoteObject implements PerfectTimeI{
> public long getPerfectTime() throws RemoteException{
> return System.currentTimeMillis();
> }
> public PerfectTime() throws RemoteException{
> super();
> }

> public static void main(String[] args){
> System.setSecurityManager(new RMISecurityManager());
> try{
> PerfectTime pt = new PerfectTime();
> Naming.rebind("PerfectTime", pt);
> System.out.println("Object registered!");
> }catch(Exception e){
> e.printStackTrace();
> }
> }
> }






Replies:

Sponsored Links



Google
  Web Artima.com   
Copyright © 1996-2009 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use - Advertise with Us