if (gfr == null) {
try {
LOGGER.info("Create instantiated GlassFishRuntime");
gfr = GlassFishRuntime.bootstrap();
} catch (GlassFishException ex) {
throw new TestContainerException(ex);
}
} else {
LOGGER.info("Re-use Already instantiated GlassFishRuntime");
// try doing gfr.shutdown() if you were to
// bootstrap GlassFishRuntime again.
// Shutdown GlassFish.
try {
gfr.shutdown();
// can comment out to see if this fixes 'already bootstrapped' error
// but never reaches here on 2nd test
gfr = GlassFishRuntime.bootstrap();
} catch (GlassFishException shutdownex) {
throw new TestContainerException(shutdownex);
}
}
if (glassfish == null) {
try {
GlassFishProperties gfProperties = new GlassFishProperties();
gfProperties.setPort("http-listener", getBaseUri().getPort());
glassfish = gfr.newGlassFish(gfProperties);
// use glassfish
} catch (GlassFishException ngfex) {
throw new TestContainerException(ngfex);
}
} else {
LOGGER.info("Dispose Already instantiated GlassFish");
try {
// dispose it.
glassfish.dispose();
} catch (GlassFishException disposeex) {
throw new TestContainerException(disposeex);
}
LOGGER.info("Create another instantiated GlassFish");
try {
glassfish = gfr.newGlassFish();
} catch (GlassFishException ngfex2) {
throw new TestContainerException(ngfex2);
}
}
}