Search in sources :

Example 1 with ProtocolFinder

use of org.glassfish.grizzly.portunif.ProtocolFinder in project Payara by payara.

the class GenericGrizzlyListener method configureSubProtocol.

protected void configureSubProtocol(final ServiceLocator habitat, final NetworkListener networkListener, final Protocol protocol, final FilterChainBuilder filterChainBuilder) {
    if (protocol.getHttp() != null) {
        final Http http = protocol.getHttp();
        configureHttpProtocol(habitat, networkListener, http, filterChainBuilder, Boolean.valueOf(protocol.getSecurityEnabled()));
    } else if (protocol.getPortUnification() != null) {
        // Port unification
        final PortUnification pu = protocol.getPortUnification();
        final String puFilterClassname = pu.getClassname();
        PUFilter puFilter = null;
        if (puFilterClassname != null) {
            try {
                puFilter = Utils.newInstance(habitat, PUFilter.class, puFilterClassname, puFilterClassname);
                configureElement(habitat, networkListener, pu, puFilter);
            } catch (Exception e) {
                LOGGER.log(Level.WARNING, "Can not initialize port unification filter: " + puFilterClassname + " default filter will be used instead", e);
            }
        }
        if (puFilter == null) {
            puFilter = new PUFilter();
        }
        List<org.glassfish.grizzly.config.dom.ProtocolFinder> findersConfig = pu.getProtocolFinder();
        for (org.glassfish.grizzly.config.dom.ProtocolFinder finderConfig : findersConfig) {
            final String finderClassname = finderConfig.getClassname();
            try {
                final ProtocolFinder protocolFinder = Utils.newInstance(habitat, ProtocolFinder.class, finderClassname, finderClassname);
                configureElement(habitat, networkListener, finderConfig, protocolFinder);
                final Protocol subProtocol = finderConfig.findProtocol();
                if (subProtocol.getHttp() != null) {
                    if (LOGGER.isLoggable(WARNING)) {
                        LOGGER.log(WARNING, "HTTP/2 (enabled by default) is unsupported with port " + "unification and will be disabled for network listener {0}.", networkListener.getName());
                    }
                    skipHttp2 = true;
                }
                final FilterChainBuilder subProtocolFilterChainBuilder = puFilter.getPUFilterChainBuilder();
                // If subprotocol is secured - we need to wrap it under SSLProtocolFinder
                if (Boolean.valueOf(subProtocol.getSecurityEnabled())) {
                    final PUFilter extraSslPUFilter = new PUFilter();
                    final Filter addedSSLFilter = configureSsl(habitat, getSsl(subProtocol), subProtocolFilterChainBuilder);
                    subProtocolFilterChainBuilder.add(extraSslPUFilter);
                    final FilterChainBuilder extraSslPUFilterChainBuilder = extraSslPUFilter.getPUFilterChainBuilder();
                    try {
                        // temporary add SSL Filter, so subprotocol
                        // will see it
                        extraSslPUFilterChainBuilder.add(addedSSLFilter);
                        configureSubProtocol(habitat, networkListener, subProtocol, extraSslPUFilterChainBuilder);
                    } finally {
                        // remove SSL Filter
                        extraSslPUFilterChainBuilder.remove(addedSSLFilter);
                    }
                    extraSslPUFilter.register(protocolFinder, extraSslPUFilterChainBuilder.build());
                    puFilter.register(new SSLProtocolFinder(new SSLConfigurator(habitat, subProtocol.getSsl())), subProtocolFilterChainBuilder.build());
                } else {
                    configureSubProtocol(habitat, networkListener, subProtocol, subProtocolFilterChainBuilder);
                    puFilter.register(protocolFinder, subProtocolFilterChainBuilder.build());
                }
            } catch (Exception e) {
                LOGGER.log(Level.WARNING, "Can not initialize sub protocol. Finder: " + finderClassname, e);
            }
        }
        filterChainBuilder.add(puFilter);
    } else if (protocol.getHttpRedirect() != null) {
        filterChainBuilder.add(createHttpServerCodecFilter());
        final HttpRedirectFilter filter = new HttpRedirectFilter();
        filter.configure(habitat, networkListener, protocol.getHttpRedirect());
        filterChainBuilder.add(filter);
    } else {
        ProtocolChainInstanceHandler pcihConfig = protocol.getProtocolChainInstanceHandler();
        if (pcihConfig == null) {
            LOGGER.log(Level.WARNING, "Empty protocol declaration");
            return;
        }
        ProtocolChain filterChainConfig = pcihConfig.getProtocolChain();
        for (ProtocolFilter filterConfig : filterChainConfig.getProtocolFilter()) {
            final String filterClassname = filterConfig.getClassname();
            try {
                final Filter filter = loadFilter(habitat, filterConfig.getName(), filterClassname);
                configureElement(habitat, networkListener, filterConfig, filter);
                filterChainBuilder.add(filter);
            } catch (Exception e) {
                LOGGER.log(Level.WARNING, "Can not initialize protocol filter: " + filterClassname, e);
                throw new IllegalStateException("Can not initialize protocol filter: " + filterClassname);
            }
        }
    }
}
Also used : PUFilter(org.glassfish.grizzly.portunif.PUFilter) PortUnification(org.glassfish.grizzly.config.dom.PortUnification) Http(org.glassfish.grizzly.config.dom.Http) IOException(java.io.IOException) SSLProtocolFinder(org.glassfish.grizzly.portunif.finders.SSLProtocolFinder) ProtocolFinder(org.glassfish.grizzly.portunif.ProtocolFinder) HttpRedirectFilter(org.glassfish.grizzly.config.portunif.HttpRedirectFilter) PUFilter(org.glassfish.grizzly.portunif.PUFilter) Filter(org.glassfish.grizzly.filterchain.Filter) TransportFilter(org.glassfish.grizzly.filterchain.TransportFilter) IdleTimeoutFilter(org.glassfish.grizzly.utils.IdleTimeoutFilter) HttpServerFilter(org.glassfish.grizzly.http.server.HttpServerFilter) CompressionEncodingFilter(org.glassfish.grizzly.http.server.CompressionEncodingFilter) HttpRedirectFilter(org.glassfish.grizzly.config.portunif.HttpRedirectFilter) FileCacheFilter(org.glassfish.grizzly.http.server.FileCacheFilter) SSLBaseFilter(org.glassfish.grizzly.ssl.SSLBaseFilter) ProtocolFilter(org.glassfish.grizzly.config.dom.ProtocolFilter) ProtocolChainInstanceHandler(org.glassfish.grizzly.config.dom.ProtocolChainInstanceHandler) ProtocolChain(org.glassfish.grizzly.config.dom.ProtocolChain) List(java.util.List) ArrayList(java.util.ArrayList) FilterChainBuilder(org.glassfish.grizzly.filterchain.FilterChainBuilder) SSLProtocolFinder(org.glassfish.grizzly.portunif.finders.SSLProtocolFinder) Protocol(org.glassfish.grizzly.config.dom.Protocol) PUProtocol(org.glassfish.grizzly.portunif.PUProtocol) ProtocolFilter(org.glassfish.grizzly.config.dom.ProtocolFilter)

Aggregations

IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Http (org.glassfish.grizzly.config.dom.Http)1 PortUnification (org.glassfish.grizzly.config.dom.PortUnification)1 Protocol (org.glassfish.grizzly.config.dom.Protocol)1 ProtocolChain (org.glassfish.grizzly.config.dom.ProtocolChain)1 ProtocolChainInstanceHandler (org.glassfish.grizzly.config.dom.ProtocolChainInstanceHandler)1 ProtocolFilter (org.glassfish.grizzly.config.dom.ProtocolFilter)1 HttpRedirectFilter (org.glassfish.grizzly.config.portunif.HttpRedirectFilter)1 Filter (org.glassfish.grizzly.filterchain.Filter)1 FilterChainBuilder (org.glassfish.grizzly.filterchain.FilterChainBuilder)1 TransportFilter (org.glassfish.grizzly.filterchain.TransportFilter)1 CompressionEncodingFilter (org.glassfish.grizzly.http.server.CompressionEncodingFilter)1 FileCacheFilter (org.glassfish.grizzly.http.server.FileCacheFilter)1 HttpServerFilter (org.glassfish.grizzly.http.server.HttpServerFilter)1 PUFilter (org.glassfish.grizzly.portunif.PUFilter)1 PUProtocol (org.glassfish.grizzly.portunif.PUProtocol)1 ProtocolFinder (org.glassfish.grizzly.portunif.ProtocolFinder)1 SSLProtocolFinder (org.glassfish.grizzly.portunif.finders.SSLProtocolFinder)1