S
Sheetal Khemani
Hi All,
I am running a simple RMI example - to no avail.
The example I'm trying out is at:
http://java.sun.com/j2se/1.4.2/docs/guide/rmi/getstart.doc.html
I've tried to follow it to the T, but there's probably something I'm
missing ...
I've got server code, that defines a class that extends
UnicastRemoteObject and implements an interface (the interface extends
Remote). Then I bind an instance of this class to a 'name'.
I've got client code, that somehow gets a reference to the remote
instance using that same 'name'. And then it invokes a method on that
remote instance. It's magical.
This is so not working.
I can set up the server, and the object gets bound and everything.
When I try the client, it gives the following error:
/usr/local/apache2/htdocs/public_html #206 > appletviewer hello.html
HelloApplet exception: access denied (java.net.SocketPermission
192.168.0.103:1099 connect,resolve)
java.security.AccessControlException: access denied
(java.net.SocketPermission 192.168.0.103:1099 connect,resolve)
at java.security.AccessControlContext.checkPermission(AccessControlContext.java:269)
at java.security.AccessController.checkPermission(AccessController.java:401)
at java.lang.SecurityManager.checkPermission(SecurityManager.java:524)
at java.lang.SecurityManager.checkConnect(SecurityManager.java:1026)
at java.net.Socket.connect(Socket.java:446)
at java.net.Socket.connect(Socket.java:402)
at java.net.Socket.<init>(Socket.java:309)
at java.net.Socket.<init>(Socket.java:124)
at sun.rmi.transport.proxy.RMIDirectSocketFactory.createSocket(RMIDirectSocketFactory.java:22)
at sun.rmi.transport.proxy.RMIMasterSocketFactory.createSocket(RMIMasterSocketFactory.java:128)
at sun.rmi.transport.tcp.TCPEndpoint.newSocket(TCPEndpoint.java:562)
at sun.rmi.transport.tcp.TCPChannel.createConnection(TCPChannel.java:185)
at sun.rmi.transport.tcp.TCPChannel.newConnection(TCPChannel.java:171)
at sun.rmi.server.UnicastRef.newCall(UnicastRef.java:313)
at sun.rmi.registry.RegistryImpl_Stub.lookup(Unknown Source)
at java.rmi.Naming.lookup(Naming.java:84)
at examples.hello.HelloApplet.init(HelloApplet.java:59)
at sun.applet.AppletPanel.run(AppletPanel.java:353)
at java.lang.Thread.run(Thread.java:534)
This is strange because my policy file, says something like:
grant {
// Allow everything for now
permission java.security.AllPermission;
};
Any ideas ?
Thanks
Sheetal
PS: Here is all my code:
public interface Hello extends Remote {
String sayHello() throws RemoteException;
}
public class HelloImpl extends UnicastRemoteObject
implements Hello {
public HelloImpl() throws RemoteException {
super();
}
public String sayHello() {
return "Hello World!";
}
public static void main(String args[]) {
// Create and install a security manager
if (System.getSecurityManager() == null) {
System.setSecurityManager(new RMISecurityManager());
}
try {
HelloImpl obj = new HelloImpl();
// Bind this object instance to the name "HelloServer"
Naming.rebind("//192.168.0.103/HelloServer", obj);
System.out.println("HelloServer bound in registry");
} catch (Exception e) {
System.out.println("HelloImpl err: " + e.getMessage());
e.printStackTrace();
}
}
}
public class HelloApplet extends Applet {
String message = "init";
// "obj" is the identifier that we'll use to refer
// to the remote object that implements the "Hello"
// interface
Hello obj = null;
public void init() {
try {
repaint();
//obj = (Hello)Naming.lookup("//" +
getCodeBase().getHost() + "/HelloServer");
obj = (Hello)Naming.lookup("//192.168.0.103/HelloServer");
message = obj.sayHello();
repaint();
} catch (Exception e) {
System.out.println("HelloApplet exception: " +
e.getMessage());
e.printStackTrace();
}
}
public void paint(Graphics g) {
g.drawString(message, 25, 50);
}
}
I am running a simple RMI example - to no avail.
The example I'm trying out is at:
http://java.sun.com/j2se/1.4.2/docs/guide/rmi/getstart.doc.html
I've tried to follow it to the T, but there's probably something I'm
missing ...
I've got server code, that defines a class that extends
UnicastRemoteObject and implements an interface (the interface extends
Remote). Then I bind an instance of this class to a 'name'.
I've got client code, that somehow gets a reference to the remote
instance using that same 'name'. And then it invokes a method on that
remote instance. It's magical.
This is so not working.
I can set up the server, and the object gets bound and everything.
When I try the client, it gives the following error:
/usr/local/apache2/htdocs/public_html #206 > appletviewer hello.html
HelloApplet exception: access denied (java.net.SocketPermission
192.168.0.103:1099 connect,resolve)
java.security.AccessControlException: access denied
(java.net.SocketPermission 192.168.0.103:1099 connect,resolve)
at java.security.AccessControlContext.checkPermission(AccessControlContext.java:269)
at java.security.AccessController.checkPermission(AccessController.java:401)
at java.lang.SecurityManager.checkPermission(SecurityManager.java:524)
at java.lang.SecurityManager.checkConnect(SecurityManager.java:1026)
at java.net.Socket.connect(Socket.java:446)
at java.net.Socket.connect(Socket.java:402)
at java.net.Socket.<init>(Socket.java:309)
at java.net.Socket.<init>(Socket.java:124)
at sun.rmi.transport.proxy.RMIDirectSocketFactory.createSocket(RMIDirectSocketFactory.java:22)
at sun.rmi.transport.proxy.RMIMasterSocketFactory.createSocket(RMIMasterSocketFactory.java:128)
at sun.rmi.transport.tcp.TCPEndpoint.newSocket(TCPEndpoint.java:562)
at sun.rmi.transport.tcp.TCPChannel.createConnection(TCPChannel.java:185)
at sun.rmi.transport.tcp.TCPChannel.newConnection(TCPChannel.java:171)
at sun.rmi.server.UnicastRef.newCall(UnicastRef.java:313)
at sun.rmi.registry.RegistryImpl_Stub.lookup(Unknown Source)
at java.rmi.Naming.lookup(Naming.java:84)
at examples.hello.HelloApplet.init(HelloApplet.java:59)
at sun.applet.AppletPanel.run(AppletPanel.java:353)
at java.lang.Thread.run(Thread.java:534)
This is strange because my policy file, says something like:
grant {
// Allow everything for now
permission java.security.AllPermission;
};
Any ideas ?
Thanks
Sheetal
PS: Here is all my code:
public interface Hello extends Remote {
String sayHello() throws RemoteException;
}
public class HelloImpl extends UnicastRemoteObject
implements Hello {
public HelloImpl() throws RemoteException {
super();
}
public String sayHello() {
return "Hello World!";
}
public static void main(String args[]) {
// Create and install a security manager
if (System.getSecurityManager() == null) {
System.setSecurityManager(new RMISecurityManager());
}
try {
HelloImpl obj = new HelloImpl();
// Bind this object instance to the name "HelloServer"
Naming.rebind("//192.168.0.103/HelloServer", obj);
System.out.println("HelloServer bound in registry");
} catch (Exception e) {
System.out.println("HelloImpl err: " + e.getMessage());
e.printStackTrace();
}
}
}
public class HelloApplet extends Applet {
String message = "init";
// "obj" is the identifier that we'll use to refer
// to the remote object that implements the "Hello"
// interface
Hello obj = null;
public void init() {
try {
repaint();
//obj = (Hello)Naming.lookup("//" +
getCodeBase().getHost() + "/HelloServer");
obj = (Hello)Naming.lookup("//192.168.0.103/HelloServer");
message = obj.sayHello();
repaint();
} catch (Exception e) {
System.out.println("HelloApplet exception: " +
e.getMessage());
e.printStackTrace();
}
}
public void paint(Graphics g) {
g.drawString(message, 25, 50);
}
}