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);
}
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);
}
Aggregations