use of org.glassfish.embeddable.GlassFish in project Payara by payara.
the class BasicCDITest method test.
@Test
public void test() throws Exception {
GlassFishProperties props = new GlassFishProperties();
BootstrapProperties bootstrapProperties = new BootstrapProperties();
props.setPort("http-listener", 8080);
GlassFish glassfish = GlassFishRuntime.bootstrap(bootstrapProperties).newGlassFish(props);
glassfish.start();
// Test Scattered Web Archive
ScatteredArchive sa = new ScatteredArchive("cdi_ejb_jpa", ScatteredArchive.Type.WAR, new File("src/main/webapp"));
sa.addClassPath(new File("target/classes"));
sa.addClassPath(new File("src/main/resources"));
URI warURI = sa.toURI();
printContents(warURI);
// Deploy archive
Deployer deployer = glassfish.getDeployer();
String appname = deployer.deploy(warURI);
System.out.println("Deployed [" + appname + "]");
Assert.assertEquals(appname, "cdi_ejb_jpa");
// Now create a http listener and access the app.
WebContainer webcontainer = glassfish.getService(WebContainer.class);
HttpListener listener = new HttpListener();
listener.setId("my-listener");
listener.setPort(9090);
webcontainer.addWebListener(listener);
get("http://localhost:8080/cdi_ejb_jpa/BasicCDITestServlet", "All CDI beans have been injected.");
deployer.undeploy(appname);
glassfish.dispose();
}
use of org.glassfish.embeddable.GlassFish in project Payara by payara.
the class MySqlTest method test.
@Test
public void test() throws Exception {
GlassFishProperties glassFishProperties = new GlassFishProperties();
glassFishProperties.setPort("http-listener", 8080);
GlassFish glassFish = GlassFishRuntime.bootstrap().newGlassFish(glassFishProperties);
glassFish.start();
Deployer deployer = glassFish.getDeployer();
String appName = deployer.deploy(new File("target/mysqltest.war"));
System.out.println("Deployed [" + appName + "]");
// Access the app
get("http://localhost:8080/mysqltest/mysqlTestServlet", "connection = ");
glassFish.dispose();
}
use of org.glassfish.embeddable.GlassFish in project Payara by payara.
the class BookStoreTest method test.
@Test
public void test() throws Exception {
// 1. Bootstrap GlassFish DAS in embedded mode.
GlassFishProperties glassFishProperties = new GlassFishProperties();
glassFishProperties.setInstanceRoot(System.getenv("S1AS_HOME") + "/domains/domain1");
glassFishProperties.setConfigFileReadOnly(false);
GlassFish glassfish = GlassFishRuntime.bootstrap().newGlassFish(glassFishProperties);
PrintStream sysout = System.out;
glassfish.start();
System.setOut(sysout);
// 2. Deploy the PaaS-bookstore application.
File archive = new File(System.getProperty("basedir") + // TODO :: use mvn apis to get the
"/target/bookstore.war");
// archive location.
Assert.assertTrue(archive.exists());
Deployer deployer = null;
String appName = null;
try {
deployer = glassfish.getDeployer();
appName = deployer.deploy(archive);
System.err.println("Deployed [" + appName + "]");
Assert.assertNotNull(appName);
CommandRunner commandRunner = glassfish.getCommandRunner();
CommandResult result = commandRunner.run("list-services");
System.out.println("\nlist-services command output [ " + result.getOutput() + "]");
// 3. Access the app to make sure PaaS-bookstore app is correctly
// provisioned.
String HTTP_PORT = (System.getProperty("http.port") != null) ? System.getProperty("http.port") : "28080";
String instanceIP = getLBIPAddress(glassfish);
get("http://" + instanceIP + ":" + HTTP_PORT + "/bookstore/BookStoreServlet", "Please wait while accessing the bookstore database.....");
get("http://" + instanceIP + ":" + HTTP_PORT + "/bookstore/BookStoreServlet?title=Advanced+guide+for+developing+PaaS+components&authors=Shalini+M&price=100%24", "Here are the list of books available in our store:");
get("http://" + instanceIP + ":" + HTTP_PORT + "/bookstore/BookStoreServlet", "Advanced guide for developing PaaS components");
// 4. Undeploy the Bookstore application .
} finally {
if (appName != null) {
deployer.undeploy(appName);
System.err.println("Undeployed [" + appName + "]");
try {
boolean undeployClean = false;
CommandResult commandResult = glassfish.getCommandRunner().run("list-services");
if (commandResult.getOutput().contains("Nothing to list.")) {
undeployClean = true;
}
Assert.assertTrue(undeployClean);
} catch (Exception e) {
System.err.println("Couldn't varify whether undeploy succeeded");
}
}
}
}
use of org.glassfish.embeddable.GlassFish in project Payara by payara.
the class EmbeddedOSGiGlassFishRuntime method newGlassFish.
@Override
public synchronized GlassFish newGlassFish(GlassFishProperties gfProps) throws GlassFishException {
try {
// set env props before updating config, because configuration update may actually trigger
// some code to be executed which may be depending on the environment variable values.
setEnv(gfProps.getProperties());
final StartupContext startupContext = new StartupContext(gfProps.getProperties());
final ServiceTracker hk2Tracker = new ServiceTracker(getBundleContext(), Main.class.getName(), null);
hk2Tracker.open();
final Main main = (Main) hk2Tracker.waitForService(0);
hk2Tracker.close();
final ModulesRegistry mr = ModulesRegistry.class.cast(getBundleContext().getService(getBundleContext().getServiceReference(ModulesRegistry.class.getName())));
ServiceLocator serviceLocator = main.createServiceLocator(mr, startupContext, null, null);
final ModuleStartup gfKernel = main.findStartupService(mr, serviceLocator, null, startupContext);
GlassFish glassFish = createGlassFish(gfKernel, serviceLocator, gfProps.getProperties());
gfs.add(glassFish);
return glassFish;
} catch (BootException ex) {
throw new GlassFishException(ex);
} catch (InterruptedException ex) {
throw new GlassFishException(ex);
}
}
use of org.glassfish.embeddable.GlassFish in project Payara by payara.
the class OSGiGlassFishRuntime method newGlassFish.
@Override
public GlassFish newGlassFish(GlassFishProperties glassfishProperties) throws GlassFishException {
GlassFish embeddedGf = super.newGlassFish(glassfishProperties);
int finalStartLevel = Integer.parseInt(glassfishProperties.getProperties().getProperty(Constants.FINAL_START_LEVEL_PROP, "2"));
return new OSGiGlassFishImpl(embeddedGf, framework.getBundleContext(), finalStartLevel);
}
Aggregations