aspose file tools*
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes RMI Example Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "RMI Example" Watch "RMI Example" New topic
Author

RMI Example

JinXi Li
Greenhorn

Joined: Mar 12, 2002
Posts: 7
For using rmi,I write a examples for test.But when I run server side program,there is error.Like:
HelloImpl err:access denied (java.net.SocketPermission 127.0.0.1:1099 connect,re
solve)
java.security.AccessControlException: access denied (java.net.SocketPermission 1
27.0.0.1:1099 connect,resolve)
at java.security.AccessControlContext.checkPermission(AccessControlConte
xt.java:272)
at java.security.AccessController.checkPermission(AccessController.java:
399)
at java.lang.SecurityManager.checkPermission(SecurityManager.java:545)
at java.lang.SecurityManager.checkConnect(SecurityManager.java:1044)
at java.net.Socket.<init>(Socket.java:262)
at java.net.Socket.<init>(Socket.java:100)
at sun.rmi.transport.proxy.RMIDirectSocketFactory.createSocket(RMIDirect
SocketFactory.java:25)
at sun.rmi.transport.proxy.RMIMasterSocketFactory.createSocket(RMIMaster
SocketFactory.java:120)
at sun.rmi.transport.tcp.TCPEndpoint.newSocket(TCPEndpoint.java:499)
at sun.rmi.transport.tcp.TCPChannel.createConnection(TCPChannel.java:190
)
at sun.rmi.transport.tcp.TCPChannel.newConnection(TCPChannel.java:174)
at sun.rmi.server.UnicastRef.newCall(UnicastRef.java:318)
at sun.rmi.registry.RegistryImpl_Stub.rebind(Unknown Source)
at java.rmi.Naming.rebind(Naming.java:160)
at examples.hello.HelloImpl.main(HelloImpl.java:17)

Who can help me to solve the problem.
Here is my code:
package examples.hello;
import java.rmi.*;
public interface Hello extends Remote {
String sayHello() throws RemoteException;
}

package examples.hello;
import java.rmi.*;
import java.rmi.server.UnicastRemoteObject;
public class HelloImpl extends UnicastRemoteObject implements Hello {
private String name;
public HelloImpl(String s) throws RemoteException {
super();
name = s;
}
public String sayHello() throws RemoteException {
return "Hello Zeng Gang";
}
public static void main(String[] args) {
System.setSecurityManager(new RMISecurityManager());
try {
HelloImpl obj = new HelloImpl("HelloServer");
Naming.rebind("/HelloServer",obj);
System.out.println("HelloServer bound in registry");
}
catch(Exception e) {
System.out.println("HelloImpl err:"+e.getMessage());
e.printStackTrace();
}
}
}
Another question: How to use policy file?
Thanks!
Sai Prasad
Ranch Hand

Joined: Feb 25, 2002
Posts: 560
I guess you didn't start the RMI Registry. You can use the policy file by giving the policy file as one of the configuration parameters during the RMI server startup like -D java.security.policy=java.policy
JinXi Li
Greenhorn

Joined: Mar 12, 2002
Posts: 7
Thank you!
But I have started rmiregistry!
Sai Prasad
Ranch Hand

Joined: Feb 25, 2002
Posts: 560
Remove the code that sets the RMI Security Manager. If you like to use RMISecurityManager, you need to have a java.policy file which gives rights for the server to make the socket connection at port 1099
Terry Wang
Ranch Hand

Joined: Aug 27, 2001
Posts: 102
sample policy file:
grant {
permission java.security.AllPermission;
};


scjp/jd/wcd/mcad/scea 1
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17257
    
    6

I'd just remove the RMISecurity.
Mark


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
JinXi Li
Greenhorn

Joined: Mar 12, 2002
Posts: 7
Thanks for everyone!
I have solved the problem with policy file!
Thanks again!
John Smith
Ranch Hand

Joined: Oct 08, 2001
Posts: 2937
Mark Spritzler
bartender posted:
I'd just remove the RMISecurity.

Mark,
Do you think that the grader might take a few points off for not implementing the security?
Eugene Kononov.
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17257
    
    6

Mark,
Do you think that the grader might take a few points off for not implementing the security?

No, just ask Peter.
I had security on the client only in my submission. and I didn't even need that.
Mark
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: RMI Example