Hello
everyone,
I have the following class (see code below) that I've been trying
to
run.
*********************************************************************
//
Code extracted from the Eckel Book, Copyright Eckel.
//
PerfectTime.java
// RMI server
import java.rmi.*;
import
java.rmi.server.*;
import java.rmi.registry.*;
import
java.net.*;
public class PerfectTime extends UnicastRemoteObject
implements PerfectTimeI
{
// Implementation of the
interface:
public long
getPerfectTime()
throws RemoteException
{
return System.currentTimeMillis();
}
// Must implement constructor
// to throw RemoteException:
public PerfectTime() throws RemoteException {
// super();
// Called automatically
}
// Registration for RMI serving.
Throw
// exceptions out to the console.
public static void
main(String[] args)
throws Exception {
System.setSecurityManager( new RMISecurityManager());
PerfectTime pt = new PerfectTime();
Naming.bind("//coper:2005/PerfectTime", pt); // Calling this, trowns an
exception!!
System.out.println("Ready to do time");
}
}
*********************************************************************
The
code compiles fine but when I run it, I get the following exception:
(see
below):
*********************************************************************
java.security.AccessControlException:
access denied
(java.net.SocketPermission coper resolve)
at
java.security.AccessControlContext.checkPermission(Unknown Source)
at
java.security.AccessController.checkPermission(Unknown Source)
at
java.lang.SecurityManager.checkPermission(Unknown Source)
at
java.lang.SecurityManager.checkConnect(Unknown Source)
at
java.net.InetAddress.getAllByName0(Unknown Source)
at
java.net.InetAddress.getAllByName0(Unknown Source)
at
java.net.InetAddress.getByName(Unknown Source)
at
java.net.Socket.<init>(Unknown Source)
at
sun.rmi.transport.proxy.RMIDirectSocketFactory.createSocket(Unknown
Source)
at
sun.rmi.transport.proxy.RMIMasterSocketFactory.createSocket(Unknown
Source)
at
sun.rmi.transport.tcp.TCPEndpoint.newSocket(Unknown Source)
at
sun.rmi.transport.tcp.TCPChannel.createConnection(Unknown Source)
at
sun.rmi.transport.tcp.TCPChannel.newConnection(Unknown Source)
at
sun.rmi.server.UnicastRef.newCall(Unknown Source)
at
sun.rmi.registry.RegistryImpl_Stub.bind(Unknown Source)
at
java.rmi.Naming.bind(Unknown Source)
at
PerfectTime.main(PerfectTime.java:29)
Exception in thread
"main"
*********************************************************************
Before
I run the PerfectTime class, I have the "rmiregistery" running on
port
2005.
It seems to me that line >>
Naming.bind("//coper:2005/PerfectTime", pt); is
causing the exception. I
don't know if this has something to do with the
"java security properties
file"
Any suggestions on what is causing the exception?
Any help
will be much appreciated.
Thanks in
advance.
Tony.