Search in sources :

Example 1 with ContainerBuilder

use of org.glassfish.internal.embedded.ContainerBuilder 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 ContainerBuilder

use of org.glassfish.internal.embedded.ContainerBuilder in project Payara by payara.

the class EmbeddedTest method testWeb.

@Test
public void testWeb() throws Exception {
    System.out.println("Starting Web " + server);
    ContainerBuilder b = server.createConfig(ContainerBuilder.Type.web);
    System.out.println("builder is " + b);
    server.addContainer(b);
    EmbeddedDeployer deployer = server.getDeployer();
    System.out.println("Added Web");
    String testClass = "org/glassfish/tests/embedded/webwar/EmbeddedTest.class";
    URL source = this.getClass().getClassLoader().getResource(testClass);
    String p = source.getPath().substring(0, source.getPath().length() - testClass.length()) + "../../../war/target/test-war.war";
    System.out.println("Root is " + p);
    DeployCommandParameters dp = new DeployCommandParameters(new File(p));
    System.out.println("Deploying " + p);
    String appName = null;
    try {
        appName = deployer.deploy(new File(p), dp);
        System.out.println("Deployed " + appName);
        Assert.assertTrue(appName != null);
        try {
            URL servlet = new URL("http://localhost:8080/test-war/");
            URLConnection yc = servlet.openConnection();
            BufferedReader in = new BufferedReader(new InputStreamReader(yc.getInputStream()));
            String inputLine = in.readLine();
            if (inputLine != null)
                System.out.println(inputLine);
            Assert.assertEquals(inputLine.trim(), "filterMessage=213");
            in.close();
        } catch (Exception e) {
            e.printStackTrace();
            throw e;
        }
    } catch (Exception e) {
        e.printStackTrace();
        throw e;
    }
    if (appName != null)
        deployer.undeploy(appName, null);
}
Also used : DeployCommandParameters(org.glassfish.api.deployment.DeployCommandParameters) EmbeddedDeployer(org.glassfish.internal.embedded.EmbeddedDeployer) ContainerBuilder(org.glassfish.internal.embedded.ContainerBuilder) InputStreamReader(java.io.InputStreamReader) BufferedReader(java.io.BufferedReader) File(java.io.File) URL(java.net.URL) URLConnection(java.net.URLConnection) NamingException(javax.naming.NamingException) LifecycleException(org.glassfish.internal.embedded.LifecycleException) IOException(java.io.IOException) Test(org.junit.Test)

Aggregations

IOException (java.io.IOException)2 ContainerBuilder (org.glassfish.internal.embedded.ContainerBuilder)2 BufferedReader (java.io.BufferedReader)1 File (java.io.File)1 InputStreamReader (java.io.InputStreamReader)1 URL (java.net.URL)1 URLConnection (java.net.URLConnection)1 NamingException (javax.naming.NamingException)1 DeployCommandParameters (org.glassfish.api.deployment.DeployCommandParameters)1 EmbeddedWebContainer (org.glassfish.api.embedded.web.EmbeddedWebContainer)1 NetworkConfig (org.glassfish.grizzly.config.dom.NetworkConfig)1 NetworkListener (org.glassfish.grizzly.config.dom.NetworkListener)1 EmbeddedDeployer (org.glassfish.internal.embedded.EmbeddedDeployer)1 LifecycleException (org.glassfish.internal.embedded.LifecycleException)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