use of org.glassfish.embeddable.web.WebContainer in project Payara by payara.
the class BasicCDITest method test.
@Test
public void test() throws Exception {
GlassFishProperties props = new GlassFishProperties();
props.setPort("http-listener", 8080);
GlassFish glassfish = GlassFishRuntime.bootstrap().newGlassFish(props);
glassfish.start();
// Test Scattered Web Archive
ScatteredArchive sa = new ScatteredArchive("cdi_basic", 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_basic");
// 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_basic/BasicCDITestServlet", "All CDI beans have been injected.");
deployer.undeploy(appname);
glassfish.dispose();
}
use of org.glassfish.embeddable.web.WebContainer 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.web.WebContainer in project Payara by payara.
the class WebContainerImpl method init.
// --------------------------------------------------------- Private Methods
private void init() {
if (initialized) {
return;
}
if (config == null) {
// use default settings
config = new WebContainerConfig();
}
container = habitat.getServiceHandle(org.glassfish.api.container.Container.class, "com.sun.enterprise.web.WebContainer");
if (container == null) {
log.severe("Cannot find webcontainer implementation");
return;
}
ActiveDescriptor<?> activeDescriptor = habitat.getBestDescriptor(BuilderHelper.createContractFilter("com.sun.enterprise.web.EmbeddedWebContainer"));
if (activeDescriptor == null) {
log.severe("Cannot find embedded implementation");
return;
}
embeddedInhabitant = habitat.getServiceHandle(activeDescriptor);
try {
webContainer = (com.sun.enterprise.web.WebContainer) container.getService();
embedded = (EmbeddedWebContainer) embeddedInhabitant.getService();
if ((webContainer == null) || (embedded == null)) {
log.severe("Cannot find webcontainer implementation");
return;
}
engine = webContainer.getEngine();
if (engine == null) {
log.severe("Cannot find engine implementation");
return;
}
initialized = true;
} catch (Exception e) {
log.severe("Init exception " + e.getMessage());
}
}
use of org.glassfish.embeddable.web.WebContainer in project Payara by payara.
the class EmbeddedTest method setup.
@BeforeClass
public static void setup() throws GlassFishException {
glassfish = GlassFishRuntime.bootstrap().newGlassFish();
glassfish.start();
WebContainer webcontainer = glassfish.getService(WebContainer.class);
Collection<WebListener> listeners = webcontainer.getWebListeners();
System.out.println("Network listener size before creation " + listeners.size());
for (WebListener listener : listeners) {
System.out.println("Network listener " + listener.getPort());
}
try {
HttpListener listener = new HttpListener();
listener.setPort(8080);
listener.setId("embedded-listener-1");
webcontainer.addWebListener(listener);
} catch (Exception e) {
throw new RuntimeException(e);
}
listeners = webcontainer.getWebListeners();
System.out.println("Network listener size after creation " + listeners.size());
Assert.assertTrue(listeners.size() == 1);
for (WebListener listener : listeners) {
System.out.println("Network listener " + listener.getPort());
}
}
use of org.glassfish.embeddable.web.WebContainer in project Payara by payara.
the class ScatteredArchiveTest method test.
@Test
public void test() throws Exception {
GlassFishProperties props = new GlassFishProperties();
props.setPort("http-listener", 8080);
GlassFish glassfish = GlassFishRuntime.bootstrap().newGlassFish(props);
glassfish.start();
// Test Scattered Web Archive
ScatteredArchive sa = new ScatteredArchive("scatteredarchive", 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, "scatteredarchive");
// 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:9090/satest", "Hi, my name is Bhavani. What's yours?");
get("http://localhost:9090/satest/ScatteredArchiveTestServlet", "Hi from ScatteredArchiveTestServlet");
get("http://localhost:8080/satest/ScatteredArchiveTestServlet", "Hi from ScatteredArchiveTestServlet");
deployer.undeploy(appname);
// Test Scattered RA
ScatteredArchive rar = new ScatteredArchive("scatteredra", ScatteredArchive.Type.RAR);
rar.addClassPath(new File("target/classes"));
rar.addMetadata(new File("src/main/config/ra.xml"));
URI rarURI = rar.toURI();
printContents(rarURI);
appname = deployer.deploy(rarURI);
System.out.println("Deployed RAR [" + appname + "]");
Assert.assertEquals(appname, "scatteredra");
// Test Scattered Enterprise Archive.
ScatteredEnterpriseArchive ear = new ScatteredEnterpriseArchive("sear");
ear.addArchive(warURI, "sa.war");
ear.addArchive(rarURI);
ear.addMetadata(new File("src/main/config/application.xml"));
URI earURI = ear.toURI();
printContents(earURI);
appname = deployer.deploy(earURI);
System.out.println("Deployed [" + appname + "]");
Assert.assertEquals(appname, "sear");
get("http://localhost:9090/satest", "Hi, my name is Bhavani. What's yours?");
get("http://localhost:9090/satest/ScatteredArchiveTestServlet", "Hi from ScatteredArchiveTestServlet");
get("http://localhost:8080/satest/ScatteredArchiveTestServlet", "Hi from ScatteredArchiveTestServlet");
glassfish.dispose();
}
Aggregations