Hello All
I'm trying to run the server class to create remote objects and registers them,I'm having that Exception.
Do i need to set up anything on my machine?
please any help?
Here is the full output:
============================
C:\>
java -Djava.rmi..server.codebase=file:/..\..\-Djava.security.policy=RMI
Security.policy examples.network.StudentEnrollment
java.security.AccessControlException: access denied (java.net.SocketPermiss
ion 127.0.0.1:1099 connect,resolve)
at java.security.AccessControlContext.checkPermission(Unknown Sourc
e)
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.<init>(Unknown Source)
at java.net.Socket.<init>(Unknown Source)
at sun.rmi.transport.proxy.RMIDirectSocketFactory.createSocket(Unkn
own Source)
at sun.rmi.transport.proxy.RMIMasterSocketFactory.createSocket(Unkn
own 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)
===========================
Here are all files that i have:
====================================
package examples.network;
import java.rmi.Remote;
import java.rmi.RemoteException;
public interface Student extends Remote
{
public int getID() throws RemoteException;
public void setName(
String name) throws RemoteException;
public String getName() throws RemoteException;
public int getCredits() throws RemoteException;
public int addCredits(int credits) throws RemoteException;
}
=============================================
package examples.network;
import java.rmi.Naming;
import java.rmi.RMISecurityManager;
public class StudentClient
{
private static final String HOST_NAME="localhost";
public static void main(String s[])
{
if(System.getSecurityManager()==null)
{
System.setSecurityManager(new RMISecurityManager());
}
try
{
Student s1001=(Student) Naming.lookup("//"+HOST_NAME+"/Student1001");
Student s1002=(Student) Naming.lookup("//"+HOST_NAME+"/Student1002");
System.out.println(s1001.getName());
System.out.println(s1002.getName());
System.out.println(s1001.getCredits());
s1001.addCredits(3);
s1001.setName("Elaine Goldman");
System.out.println(s1001.getName());
System.out.println(s1001.getCredits());
}
catch(Exception x)
{
x.printStackTrace();
}
}
=============================================
package examples.network;
import java.rmi.Naming;
import java.rmi.RMISecurityManager;
public class StudentEnrollment
{
public static void main(String s[])
{
if(System.getSecurityManager()==null)
{
System.setSecurityManager(new RMISecurityManager());
}
try
{
StudentImpl[] students=
{
new StudentImpl(1001,"Matt1 Seif1"),
new StudentImpl(1002,"Matt2 Seif2"),
new StudentImpl(1003,"Matt3 Seif3")
};
for(int i=0;i<students.length;i++)
{
int id =students[i].getID();
Naming.rebind("student"+id,students[i]);
}
System.out.println("student objects bound .");
}
catch(Exception x)
{
x.printStackTrace();
}
}
}
===============================================
package examples.network;
import java.rmi.server.UnicastRemoteObject;
import java.rmi.RemoteException;
public class StudentImpl extends UnicastRemoteObject
implements Student
{
private int ID;
private String name;
private int credits=0;
public StudentImpl(int ID,String name)throws RemoteException
{
this.ID=ID;
this.name=name;
}
public int getID() throws RemoteException
{
return ID;
}
public void setName(String name) throws RemoteException
{
this.name=name;
}
public String getName() throws RemoteException
{
return name;
}
public int getCredits() throws RemoteException
{
return credits;
}
public int addCredits(int credits) throws RemoteException
{
return (this.credits +=credits);
}
}
===========================================