4

I am trying to start an embedded Google App Engine Development Server (sdk 1.7.3) inside a @BeforeClass of a test suite run by the maven failsafe plugin. The code that should start it looks like this:

private static final String HOST = "0.0.0.0";
private static final int PORT = 8887;
private static DevAppServer devAppServer;


@BeforeClass
public static void setup() throws Exception {
    log.debug("Starting development server");
    File appRootDir = new File("target/visualize-1.0.war");
    DevAppServerFactory devAppServerFactory = new DevAppServerFactory();
    devAppServer = devAppServerFactory.createDevAppServer(appRootDir, HOST, PORT); 
    devAppServer.start();
}

However during the call to createDevAppServer, I get a security exception:

java.security.AccessControlException: access denied (java.lang.RuntimePermission setContextClassLoader)
at java.security.AccessControlContext.checkPermission(AccessControlContext.java:374)
at java.security.AccessController.checkPermission(AccessController.java:546)
at java.lang.SecurityManager.checkPermission(SecurityManager.java:532)
at java.lang.Thread.setContextClassLoader(Thread.java:1394)
at org.apache.maven.surefire.booter.SurefireBooter.runSuitesInProcess(SurefireBooter.java:366)
at org.apache.maven.surefire.booter.SurefireBooter.main(SurefireBooter.java:1021)

debugging the security exception with -Djava.security.debug=access,failure I see:

  access: access allowed (java.io.FilePermission    /home/me/.m2/repository/com/google/appengine/appengine-tools-sdk/1.7.3/appengine-tools-sdk-1.7.3.jar read)
 access: access denied (java.security.SecurityPermission getPolicy)
java.lang.Exception: Stack trace
at java.lang.Thread.dumpStack(Thread.java:1249)
at java.security.AccessControlContext.checkPermission(AccessControlContext.java:364)
at java.security.AccessController.checkPermission(AccessController.java:546)
at java.lang.SecurityManager.checkPermission(SecurityManager.java:532)
at java.security.Policy.getPolicy(Policy.java:133)
at com.google.apphosting.utils.security.SecurityManagerInstaller.install(SecurityManagerInstaller.java:81)
at com.google.appengine.tools.development.DevAppServerFactory.createDevAppServer(DevAppServerFactory.java:152)
at com.google.appengine.tools.development.DevAppServerFactory.createDevAppServer(DevAppServerFactory.java:69)
at com.google.appengine.tools.development.DevAppServerFactory.createDevAppServer(DevAppServerFactory.java:53)

What am I doing wrong?

nwaltham
  • 2,067
  • 1
  • 22
  • 40
  • I have also tried specifying a totally permissive security policy like this: grant { permission java.security.AllPermission; permission java.lang.reflect.ReflectPermission "suppressAccessChecks"; }; But then I just another exception from the google code saying a security manager is already installed – nwaltham Nov 12 '12 at 12:05
  • I'm interested in the answer but in the meantime, I'm curious about the type of integration tests you're writing that require the app server running. We have several integration tests that use the various LocalServiceTestHelpers as well as UI tests running against a dev server launched via Ant. The UI tests run slowly so I'm always looking for ways to get the same test coverage faster. – Kyle Baley Dec 28 '12 at 03:25
  • Hi Kyle, perhaps my case is not relevant to you; I am not using GWT, but in fact Restlet for GAE - to provide rest web services. I am then consuming these with JSON. – nwaltham Jan 02 '13 at 07:28
  • Thanks for accepting - The whole project is in github.com/ipeirotis/ReadabilityMetrics/ and it is also a RESTful server. Perhaps you might learn a trick or two. – aldrinleal Jan 02 '13 at 14:30

1 Answers1

2

Actually, you're not supposed to call GAE the way you've done (hint: GAE has so many patches for dealing with security its simply not worth it)

However, the maven-gae-plugin does have gae:start and gae:stop specially for IT.

This is how I use it for IT:

<plugin>
    <groupId>net.kindleit</groupId>
    <artifactId>maven-gae-plugin</artifactId>
    <version>0.9.4</version>
    <dependencies>
        <dependency>
            <groupId>net.kindleit</groupId>
            <artifactId>gae-runtime</artifactId>
            <version>1.6.6</version>
            <type>pom</type>
        </dependency>
    </dependencies>
    <executions>
        <execution>
            <id>start-integration-test</id>
            <phase>pre-integration-test</phase>
            <goals>
                <goal>start</goal>
            </goals>
        </execution>
        <execution>
            <id>stop-integration-test</id>
            <phase>post-integration-test</phase>
            <goals>
                <goal>stop</goal>
            </goals>
        </execution>
    </executions>
</plugin>
<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-failsafe-plugin</artifactId>
    <version>2.12</version>
    <executions>
        <execution>
            <id>it</id>
            <phase>integration-test</phase>
            <goals>
                <goal>integration-test</goal>
            </goals>
        </execution>
    </executions>
</plugin>
aldrinleal
  • 3,559
  • 26
  • 33