use of org.glassfish.grizzly.config.dom.Protocol 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.grizzly.config.dom.Protocol in project Payara by payara.
the class GetHostAndPortCommand method getHostAndPort.
private HostAndPort getHostAndPort(HttpService httpService, VirtualServer vs, boolean securityEnabled) {
List<VirtualServer> virtualServerList = httpService.getVirtualServer();
List<NetworkListener> httpListenerList = httpService.getParent(Config.class).getNetworkConfig().getNetworkListeners().getNetworkListener();
for (VirtualServer virtualServer : virtualServerList) {
if (!virtualServer.getId().equals(vs.getId())) {
continue;
}
String vsHttpListeners = virtualServer.getNetworkListeners();
if (vsHttpListeners == null) {
continue;
}
List<String> vsHttpListenerList = StringUtils.parseStringList(vsHttpListeners, " ,");
for (String vsHttpListener : vsHttpListenerList) {
for (NetworkListener httpListener : httpListenerList) {
if (!httpListener.getName().equals(vsHttpListener)) {
continue;
}
if (!Boolean.valueOf(httpListener.getEnabled())) {
continue;
}
final Protocol protocol = httpListener.findHttpProtocol();
if (Boolean.valueOf(protocol.getSecurityEnabled()) == securityEnabled) {
String serverName = protocol.getHttp().getServerName();
if (serverName == null || serverName.trim().equals("")) {
serverName = DeploymentCommandUtils.getLocalHostName();
}
String portStr = httpListener.getPort();
String redirPort = protocol.getHttp().getRedirectPort();
if (redirPort != null && !redirPort.trim().equals("")) {
portStr = redirPort;
}
int port = Integer.parseInt(portStr);
return new HostAndPort(serverName, port, securityEnabled);
}
}
}
}
return null;
}
use of org.glassfish.grizzly.config.dom.Protocol in project Payara by payara.
the class GetHostAndPortCommand method getHostAndPort.
private HostAndPort getHostAndPort(HttpService httpService, boolean securityEnabled) {
List<NetworkListener> httpListenerList = httpService.getParent(Config.class).getNetworkConfig().getNetworkListeners().getNetworkListener();
for (NetworkListener httpListener : httpListenerList) {
if (!Boolean.valueOf(httpListener.getEnabled())) {
continue;
}
final Protocol protocol = httpListener.findHttpProtocol();
final Http http = protocol.getHttp();
if (http.getDefaultVirtualServer().equals("__asadmin")) {
continue;
}
if (Boolean.valueOf(protocol.getSecurityEnabled()) == securityEnabled) {
String serverName = http.getServerName();
if (serverName == null || serverName.trim().equals("")) {
serverName = DeploymentCommandUtils.getLocalHostName();
}
String portStr = httpListener.getPort();
String redirPort = http.getRedirectPort();
if (redirPort != null && !redirPort.trim().equals("")) {
portStr = redirPort;
}
int port = Integer.parseInt(portStr);
return new HostAndPort(serverName, port, securityEnabled);
}
}
return null;
}
use of org.glassfish.grizzly.config.dom.Protocol in project Payara by payara.
the class GetApplicationLaunchURLsCommand method getURLsForServer.
private List<URL> getURLsForServer(Server server, String appName, String contextRoot, Logger logger) {
List<URL> serverURLs = new ArrayList<URL>();
String virtualServers = server.getApplicationRef(appName).getVirtualServers();
if (virtualServers == null || virtualServers.trim().equals("")) {
return serverURLs;
}
String nodeName = server.getNodeRef();
String host = null;
if (nodeName != null) {
Node node = domain.getNodeNamed(nodeName);
host = node.getNodeHost();
}
if (host == null || host.trim().equals("") || host.trim().equalsIgnoreCase("localhost")) {
host = DeploymentCommandUtils.getLocalHostName();
}
List<String> vsList = StringUtils.parseStringList(virtualServers, " ,");
Config config = domain.getConfigNamed(server.getConfigRef());
HttpService httpService = config.getHttpService();
for (String vsName : vsList) {
VirtualServer vs = httpService.getVirtualServerByName(vsName);
String vsHttpListeners = vs.getNetworkListeners();
if (vsHttpListeners == null || vsHttpListeners.trim().equals("")) {
continue;
}
List<String> vsHttpListenerList = StringUtils.parseStringList(vsHttpListeners, " ,");
List<NetworkListener> httpListenerList = config.getNetworkConfig().getNetworkListeners().getNetworkListener();
for (String vsHttpListener : vsHttpListenerList) {
for (NetworkListener httpListener : httpListenerList) {
if (!httpListener.getName().equals(vsHttpListener)) {
continue;
}
if (!Boolean.valueOf(httpListener.getEnabled())) {
continue;
}
Protocol protocol = httpListener.findHttpProtocol();
// Do not include jk enabled listeners
if (Boolean.valueOf(protocol.getHttp().getJkEnabled())) {
continue;
}
boolean securityEnabled = Boolean.valueOf(protocol.getSecurityEnabled());
String proto = (securityEnabled ? "https" : "http");
String portStr = httpListener.getPort();
String redirPort = protocol.getHttp().getRedirectPort();
if (redirPort != null && !redirPort.trim().equals("")) {
portStr = redirPort;
}
// we need to resolve port for non-DAS instances
if (!DeploymentUtils.isDASTarget(server.getName())) {
PropertyResolver resolver = new PropertyResolver(domain, server.getName());
portStr = resolver.getPropertyValue(portStr);
}
try {
int port = Integer.parseInt(portStr);
URL url = new URL(proto, host, port, contextRoot);
serverURLs.add(url);
} catch (Exception ee) {
logger.log(Level.WARNING, ee.getMessage(), ee);
}
}
}
}
return serverURLs;
}
use of org.glassfish.grizzly.config.dom.Protocol in project Payara by payara.
the class WebSslConfigHandler method create.
@Override
public void create(final CreateSsl command, ActionReport report) {
NetworkConfig netConfig = command.config.getNetworkConfig();
// ensure we have the specified listener
NetworkListener listener = netConfig.getNetworkListener(command.listenerId);
Protocol httpProtocol;
try {
if (listener == null) {
report.setMessage(MessageFormat.format(rb.getString(LogFacade.CREATE_SSL_HTTP_NOT_FOUND), command.listenerId));
httpProtocol = command.findOrCreateProtocol(command.listenerId);
} else {
httpProtocol = listener.findHttpProtocol();
Ssl ssl = httpProtocol.getSsl();
if (ssl != null) {
report.setMessage(MessageFormat.format(rb.getString(LogFacade.CREATE_SSL_HTTP_ALREADY_EXISTS), command.listenerId));
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
return;
}
}
ConfigSupport.apply(new SingleConfigCode<Protocol>() {
public Object run(Protocol param) throws TransactionFailure {
Ssl newSsl = param.createChild(Ssl.class);
command.populateSslElement(newSsl);
param.setSsl(newSsl);
return newSsl;
}
}, httpProtocol);
} catch (TransactionFailure e) {
command.reportError(report, e);
}
command.reportSuccess(report);
}
Aggregations