Search in sources :

Example 1 with Http

use of org.glassfish.grizzly.config.dom.Http 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 Http

use of org.glassfish.grizzly.config.dom.Http 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 3 with Http

use of org.glassfish.grizzly.config.dom.Http in project Payara by payara.

the class HttpServiceTest method validTransaction.

@Test
public void validTransaction() throws TransactionFailure {
    final String max = listener.findHttpProtocol().getHttp().getMaxConnections();
    ConfigSupport.apply(new SingleConfigCode<NetworkListener>() {

        public Object run(NetworkListener okToChange) throws TransactionFailure {
            final Http http = okToChange.createChild(Http.class);
            http.setMaxConnections("100");
            http.setTimeoutSeconds("65");
            http.setFileCache(http.createChild(FileCache.class));
            ConfigSupport.apply(new SingleConfigCode<Protocol>() {

                @Override
                public Object run(Protocol param) {
                    param.setHttp(http);
                    return null;
                }
            }, okToChange.findHttpProtocol());
            return http;
        }
    }, listener);
    ConfigSupport.apply(new SingleConfigCode<Http>() {

        @Override
        public Object run(Http param) {
            param.setMaxConnections(max);
            return null;
        }
    }, listener.findHttpProtocol().getHttp());
    try {
        ConfigSupport.apply(new SingleConfigCode<Http>() {

            public Object run(Http param) throws TransactionFailure {
                param.setMaxConnections("7");
                throw new TransactionFailure("Sorry, changed my mind", null);
            }
        }, listener.findHttpProtocol().getHttp());
    } catch (TransactionFailure e) {
        logger.fine("good, got my exception about changing my mind");
    }
}
Also used : TransactionFailure(org.jvnet.hk2.config.TransactionFailure) SingleConfigCode(org.jvnet.hk2.config.SingleConfigCode) Http(org.glassfish.grizzly.config.dom.Http) Protocol(org.glassfish.grizzly.config.dom.Protocol) NetworkListener(org.glassfish.grizzly.config.dom.NetworkListener) Test(org.junit.Test)

Example 4 with Http

use of org.glassfish.grizzly.config.dom.Http in project Payara by payara.

the class DynamicConfigListener method changed.

@Override
public synchronized UnprocessedChangeEvents changed(final PropertyChangeEvent[] events) {
    return ConfigSupport.sortAndDispatch(events, new Changed() {

        @Override
        public <T extends ConfigBeanProxy> NotProcessed changed(TYPE type, Class<T> tClass, T t) {
            if (logger.isLoggable(Level.FINE)) {
                logger.log(Level.FINE, "NetworkConfig changed {0} {1} {2}", new Object[] { type, tClass, t });
            }
            if (tClass == NetworkListener.class && t instanceof NetworkListener) {
                return processNetworkListener(type, (NetworkListener) t, events);
            } else if (tClass == Http.class && t instanceof Http) {
                return processProtocol(type, (Protocol) t.getParent(), events);
            } else if (tClass == FileCache.class && t instanceof FileCache) {
                return processProtocol(type, (Protocol) t.getParent().getParent(), null);
            } else if (tClass == Ssl.class && t instanceof Ssl) {
                /*
                         * Make sure the SSL parent is in fact a protocol.  It could
                         * be a jmx-connector.
                     */
                final ConfigBeanProxy parent = t.getParent();
                if (parent instanceof Protocol) {
                    return processProtocol(type, (Protocol) parent, null);
                }
            } else if (tClass == Protocol.class && t instanceof Protocol) {
                return processProtocol(type, (Protocol) t, null);
            } else if (tClass == ThreadPool.class && t instanceof ThreadPool) {
                NotProcessed notProcessed = null;
                ThreadPool threadPool = (ThreadPool) t;
                for (NetworkListener listener : threadPool.findNetworkListeners()) {
                    notProcessed = processNetworkListener(type, listener, null);
                }
                // Throw an unprocessed event change if one hasn't already if HTTP or ThreadPool monitoring is enabled.
                MonitoringService ms = config.getMonitoringService();
                String threadPoolLevel = ms.getModuleMonitoringLevels().getThreadPool();
                String httpServiceLevel = ms.getModuleMonitoringLevels().getHttpService();
                if (((threadPoolLevel != null && !threadPoolLevel.equals(OFF)) || (httpServiceLevel != null && !httpServiceLevel.equals(OFF))) && notProcessed == null) {
                    notProcessed = new NotProcessed("Monitoring statistics will be incorrect for " + threadPool.getName() + " until restart due to changed attribute(s).");
                }
                return notProcessed;
            } else if (tClass == Transport.class && t instanceof Transport) {
                NotProcessed notProcessed = null;
                for (NetworkListener listener : ((Transport) t).findNetworkListeners()) {
                    notProcessed = processNetworkListener(type, listener, null);
                }
                return notProcessed;
            } else if (tClass == VirtualServer.class && t instanceof VirtualServer && !grizzlyService.hasMapperUpdateListener()) {
                return processVirtualServer(type, (VirtualServer) t);
            } else if (tClass == SystemProperty.class && t instanceof SystemProperty) {
                NetworkConfig networkConfig = config.getNetworkConfig();
                if ((networkConfig != null) && ((SystemProperty) t).getName().endsWith("LISTENER_PORT")) {
                    for (NetworkListener listener : networkConfig.getNetworkListeners().getNetworkListener()) {
                        if (listener.getPort().equals(((SystemProperty) t).getValue())) {
                            return processNetworkListener(Changed.TYPE.CHANGE, listener, events);
                        }
                    }
                }
                return null;
            }
            return null;
        }
    }, logger);
}
Also used : ThreadPool(org.glassfish.grizzly.config.dom.ThreadPool) NetworkConfig(org.glassfish.grizzly.config.dom.NetworkConfig) Http(org.glassfish.grizzly.config.dom.Http) Ssl(org.glassfish.grizzly.config.dom.Ssl) SystemProperty(com.sun.enterprise.config.serverbeans.SystemProperty) VirtualServer(com.sun.enterprise.config.serverbeans.VirtualServer) FileCache(org.glassfish.grizzly.config.dom.FileCache) ConfigBeanProxy(org.jvnet.hk2.config.ConfigBeanProxy) Changed(org.jvnet.hk2.config.Changed) NotProcessed(org.jvnet.hk2.config.NotProcessed) Protocol(org.glassfish.grizzly.config.dom.Protocol) Transport(org.glassfish.grizzly.config.dom.Transport) MonitoringService(com.sun.enterprise.config.serverbeans.MonitoringService) NetworkListener(org.glassfish.grizzly.config.dom.NetworkListener)

Example 5 with Http

use of org.glassfish.grizzly.config.dom.Http in project Payara by payara.

the class CreateHttp method execute.

/**
 * Executes the command with the command parameters passed as Properties
 * where the keys are the parameter names and the values the parameter
 * values.
 *
 * @param context information
 */
public void execute(AdminCommandContext context) {
    Target targetUtil = services.getService(Target.class);
    Config newConfig = targetUtil.getConfig(target);
    if (newConfig != null) {
        config = newConfig;
    }
    final ActionReport report = context.getActionReport();
    // check for duplicates
    Protocols protocols = config.getNetworkConfig().getProtocols();
    Protocol protocol = null;
    for (Protocol p : protocols.getProtocol()) {
        if (protocolName.equals(p.getName())) {
            protocol = p;
        }
    }
    if (protocol == null) {
        report.setMessage(MessageFormat.format(rb.getString(LogFacade.CREATE_HTTP_FAIL_PROTOCOL_NOT_FOUND), protocolName));
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        return;
    }
    if (protocol.getHttp() != null) {
        report.setMessage(MessageFormat.format(rb.getString(LogFacade.CREATE_HTTP_FAIL_DUPLICATE), protocolName));
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        return;
    }
    // Add to the <network-config>
    try {
        ConfigSupport.apply(new SingleConfigCode<Protocol>() {

            public Object run(Protocol param) throws TransactionFailure {
                Http http = param.createChild(Http.class);
                final FileCache cache = http.createChild(FileCache.class);
                cache.setEnabled("false");
                http.setFileCache(cache);
                http.setDefaultVirtualServer(defaultVirtualServer);
                http.setDnsLookupEnabled(dnsLookupEnabled == null ? null : dnsLookupEnabled.toString());
                http.setMaxConnections(maxConnections);
                http.setRequestTimeoutSeconds(requestTimeoutSeconds);
                http.setTimeoutSeconds(timeoutSeconds);
                http.setXpoweredBy(xPoweredBy == null ? null : xPoweredBy.toString());
                http.setServerHeader(serverHeader == null ? null : serverHeader.toString());
                http.setXframeOptions(xFrameOptions == null ? null : xFrameOptions.toString());
                http.setServerName(serverName);
                // HTTP2 options
                http.setHttp2Enabled(http2Enabled.toString());
                if (http2MaxConcurrentStreams != null) {
                    http.setHttp2MaxConcurrentStreams(http2MaxConcurrentStreams.toString());
                }
                if (http2InitialWindowSizeInBytes != null) {
                    http.setHttp2InitialWindowSizeInBytes(http2InitialWindowSizeInBytes.toString());
                }
                if (http2MaxFramePayloadSizeInBytes != null) {
                    http.setHttp2MaxFramePayloadSizeInBytes(http2MaxFramePayloadSizeInBytes.toString());
                }
                if (http2MaxHeaderListSizeInBytes != null) {
                    http.setHttp2MaxHeaderListSizeInBytes(http2MaxHeaderListSizeInBytes.toString());
                }
                if (http2StreamsHighWaterMark != null) {
                    http.setHttp2StreamsHighWaterMark(http2StreamsHighWaterMark.toString());
                }
                if (http2CleanPercentage != null) {
                    http.setHttp2CleanPercentage(http2CleanPercentage.toString());
                }
                if (http2CleanFrequencyCheck != null) {
                    http.setHttp2CleanFrequencyCheck(http2CleanFrequencyCheck.toString());
                }
                if (http2DisableCipherCheck != null) {
                    http.setHttp2DisableCipherCheck(http2DisableCipherCheck.toString());
                }
                if (http2PushEnabled != null) {
                    http.setHttp2PushEnabled(http2PushEnabled.toString());
                }
                param.setHttp(http);
                return http;
            }
        }, protocol);
    } catch (TransactionFailure e) {
        report.setMessage(MessageFormat.format(rb.getString(LogFacade.CREATE_HTTP_REDIRECT_FAIL), protocolName, e.getMessage() == null ? "No reason given." : e.getMessage()));
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        report.setFailureCause(e);
        return;
    }
    report.setActionExitCode(ActionReport.ExitCode.SUCCESS);
}
Also used : TransactionFailure(org.jvnet.hk2.config.TransactionFailure) Target(org.glassfish.internal.api.Target) CommandTarget(org.glassfish.config.support.CommandTarget) Protocols(org.glassfish.grizzly.config.dom.Protocols) Config(com.sun.enterprise.config.serverbeans.Config) Http(org.glassfish.grizzly.config.dom.Http) ActionReport(org.glassfish.api.ActionReport) Protocol(org.glassfish.grizzly.config.dom.Protocol) FileCache(org.glassfish.grizzly.config.dom.FileCache)

Aggregations

Http (org.glassfish.grizzly.config.dom.Http)11 Protocol (org.glassfish.grizzly.config.dom.Protocol)9 NetworkListener (org.glassfish.grizzly.config.dom.NetworkListener)7 Protocols (org.glassfish.grizzly.config.dom.Protocols)4 TransactionFailure (org.jvnet.hk2.config.TransactionFailure)4 Config (com.sun.enterprise.config.serverbeans.Config)3 NetworkConfig (org.glassfish.grizzly.config.dom.NetworkConfig)3 List (java.util.List)2 FileCache (org.glassfish.grizzly.config.dom.FileCache)2 Ssl (org.glassfish.grizzly.config.dom.Ssl)2 ThreadPool (org.glassfish.grizzly.config.dom.ThreadPool)2 Transport (org.glassfish.grizzly.config.dom.Transport)2 Test (org.junit.Test)2 HttpService (com.sun.enterprise.config.serverbeans.HttpService)1 JavaConfig (com.sun.enterprise.config.serverbeans.JavaConfig)1 MonitoringService (com.sun.enterprise.config.serverbeans.MonitoringService)1 SystemProperty (com.sun.enterprise.config.serverbeans.SystemProperty)1 VirtualServer (com.sun.enterprise.config.serverbeans.VirtualServer)1 HostAndPort (com.sun.enterprise.util.HostAndPort)1 PropertyChangeEvent (java.beans.PropertyChangeEvent)1