Her er mine filer
---------- myRMIServer.jar ------------
grant {
// Allow everything for now
permission java.security.AllPermission;
};
---------- Register.java ---------------
import java.rmi.*;
import java.rmi.activation.*;
import java.util.Properties;
public class Register {
/** Creates a new instance of Register */
public Register() {
}
public static void main(String[] args) throws Exception {
RMISecurityManager rmiMGR = new RMISecurityManager();
System.setSecurityManager(rmiMGR);
Properties pProperties = new Properties();
pProperties.put("java.security.policy",
"C:/Lokal disk (E)/DiplomIT/RMItest_2/src/policy");
ActivationGroupDesc.CommandEnvironment actCommandEnv = null;
ActivationGroupDesc actGroup = new ActivationGroupDesc(pProperties, actCommandEnv);
ActivationGroupID actGroupID = ActivationGroup.getSystem().registerGroup(actGroup);
String sFileLocations = "
file:///C:" +
"/Lokal disk (E)/DiplomIT/RMItest_2/src";
/* Create the rest of the parameters that will be passed to the
* ActivationGroupDesc constructor
*/
MarshalledObject marshalledObj = null;
ActivationDesc actDesc = new ActivationDesc(actGroupID, "TestActivationImpl",
sFileLocations, marshalledObj);
/* Register with rmid */
TestRemoteInterface trInterface = (TestRemoteInterface)Activatable.register(actDesc);
/* Bind the stub that we received with the RMI registry */
Naming.rebind("TestActivationImpl", trInterface);
}
}
----------------- TestClient.java ------------------
import java.rmi.*;
public class TestClient {
/** Creates a new instance of TestClient */
public TestClient() {
}
public static void main(String args[]) {
String sURI = "
rmi://127.0.0.1/TestActivationImpl"; /*Get a securety manager */
RMISecurityManager rmiSM = new RMISecurityManager();
System.setSecurityManager(rmiSM);
try{
TestRemoteInterface testRI = (TestRemoteInterface)Naming.lookup(sURI);
String sResponse = (String)testRI.rmiWelcome();
System.out.println("Received the following response from " +
"activatable remote object: " + sResponse);
}catch(Exception e){
e.printStackTrace();
}
}
}
------------------ TestRemoteInterface.java --------------------
import java.rmi.*;
public interface TestRemoteInterface extends Remote{
public String rmiWelcome() throws RemoteException;
}
--------------------- TestActivationImpl.java ------------------------
import java.rmi.*;
import java.rmi.activation.*;
public class TestActivationImpl extends Activatable implements TestRemoteInterface {
/** Creates a new instance of TestActivationImpl */
public TestActivationImpl(ActivationID activationID, MarshalledObject marshalledObj)
throws RemoteException {
// Register the object
super(activationID, 0);
}
/* Now you need to implement the remote interfaces here!
*/
public String rmiWelcome() throws RemoteException {
return (String)"Welcome to activatable RMI";
}
}