Search in sources :

Example 1 with EmbeddedWebContainer

use of org.glassfish.api.embedded.web.EmbeddedWebContainer in project Payara by payara.

the class EmbeddedTest method setup.

@BeforeClass
public static void setup() {
    Server.Builder builder = new Server.Builder("build");
    server = builder.build();
    NetworkConfig nc = server.getHabitat().getService(NetworkConfig.class, ServerEnvironment.DEFAULT_INSTANCE_NAME);
    List<NetworkListener> listeners = nc.getNetworkListeners().getNetworkListener();
    System.out.println("Network listener size before creation " + listeners.size());
    for (NetworkListener nl : listeners) {
        System.out.println("Network listener " + nl.getPort());
    }
    try {
        http = server.createPort(8080);
        ContainerBuilder b = server.createConfig(ContainerBuilder.Type.web);
        server.addContainer(b);
        EmbeddedWebContainer embedded = (EmbeddedWebContainer) b.create(server);
        embedded.bind(http, "http");
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
    listeners = nc.getNetworkListeners().getNetworkListener();
    System.out.println("Network listener size after creation " + listeners.size());
    Assert.assertTrue(listeners.size() == 1);
    for (NetworkListener nl : listeners) {
        System.out.println("Network listener " + nl.getPort());
    }
    Collection<NetworkListener> cnl = server.getHabitat().getAllServices(NetworkListener.class);
    System.out.println("Network listener size after creation " + cnl.size());
    for (NetworkListener nl : cnl) {
        System.out.println("Network listener " + nl.getPort());
    }
    server.addContainer(ContainerBuilder.Type.all);
}
Also used : ContainerBuilder(org.glassfish.internal.embedded.ContainerBuilder) Server(org.glassfish.internal.embedded.Server) EmbeddedWebContainer(org.glassfish.api.embedded.web.EmbeddedWebContainer) ContainerBuilder(org.glassfish.internal.embedded.ContainerBuilder) Builder(org.glassfish.internal.embedded.ScatteredArchive.Builder) NetworkConfig(org.glassfish.grizzly.config.dom.NetworkConfig) IOException(java.io.IOException) NetworkListener(org.glassfish.grizzly.config.dom.NetworkListener) BeforeClass(org.junit.BeforeClass)

Example 2 with EmbeddedWebContainer

use of org.glassfish.api.embedded.web.EmbeddedWebContainer in project Payara by payara.

the class InplantedTest method testWeb.

@Test
public void testWeb() throws Exception {
    System.out.println("test web");
    File f = new File(System.getProperty("basedir"));
    f = new File(f, "target");
    f = new File(f, "test-classes");
    ScatteredArchive.Builder builder = new ScatteredArchive.Builder("hello", f);
    builder.addClassPath(f.toURI().toURL());
    builder.resources(f);
    ScatteredArchive war = builder.buildWar();
    System.out.println("War content");
    Enumeration<String> contents = war.entries();
    while (contents.hasMoreElements()) {
        System.out.println(contents.nextElement());
    }
    Port http = server.createPort(8080);
    ContainerBuilder b = server.createConfig(ContainerBuilder.Type.web);
    server.addContainer(b);
    EmbeddedWebContainer embedded = (EmbeddedWebContainer) b.create(server);
    embedded.bind(http, "http");
    DeployCommandParameters dp = new DeployCommandParameters(f);
    String appName = server.getDeployer().deploy(war, dp);
    WebClient webClient = new WebClient();
    Page page = webClient.getPage("http://localhost:8080/test-classes/hello");
    System.out.println("Got response " + page.getWebResponse().getContentAsString());
    Assert.assertTrue("Servlet returned wrong content", page.getWebResponse().getContentAsString().startsWith("Hello World"));
    server.getDeployer().undeploy(appName, null);
}
Also used : DeployCommandParameters(org.glassfish.api.deployment.DeployCommandParameters) EmbeddedWebContainer(org.glassfish.api.embedded.web.EmbeddedWebContainer) HtmlPage(com.gargoylesoftware.htmlunit.html.HtmlPage) Page(com.gargoylesoftware.htmlunit.Page) File(java.io.File) WebClient(com.gargoylesoftware.htmlunit.WebClient) Test(org.junit.Test)

Aggregations

EmbeddedWebContainer (org.glassfish.api.embedded.web.EmbeddedWebContainer)2 Page (com.gargoylesoftware.htmlunit.Page)1 WebClient (com.gargoylesoftware.htmlunit.WebClient)1 HtmlPage (com.gargoylesoftware.htmlunit.html.HtmlPage)1 File (java.io.File)1 IOException (java.io.IOException)1 DeployCommandParameters (org.glassfish.api.deployment.DeployCommandParameters)1 NetworkConfig (org.glassfish.grizzly.config.dom.NetworkConfig)1 NetworkListener (org.glassfish.grizzly.config.dom.NetworkListener)1 ContainerBuilder (org.glassfish.internal.embedded.ContainerBuilder)1 Builder (org.glassfish.internal.embedded.ScatteredArchive.Builder)1 Server (org.glassfish.internal.embedded.Server)1 BeforeClass (org.junit.BeforeClass)1 Test (org.junit.Test)1