|
-
Java RMI Client AccessControlException
Hi I've had some problems trying to get RMI working and was wondering if anyone can help me? I've tried implementing the client/server code two different ways - one way using a Registry object to bind my remote object and one using the Naming.rebind()/Naming.lookup() methods (my current code, which I'll supply in a sec).
I noticed when I was using the Registry object to bind the DriverObject I was getting errors about stuff not being serializable when trying to run the client. Is it talking about the objects that the DriverObject uses?
I'm running all of this on a windows machine using the following commands (the code is located in the folder C:\pid):
set CLASSPATH=
start rmiregistry
javac *.java
rmic -Djava.security.policy=policy.all javapid.DriverObject
java Server
java -Djava.security.policy=policy.all -classpath /pid ClientObject
When running the ClientObject I get the following error:
exporter: an exception occurred: access denied (java.net.SocketPermission 127.0.0.1:1099 connect,resolve)
java.security.AccessControlException: access denied (java.net.SocketPermission 127.0.0.1:1099 connect,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.Socket.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at java.net.Socket.<init>(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.lookup(Unknown Source)
at java.rmi.Naming.lookup(Unknown Source)
at ClientObject.main(ClientObject.java:405)
I've taken some of the code out of the driver object (the getters/setters are pretty much the same) for this post.
RemoteEvent.java
Code:
package javapid;
import java.rmi.Remote;
import java.rmi.RemoteException;
public interface RemoteEvent extends Remote
{
public double getInput () throws RemoteException;
public double getOutput () throws RemoteException;
public double getKp () throws RemoteException;
public double getKi () throws RemoteException;
public double getKd () throws RemoteException;
public double getPlant () throws RemoteException;
public int getSgm () throws RemoteException;
public double getSgmiv () throws RemoteException;
public double getSgmav () throws RemoteException;
public double getSgni () throws RemoteException;
public void setKp (double Kp) throws RemoteException;
public void setKi (double Ki) throws RemoteException;
public void setKd (double Kd) throws RemoteException;
public void setPlant (double g) throws RemoteException;
public void setRate (double r) throws RemoteException;
public void setSgmiv (double mi) throws RemoteException;
public void setSgmav (double ma) throws RemoteException;
public void setSgni (double ni) throws RemoteException;
public void setSgm (int md) throws RemoteException;
public void resetSigGen () throws RemoteException;
}
DriverObject.java
Code:
package javapid;
import java.rmi.*;
import java.rmi.server.*;
import java.rmi.registry.*;
public class DriverObject extends UnicastRemoteObject implements AsyncEvent, RemoteEvent {
private int externalCount = 0;
private SignalObject SO;
private SystemObject SY;
private int period = 20;
public DriverObject() throws RemoteException {
System.out.println("Creating remote control object");
SO = new SignalObject(0.0,5.0,0.01,100,0,0.0);
SY = new SystemObject(SO);
this.Start();
}
public DriverObject(SignalObject Sig, SystemObject Sys) throws RemoteException {
System.out.println("Creating remote control object");
SO = Sig;
SY = Sys;
this.Start();
}
public double getInput() throws RemoteException {
return SO.getOutput();
}
public void setKp(double Kp) throws RemoteException {
SY.setKp(Kp);
}
public void Start() {
ClockedEventObject SOT = new ClockedEventObject(period, SO);
ClockedEventObject SOY = new ClockedEventObject(period, SY);
ClockedEventObject DOT = new ClockedEventObject(period, this);
while(true) {}
}
public void handleAsyncEvent() {
// this is used by a clock object I created which is used in the Start() method.
// it implements the method defined in the AsyncEvent interface.
externalCount++;
}
public static void main (String args[])
{
try
{
System.setSecurityManager(new RMISecurityManager());
DriverObject Do = new DriverObject ();
System.out.println ("Created remote object, now advertising it");
//Registry registry = LocateRegistry.getRegistry ("localhost", 1099);
//registry.rebind ("RemotePID", Do);
Naming.rebind("RemotePID", Do);
System.out.println ("Advertising completed");
}
catch (Exception e)
{
System.out.println ("exporter: an exception occurred: "+
e.getMessage ());
e.printStackTrace ();
System.exit (1);
}
}
}
ClientObject.java
Code:
import javapid.*;
import java.rmi.*;
import java.rmi.registry.*;
class ClientObject
{
// public void setRst(int i) {
// try
// {
// System.out.println ("Starting client");
//
// Registry registry = LocateRegistry.getRegistry ("localhost", 1099);
// Object O = registry.lookup("RemotePID");
// RemoteEvent Rev = (RemoteEvent) O;
//
// if (i > 0) Rev.resetSigGen();
// } catch (Exception e) {
// System.out.println ("exporter: an exception occurred: "+
// e.getMessage ());
// e.printStackTrace ();
// System.exit (1);
// }
// }
public static void main(String args[]) {
System.setSecurityManager(new RMISecurityManager());
try {
System.out.println("Security Manager loaded");
String url = "//localhost/RemotePID";
RemoteEvent Rev = (RemoteEvent) Naming.lookup(url);
System.out.println("Got remote object");
System.out.println("Output is:"+ Rev.getOutput());
} catch (Exception e) {
System.out.println ("exporter: an exception occurred: "+
e.getMessage ());
e.printStackTrace ();
System.exit (1);
}
}
}
Thanks .
Similar Threads
-
By Sam Learner in forum Java
Replies: 1
Last Post: 02-20-2001, 01:52 AM
-
Replies: 0
Last Post: 12-14-2000, 02:45 PM
-
Replies: 0
Last Post: 08-14-2000, 05:37 PM
-
By JJ in forum Enterprise
Replies: 1
Last Post: 07-06-2000, 04:50 AM
-
Replies: 3
Last Post: 06-03-2000, 06:49 PM
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks