use of org.glassfish.embeddable.web.HttpListener 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.HttpListener 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.HttpListener in project Payara by payara.
the class WebContainerImpl method bind.
private void bind(Port port, WebListener webListener, String vsId) {
String protocol = Port.HTTP_PROTOCOL;
final int portNumber = port.getPortNumber();
final String defaultVS = vsId;
final WebListener listener = webListener;
if (webListener == null) {
listenerName = getListenerName();
webListener = new HttpListener();
webListener.setId(listenerName);
webListener.setPort(portNumber);
} else {
listenerName = webListener.getId();
protocol = webListener.getProtocol();
}
listeners.add(webListener);
if (protocol.equals(Port.HTTP_PROTOCOL)) {
securityEnabled = "false";
} else if (protocol.equals(Port.HTTPS_PROTOCOL)) {
securityEnabled = "true";
}
try {
ConfigSupport.apply(new SingleConfigCode<Protocols>() {
public Object run(Protocols param) throws TransactionFailure {
final Protocol protocol = param.createChild(Protocol.class);
protocol.setName(listenerName);
protocol.setSecurityEnabled(securityEnabled);
param.getProtocol().add(protocol);
final Http http = protocol.createChild(Http.class);
http.setDefaultVirtualServer(defaultVS);
http.setFileCache(http.createChild(FileCache.class));
protocol.setHttp(http);
return protocol;
}
}, networkConfig.getProtocols());
ConfigSupport.apply(new ConfigCode() {
public Object run(ConfigBeanProxy... params) throws TransactionFailure {
NetworkListeners nls = (NetworkListeners) params[0];
Transports transports = (Transports) params[1];
final NetworkListener listener = nls.createChild(NetworkListener.class);
listener.setName(listenerName);
listener.setPort(Integer.toString(portNumber));
listener.setProtocol(listenerName);
listener.setThreadPool("http-thread-pool");
if (listener.findThreadPool() == null) {
final ThreadPool pool = nls.createChild(ThreadPool.class);
pool.setName(listenerName);
listener.setThreadPool(listenerName);
}
listener.setTransport("tcp");
if (listener.findTransport() == null) {
final Transport transport = transports.createChild(Transport.class);
transport.setName(listenerName);
listener.setTransport(listenerName);
}
nls.getNetworkListener().add(listener);
return listener;
}
}, networkConfig.getNetworkListeners(), networkConfig.getTransports());
if (webListener.getProtocol().equals("https")) {
NetworkListener networkListener = networkConfig.getNetworkListener(listenerName);
Protocol httpProtocol = networkListener.findHttpProtocol();
ConfigSupport.apply(new SingleConfigCode<Protocol>() {
public Object run(Protocol param) throws TransactionFailure {
Ssl newSsl = param.createChild(Ssl.class);
populateSslElement(newSsl, listener);
System.out.println("SSL " + newSsl.getKeyStore() + " " + newSsl.getKeyStorePassword() + " " + newSsl.getTrustStore() + " " + newSsl.getTrustStorePassword());
param.setSsl(newSsl);
return newSsl;
}
}, httpProtocol);
}
com.sun.enterprise.config.serverbeans.VirtualServer vs = httpService.getVirtualServerByName(config.getVirtualServerId());
ConfigSupport.apply(new SingleConfigCode<com.sun.enterprise.config.serverbeans.VirtualServer>() {
public Object run(com.sun.enterprise.config.serverbeans.VirtualServer avs) throws PropertyVetoException {
avs.addNetworkListener(listenerName);
return avs;
}
}, vs);
} catch (Exception e) {
if (listeners.contains(webListener)) {
listeners.remove(webListener);
}
e.printStackTrace();
}
}
use of org.glassfish.embeddable.web.HttpListener 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.HttpListener 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