Search in sources :

Example 1 with Protocol

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();
    }
}
Also used : Protocols(org.glassfish.grizzly.config.dom.Protocols) ThreadPool(org.glassfish.grizzly.config.dom.ThreadPool) Http(org.glassfish.grizzly.config.dom.Http) NetworkListeners(org.glassfish.grizzly.config.dom.NetworkListeners) HttpListener(org.glassfish.embeddable.web.HttpListener) Protocol(org.glassfish.grizzly.config.dom.Protocol) Transports(org.glassfish.grizzly.config.dom.Transports) Ssl(org.glassfish.grizzly.config.dom.Ssl) VirtualServer(org.glassfish.embeddable.web.VirtualServer) PropertyVetoException(java.beans.PropertyVetoException) ConfigException(org.glassfish.embeddable.web.ConfigException) GlassFishException(org.glassfish.embeddable.GlassFishException) PropertyVetoException(java.beans.PropertyVetoException) WebListener(org.glassfish.embeddable.web.WebListener) Transport(org.glassfish.grizzly.config.dom.Transport) org.jvnet.hk2.config(org.jvnet.hk2.config) NetworkListener(org.glassfish.grizzly.config.dom.NetworkListener)

Example 2 with Protocol

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;
}
Also used : HostAndPort(com.sun.enterprise.util.HostAndPort) Config(com.sun.enterprise.config.serverbeans.Config) Protocol(org.glassfish.grizzly.config.dom.Protocol) VirtualServer(com.sun.enterprise.config.serverbeans.VirtualServer) RestEndpoint(org.glassfish.api.admin.RestEndpoint) NetworkListener(org.glassfish.grizzly.config.dom.NetworkListener)

Example 3 with Protocol

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;
}
Also used : HostAndPort(com.sun.enterprise.util.HostAndPort) Config(com.sun.enterprise.config.serverbeans.Config) Http(org.glassfish.grizzly.config.dom.Http) Protocol(org.glassfish.grizzly.config.dom.Protocol) RestEndpoint(org.glassfish.api.admin.RestEndpoint) NetworkListener(org.glassfish.grizzly.config.dom.NetworkListener)

Example 4 with Protocol

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;
}
Also used : ArrayList(java.util.ArrayList) PropertyResolver(org.glassfish.config.support.PropertyResolver) URL(java.net.URL) RestEndpoint(org.glassfish.api.admin.RestEndpoint) Protocol(org.glassfish.grizzly.config.dom.Protocol) NetworkListener(org.glassfish.grizzly.config.dom.NetworkListener)

Example 5 with Protocol

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);
}
Also used : TransactionFailure(org.jvnet.hk2.config.TransactionFailure) NetworkConfig(org.glassfish.grizzly.config.dom.NetworkConfig) Protocol(org.glassfish.grizzly.config.dom.Protocol) CreateSsl(com.sun.enterprise.admin.commands.CreateSsl) DeleteSsl(com.sun.enterprise.admin.commands.DeleteSsl) Ssl(org.glassfish.grizzly.config.dom.Ssl) NetworkListener(org.glassfish.grizzly.config.dom.NetworkListener)

Aggregations

Protocol (org.glassfish.grizzly.config.dom.Protocol)42 Config (com.sun.enterprise.config.serverbeans.Config)22 TransactionFailure (org.jvnet.hk2.config.TransactionFailure)18 NetworkListener (org.glassfish.grizzly.config.dom.NetworkListener)16 CommandTarget (org.glassfish.config.support.CommandTarget)15 Target (org.glassfish.internal.api.Target)15 Protocols (org.glassfish.grizzly.config.dom.Protocols)14 NetworkConfig (org.glassfish.grizzly.config.dom.NetworkConfig)12 ActionReport (org.glassfish.api.ActionReport)11 Http (org.glassfish.grizzly.config.dom.Http)9 PropertyVetoException (java.beans.PropertyVetoException)7 Ssl (org.glassfish.grizzly.config.dom.Ssl)7 List (java.util.List)6 VirtualServer (com.sun.enterprise.config.serverbeans.VirtualServer)5 NetworkListeners (org.glassfish.grizzly.config.dom.NetworkListeners)5 ArrayList (java.util.ArrayList)4 PortUnification (org.glassfish.grizzly.config.dom.PortUnification)4 ProtocolChain (org.glassfish.grizzly.config.dom.ProtocolChain)4 ProtocolFinder (org.glassfish.grizzly.config.dom.ProtocolFinder)4 ConfigBeanProxy (org.jvnet.hk2.config.ConfigBeanProxy)4