Must everything be a RMI App/JUnit now ?

This is the place for general discussion of the RMI plugin for Eclipse and support questions

Must everything be a RMI App/JUnit now ?

Postby DMF » Wed Jul 09, 2008 12:48 am

This application is built to go through a central (singleton) DataFactory for data access, anticipating the time when the database would be remote. Now I've moved the database engine off into it's own process, changed the calls within the DataFactory to remote calls, and set up DataFactory to connect to the remote engine in the class initializer.

Code: Select all
public class DataFactory
{
    static {
        setProperties();
        initialize();
    }
   
    private static Server serv = null;
   
    public static boolean initialize()  {
        /*
         * RMI Plug-in created a security.policy file in the
         * project root that grants ALL permissions.
         */
        if( System.getSecurityManager() == null) {
            System.setSecurityManager(new RMISecurityManager());
        }
        String name = ApplicationContext.DbServerName();
        String URL  = ApplicationContext.DbServerURL();
        try {
            serv = (Server)Naming.lookup( URL+name );
            consoleOut("DataFactory is connected to DbServer.");
            return true;
        }
        catch( MalformedURLException ex ) { // fm Naming
            ex.printStackTrace();
            return false;
        }
        catch( NotBoundException ex ) { // fm Naming
            ex.printStackTrace();
            return false;
        }
        catch( RemoteException ex ) { // fm Naming or call to Server
            ex.printStackTrace();
            return false;
        }
    }
   
    public static final Timestamp getCurrentTime ( )  {
        try {
            return serv.getCurrentTime ();
        }
        catch( RemoteException ex ) {
            ex.printStackTrace();
            return null;
        }
    }

...
}   



This class was designed to isolate the 100 or so JUnits and clients from knowing anything about remote access or security. Here's a typical one:

Code: Select all
public class UnitTest {

    static DataFactory Fac = null;

    @BeforeClass
    public static void setUpBeforeClass() throws Exception {
        /* Class reference runs static initializer connecting to remote */
        Fac = ApplicationContext.getDataFactory();
    }

    Data data = null;

    @Before
    public void setUp() throws Exception {
        this.data = Fac.getData( key );
    }

}


The problem is that I can't run any of them now without declaring it a RMI Application or RMI JUnit. If I don't I get this exception

Code: Select all
java.security.AccessControlException: access denied (java.lang.RuntimePermission accessDeclaredMembers)
   at java.security.AccessControlContext.checkPermission(AccessControlContext.java:264)
   at java.security.AccessController.checkPermission(AccessController.java:427)
   at java.lang.SecurityManager.checkPermission(SecurityManager.java:532)
   at java.lang.SecurityManager.checkMemberAccess(SecurityManager.java:1662)
   at java.lang.Class.checkMemberAccess(Class.java:2125)
   at java.lang.Class.getDeclaredMethods(Class.java:1762)
   at org.junit.internal.runners.TestIntrospector.getTestMethods(TestIntrospector.java:26)
   at org.junit.internal.runners.BeforeAndAfterRunner.runAfters(BeforeAndAfterRunner.java:62)
   at org.junit.internal.runners.BeforeAndAfterRunner.runProtected(BeforeAndAfterRunner.java:37)
   at org.junit.internal.runners.TestClassRunner.run(TestClassRunner.java:52)
   at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:38)
   at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
   at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:460)
   at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673)
   at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386)
   at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)


apparently caused by ignorance of the security.policy file that would be specified on the RMI VM Properties tab in the Run Dialog.

Surely there must be a way to do whatever is needed programmatically. What do I need to do? Modify the default security.policy file? Or is there a way to load the replacement from within DataFactory or ApplicationContext?


Edit: fixed the -Djava.security.policy problem. It had embedded spaces.

So what should I do, define that System property at runtime? What about codebase?
DMF
 
Posts: 2
Joined: Wed Jul 09, 2008 12:08 am

Postby DMF » Wed Jul 09, 2008 2:55 pm

Yes, defining the property at runtime works for the couple I've tested. Anything else I need to set at runtime? Codebase?

Code: Select all
  public static boolean initialize()  {
        /*
         * RMI Plug-in created a security.policy file in the
         * project root that grants ALL permissions.
         */
        System.setProperty("java.security.policy"
                          ,"C:/wspace/Project/security.policy");
        if( System.getSecurityManager() == null) {
            System.setSecurityManager(new RMISecurityManager());
        }
...
DMF
 
Posts: 2
Joined: Wed Jul 09, 2008 12:08 am


Return to General discussion and support

Who is online

Users browsing this forum: No registered users and 3 guests

cron