Search in sources :

Example 1 with WebContainer

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();
}
Also used : ScatteredArchive(org.glassfish.embeddable.archive.ScatteredArchive) WebContainer(org.glassfish.embeddable.web.WebContainer) HttpListener(org.glassfish.embeddable.web.HttpListener) GlassFish(org.glassfish.embeddable.GlassFish) JarFile(java.util.jar.JarFile) File(java.io.File) URI(java.net.URI) GlassFishProperties(org.glassfish.embeddable.GlassFishProperties) Deployer(org.glassfish.embeddable.Deployer) Test(org.junit.Test)

Example 2 with WebContainer

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();
}
Also used : ScatteredArchive(org.glassfish.embeddable.archive.ScatteredArchive) BootstrapProperties(org.glassfish.embeddable.BootstrapProperties) WebContainer(org.glassfish.embeddable.web.WebContainer) HttpListener(org.glassfish.embeddable.web.HttpListener) GlassFish(org.glassfish.embeddable.GlassFish) JarFile(java.util.jar.JarFile) File(java.io.File) URI(java.net.URI) GlassFishProperties(org.glassfish.embeddable.GlassFishProperties) Deployer(org.glassfish.embeddable.Deployer) Test(org.junit.Test)

Example 3 with WebContainer

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());
    }
}
Also used : EmbeddedWebContainer(com.sun.enterprise.web.EmbeddedWebContainer) WebContainer(org.glassfish.embeddable.web.WebContainer) Container(org.apache.catalina.Container) WebContainerConfig(org.glassfish.embeddable.web.config.WebContainerConfig) PropertyVetoException(java.beans.PropertyVetoException) ConfigException(org.glassfish.embeddable.web.ConfigException) GlassFishException(org.glassfish.embeddable.GlassFishException)

Example 4 with WebContainer

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());
    }
}
Also used : WebListener(org.glassfish.embeddable.web.WebListener) WebContainer(org.glassfish.embeddable.web.WebContainer) HttpListener(org.glassfish.embeddable.web.HttpListener) GlassFishException(org.glassfish.embeddable.GlassFishException) NamingException(javax.naming.NamingException) BeforeClass(org.junit.BeforeClass)

Example 5 with WebContainer

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();
}
Also used : ScatteredArchive(org.glassfish.embeddable.archive.ScatteredArchive) WebContainer(org.glassfish.embeddable.web.WebContainer) ScatteredEnterpriseArchive(org.glassfish.embeddable.archive.ScatteredEnterpriseArchive) HttpListener(org.glassfish.embeddable.web.HttpListener) GlassFish(org.glassfish.embeddable.GlassFish) JarFile(java.util.jar.JarFile) File(java.io.File) URI(java.net.URI) GlassFishProperties(org.glassfish.embeddable.GlassFishProperties) Deployer(org.glassfish.embeddable.Deployer) Test(org.junit.Test)

Aggregations

WebContainer (org.glassfish.embeddable.web.WebContainer)5 HttpListener (org.glassfish.embeddable.web.HttpListener)4 File (java.io.File)3 URI (java.net.URI)3 JarFile (java.util.jar.JarFile)3 Deployer (org.glassfish.embeddable.Deployer)3 GlassFish (org.glassfish.embeddable.GlassFish)3 GlassFishProperties (org.glassfish.embeddable.GlassFishProperties)3 ScatteredArchive (org.glassfish.embeddable.archive.ScatteredArchive)3 Test (org.junit.Test)3 GlassFishException (org.glassfish.embeddable.GlassFishException)2 EmbeddedWebContainer (com.sun.enterprise.web.EmbeddedWebContainer)1 PropertyVetoException (java.beans.PropertyVetoException)1 NamingException (javax.naming.NamingException)1 Container (org.apache.catalina.Container)1 BootstrapProperties (org.glassfish.embeddable.BootstrapProperties)1 ScatteredEnterpriseArchive (org.glassfish.embeddable.archive.ScatteredEnterpriseArchive)1 ConfigException (org.glassfish.embeddable.web.ConfigException)1 WebListener (org.glassfish.embeddable.web.WebListener)1 WebContainerConfig (org.glassfish.embeddable.web.config.WebContainerConfig)1