use of org.glassfish.grizzly.config.dom.NetworkListener 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.grizzly.config.dom.NetworkListener in project Payara by payara.
the class ExistingConfigurationTest method setupServer.
@Test
public void setupServer() throws Exception {
Server server = null;
System.out.println("setup started with gf installation " + System.getProperty("basedir"));
File f = new File(System.getProperty("basedir"));
f = new File(f, "target");
f = new File(f, "dependency");
f = new File(f, "glassfish4");
f = new File(f, "glassfish");
if (f.exists()) {
System.out.println("Using gf at " + f.getAbsolutePath());
} else {
System.out.println("GlassFish not found at " + f.getAbsolutePath());
Assert.assertTrue(f.exists());
}
try {
EmbeddedFileSystem.Builder efsb = new EmbeddedFileSystem.Builder();
efsb.installRoot(f, false);
// find the domain root.
f = new File(f, "domains");
f = new File(f, "domain1");
f = new File(f, "config");
f = new File(f, "domain.xml");
Assert.assertTrue(f.exists());
efsb.configurationFile(f);
Server.Builder builder = new Server.Builder("inplanted");
builder.embeddedFileSystem(efsb.build());
server = builder.build();
ServiceLocator habitat = server.getHabitat();
Collection<VirtualServer> vss = habitat.getAllServices(VirtualServer.class);
Assert.assertTrue(vss.size() > 0);
for (VirtualServer vs : vss) {
System.out.println("Virtual Server " + vs.getId());
}
Collection<NetworkListener> nls = habitat.getAllServices(NetworkListener.class);
for (NetworkListener nl : nls) {
System.out.println("Network listener " + nl.getPort());
}
} catch (Exception e) {
e.printStackTrace();
throw e;
} finally {
if (server != null) {
server.stop();
}
}
}
use of org.glassfish.grizzly.config.dom.NetworkListener in project Payara by payara.
the class WsUtil method getWebServerInfoForDAS.
public WebServerInfo getWebServerInfoForDAS() {
WebServerInfo wsi = new WebServerInfo();
if (this.networkListeners == null) {
List<Integer> adminPorts = new ArrayList<Integer>();
for (org.glassfish.api.container.Adapter subAdapter : WebServiceContractImpl.getInstance().getAdapters()) {
if (subAdapter instanceof AdminAdapter) {
AdminAdapter aa = (AdminAdapter) subAdapter;
adminPorts.add(aa.getListenPort());
} else if (subAdapter instanceof AdminConsoleAdapter) {
AdminConsoleAdapter aca = (AdminConsoleAdapter) subAdapter;
adminPorts.add(aca.getListenPort());
}
}
for (NetworkListener nl : config.getNetworkConfig().getNetworkListeners().getNetworkListener()) {
if (!adminPorts.contains(Integer.valueOf(nl.getPort()))) {
// get rid of admin ports
if (networkListeners == null)
networkListeners = new ArrayList<NetworkListener>();
networkListeners.add(nl);
}
}
}
// Fix for issue 13107490
if ((networkListeners != null) && (!networkListeners.isEmpty())) {
for (NetworkListener listener : networkListeners) {
String host = listener.getAddress();
if (listener.getAddress().equals("0.0.0.0"))
try {
host = InetAddress.getLocalHost().getHostName();
} catch (UnknownHostException e) {
// fallback
host = "localhost";
}
if (listener.findHttpProtocol().getSecurityEnabled().equals("false"))
wsi.setHttpVS(new VirtualServerInfo("http", host, Integer.parseInt(listener.getPort())));
else if (listener.findHttpProtocol().getSecurityEnabled().equals("true"))
wsi.setHttpsVS(new VirtualServerInfo("https", host, Integer.parseInt(listener.getPort())));
}
} else {
wsi.setHttpVS(new VirtualServerInfo("http", "localhost", 0));
wsi.setHttpsVS(new VirtualServerInfo("https", "localhost", 0));
}
return wsi;
}
use of org.glassfish.grizzly.config.dom.NetworkListener in project Payara by payara.
the class WebContainerImpl method addVirtualServer.
/**
* Adds the given <tt>VirtualServer</tt> to this
* <tt>WebContainer</tt>.
*
* <p>If this <tt>WebContainer</tt> has already been started,
* the given <tt>virtualServer</tt> will be started as well.
*
* @param virtualServer the <tt>VirtualServer</tt> to add
*
* @throws ConfigException if a <tt>VirtualServer</tt> with the
* same id has already been registered with this
* <tt>WebContainer</tt>
* @throws GlassFishException if the given <tt>virtualServer</tt> fails
* to be started
*/
public void addVirtualServer(VirtualServer virtualServer) throws ConfigException, GlassFishException {
if (!initialized) {
init();
}
if (log.isLoggable(Level.INFO)) {
log.info("Adding virtual server " + virtualServer.getID());
}
com.sun.enterprise.web.VirtualServer vs = (com.sun.enterprise.web.VirtualServer) engine.findChild(virtualServer.getID());
if (vs != null) {
throw new ConfigException("VirtualServer with id " + virtualServer.getID() + " is already registered");
}
Collection<WebListener> webListeners = virtualServer.getWebListeners();
List<String> names = new ArrayList<String>();
if ((webListeners != null) && (!webListeners.isEmpty())) {
for (WebListener listener : webListeners) {
names.add(listener.getId());
}
} else {
for (NetworkListener networkListener : networkConfig.getNetworkListeners().getNetworkListener()) {
names.add(networkListener.getName());
}
webListeners = listeners;
}
StringBuffer networkListeners = new StringBuffer("");
if (names.size() > 0) {
networkListeners.append(names.get(0));
}
for (int i = 1; i < names.size(); i++) {
networkListeners.append(",");
networkListeners.append(names.get(i));
}
String docRoot = null;
if (virtualServer.getDocRoot() != null) {
docRoot = virtualServer.getDocRoot().getAbsolutePath();
}
String hostName = null;
if (virtualServer.getConfig() != null) {
hostName = virtualServer.getConfig().getHostNames();
}
final String root = docRoot;
final String nl = networkListeners.toString();
final String id = virtualServer.getID();
final String hosts = hostName;
try {
ConfigSupport.apply(new SingleConfigCode<HttpService>() {
public Object run(HttpService param) throws PropertyVetoException, TransactionFailure {
com.sun.enterprise.config.serverbeans.VirtualServer newVirtualServer = param.createChild(com.sun.enterprise.config.serverbeans.VirtualServer.class);
newVirtualServer.setId(id);
newVirtualServer.setNetworkListeners(nl);
if (hosts != null) {
newVirtualServer.setHosts(hosts);
}
Property property = newVirtualServer.createChild(Property.class);
property.setName("docroot");
property.setValue(root);
newVirtualServer.getProperty().add(property);
param.getVirtualServer().add(newVirtualServer);
return newVirtualServer;
}
}, httpService);
} catch (Exception ex) {
throw new GlassFishException(ex);
}
if ((webListeners != null) && (!webListeners.isEmpty())) {
for (WebListener listener : webListeners) {
if (getWebListener(listener.getId()) == null) {
addWebListener(listener, virtualServer.getID());
}
}
}
vs = (com.sun.enterprise.web.VirtualServer) engine.findChild(id);
if (vs != null) {
if (log.isLoggable(Level.INFO)) {
log.info("Added virtual server " + id + " docroot " + docRoot + " networklisteners " + nl);
}
if (virtualServer instanceof VirtualServerFacade) {
((VirtualServerFacade) virtualServer).setVirtualServer(vs);
}
vs.setNetworkListenerNames(names.toArray(new String[names.size()]));
} else {
log.severe("Could not add virtual server " + id);
throw new GlassFishException(new Exception("Cannot add virtual server " + id));
}
}
use of org.glassfish.grizzly.config.dom.NetworkListener 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();
}
}
Aggregations