Search in sources :

Example 6 with Protocol

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

the class WebSslConfigHandler method delete.

@Override
public void delete(DeleteSsl command, ActionReport report) {
    NetworkConfig netConfig = command.config.getNetworkConfig();
    NetworkListener networkListener = netConfig.getNetworkListener(command.listenerId);
    if (networkListener == null) {
        report.setMessage(MessageFormat.format(rb.getString(LogFacade.DELETE_SSL_HTTP_LISTENER_NOT_FOUND), command.listenerId));
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        return;
    }
    Protocol protocol = networkListener.findHttpProtocol();
    if (protocol.getSsl() == null) {
        report.setMessage(MessageFormat.format(rb.getString(LogFacade.DELETE_SSL_ELEMENT_DOES_NOT_EXIST), command.listenerId));
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        return;
    }
    try {
        ConfigSupport.apply(new SingleConfigCode<Protocol>() {

            public Object run(Protocol param) {
                param.setSsl(null);
                return null;
            }
        }, networkListener.findHttpProtocol());
    } catch (TransactionFailure e) {
        command.reportError(report, e);
    }
}
Also used : TransactionFailure(org.jvnet.hk2.config.TransactionFailure) NetworkConfig(org.glassfish.grizzly.config.dom.NetworkConfig) Protocol(org.glassfish.grizzly.config.dom.Protocol) NetworkListener(org.glassfish.grizzly.config.dom.NetworkListener)

Example 7 with Protocol

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

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

the class ProtocolSslConfigHandler method delete.

@Override
public void delete(final DeleteSsl command, final ActionReport report) {
    try {
        NetworkConfig networkConfig = command.config.getNetworkConfig();
        final Protocol protocol = networkConfig.findProtocol(command.listenerId);
        if (protocol != null) {
            ConfigSupport.apply(new SingleConfigCode<Protocol>() {

                @Override
                public Object run(Protocol param) {
                    param.setSecurityEnabled("false");
                    param.setSsl(null);
                    return null;
                }
            }, protocol);
        }
    } catch (TransactionFailure transactionFailure) {
        command.reportError(report, transactionFailure);
    }
}
Also used : TransactionFailure(org.jvnet.hk2.config.TransactionFailure) NetworkConfig(org.glassfish.grizzly.config.dom.NetworkConfig) Protocol(org.glassfish.grizzly.config.dom.Protocol)

Example 9 with Protocol

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

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

the class GlassfishNetworkListener method configureHttpProtocol.

@Override
protected void configureHttpProtocol(final ServiceLocator habitat, final NetworkListener networkListener, final Http http, final FilterChainBuilder filterChainBuilder, boolean securityEnabled) {
    if (httpAdapter == null) {
        registerMonitoringStatsProviders();
        final V3Mapper mapper = new V3Mapper(logger);
        mapper.setPort(port);
        mapper.setId(name);
        final ContainerMapper containerMapper = new ContainerMapper(grizzlyService, this);
        containerMapper.setMapper(mapper);
        containerMapper.setDefaultHost(http.getDefaultVirtualServer());
        containerMapper.setRequestURIEncoding(http.getUriEncoding());
        containerMapper.configureMapper();
        VirtualServer vs = null;
        String webAppRootPath = null;
        final Collection<VirtualServer> list = grizzlyService.getHabitat().getAllServices(VirtualServer.class);
        final String vsName = http.getDefaultVirtualServer();
        for (final VirtualServer virtualServer : list) {
            if (virtualServer.getId().equals(vsName)) {
                vs = virtualServer;
                webAppRootPath = vs.getDocroot();
                if (!grizzlyService.hasMapperUpdateListener() && vs.getProperty() != null && !vs.getProperty().isEmpty()) {
                    for (final Property p : vs.getProperty()) {
                        final String propertyName = p.getName();
                        if (propertyName.startsWith("alternatedocroot")) {
                            String value = p.getValue();
                            String[] mapping = value.split(" ");
                            if (mapping.length != 2) {
                                logger.log(Level.WARNING, "Invalid alternate_docroot {0}", value);
                                continue;
                            }
                            String docBase = mapping[1].substring("dir=".length());
                            String urlPattern = mapping[0].substring("from=".length());
                            containerMapper.addAlternateDocBase(urlPattern, docBase);
                        }
                    }
                }
                break;
            }
        }
        httpAdapter = new HttpAdapterImpl(vs, containerMapper, webAppRootPath);
        containerMapper.addDocRoot(webAppRootPath);
        AbstractActiveDescriptor<V3Mapper> aad = BuilderHelper.createConstantDescriptor(mapper);
        aad.addContractType(Mapper.class);
        aad.setName(address.toString() + port);
        ServiceLocatorUtilities.addOneDescriptor(grizzlyService.getHabitat(), aad);
        super.configureHttpProtocol(habitat, networkListener, http, filterChainBuilder, securityEnabled);
        final Protocol protocol = http.getParent();
        for (NetworkListener listener : protocol.findNetworkListeners()) {
            grizzlyService.notifyMapperUpdateListeners(listener, mapper);
        }
    } else {
        super.configureHttpProtocol(habitat, networkListener, http, filterChainBuilder, securityEnabled);
    }
}
Also used : Protocol(org.glassfish.grizzly.config.dom.Protocol) V3Mapper(org.glassfish.internal.grizzly.V3Mapper) Property(org.jvnet.hk2.config.types.Property) VirtualServer(com.sun.enterprise.config.serverbeans.VirtualServer) 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