Search in sources :

Example 1 with PortUnification

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

the class CreateProtocolFinder method execute.

@Override
public void execute(AdminCommandContext context) {
    Target targetUtil = services.getService(Target.class);
    Config newConfig = targetUtil.getConfig(target);
    if (newConfig != null) {
        config = newConfig;
    }
    report = context.getActionReport();
    final Protocols protocols = config.getNetworkConfig().getProtocols();
    final Protocol protocol = protocols.findProtocol(protocolName);
    final Protocol target = protocols.findProtocol(targetName);
    try {
        validate(protocol, LogFacade.CREATE_HTTP_FAIL_PROTOCOL_NOT_FOUND, protocolName);
        validate(target, LogFacade.CREATE_HTTP_FAIL_PROTOCOL_NOT_FOUND, targetName);
        final Class<?> finderClass = Thread.currentThread().getContextClassLoader().loadClass(classname);
        if (!org.glassfish.grizzly.portunif.ProtocolFinder.class.isAssignableFrom(finderClass)) {
            report.setMessage(MessageFormat.format(rb.getString(LogFacade.CREATE_PORTUNIF_FAIL_NOTFINDER), name, classname));
            report.setActionExitCode(ActionReport.ExitCode.FAILURE);
            return;
        }
        PortUnification unif = (PortUnification) ConfigSupport.apply(new SingleConfigCode<Protocol>() {

            @Override
            public Object run(Protocol param) throws PropertyVetoException, TransactionFailure {
                PortUnification pu = param.getPortUnification();
                if (pu == null) {
                    pu = param.createChild(PortUnification.class);
                    param.setPortUnification(pu);
                }
                return pu;
            }
        }, protocol);
        ConfigSupport.apply(new SingleConfigCode<PortUnification>() {

            @Override
            public Object run(PortUnification param) throws PropertyVetoException, TransactionFailure {
                final List<ProtocolFinder> list = param.getProtocolFinder();
                for (ProtocolFinder finder : list) {
                    if (name.equals(finder.getName())) {
                        throw new TransactionFailure(String.format("A protocol finder named %s already exists.", name));
                    }
                }
                final ProtocolFinder finder = param.createChild(ProtocolFinder.class);
                finder.setName(name);
                finder.setProtocol(targetName);
                finder.setClassname(classname);
                list.add(finder);
                return null;
            }
        }, unif);
    } catch (ValidationFailureException e) {
        return;
    } catch (Exception e) {
        e.printStackTrace();
        report.setMessage(MessageFormat.format(rb.getString(LogFacade.CREATE_PORTUNIF_FAIL), name, e.getMessage() == null ? "No reason given" : e.getMessage()));
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        report.setFailureCause(e);
        return;
    }
}
Also used : TransactionFailure(org.jvnet.hk2.config.TransactionFailure) Protocols(org.glassfish.grizzly.config.dom.Protocols) PortUnification(org.glassfish.grizzly.config.dom.PortUnification) SingleConfigCode(org.jvnet.hk2.config.SingleConfigCode) Config(com.sun.enterprise.config.serverbeans.Config) ProtocolFinder(org.glassfish.grizzly.config.dom.ProtocolFinder) PropertyVetoException(java.beans.PropertyVetoException) PropertyVetoException(java.beans.PropertyVetoException) Target(org.glassfish.internal.api.Target) CommandTarget(org.glassfish.config.support.CommandTarget) List(java.util.List) Protocol(org.glassfish.grizzly.config.dom.Protocol)

Example 2 with PortUnification

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

the class ListProtocolFinders method execute.

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();
    Protocol protocol = config.getNetworkConfig().getProtocols().findProtocol(protocolName);
    if (protocol != null) {
        final PortUnification pu = protocol.getPortUnification();
        if (pu != null) {
            for (ProtocolFinder finder : pu.getProtocolFinder()) {
                report.getTopMessagePart().addChild().setMessage(finder.getName());
            }
        }
    }
    report.setActionExitCode(ActionReport.ExitCode.SUCCESS);
}
Also used : Target(org.glassfish.internal.api.Target) CommandTarget(org.glassfish.config.support.CommandTarget) PortUnification(org.glassfish.grizzly.config.dom.PortUnification) Config(com.sun.enterprise.config.serverbeans.Config) ActionReport(org.glassfish.api.ActionReport) Protocol(org.glassfish.grizzly.config.dom.Protocol) ProtocolFinder(org.glassfish.grizzly.config.dom.ProtocolFinder)

Example 3 with PortUnification

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

the class DeleteProtocolFinder method getPortUnification.

private PortUnification getPortUnification(Protocol protocol) {
    PortUnification pu = protocol.getPortUnification();
    if ((pu == null) && (report != null)) {
        report.setMessage(MessageFormat.format(rb.getString(LogFacade.NOT_FOUND), "port-unification", protocol.getName()));
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
    }
    return pu;
}
Also used : PortUnification(org.glassfish.grizzly.config.dom.PortUnification)

Example 4 with PortUnification

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

the class DeleteProtocolFinder method execute.

@Override
public void execute(AdminCommandContext context) {
    Target targetUtil = services.getService(Target.class);
    Config newConfig = targetUtil.getConfig(target);
    if (newConfig != null) {
        config = newConfig;
    }
    report = context.getActionReport();
    try {
        final Protocols protocols = config.getNetworkConfig().getProtocols();
        final Protocol protocol = protocols.findProtocol(protocolName);
        validate(protocol, LogFacade.CREATE_HTTP_FAIL_PROTOCOL_NOT_FOUND, protocolName);
        PortUnification pu = getPortUnification(protocol);
        ConfigSupport.apply(new ConfigCode() {

            @Override
            public Object run(ConfigBeanProxy... params) {
                final Protocol prot = (Protocol) params[0];
                final PortUnification portUnification = (PortUnification) params[1];
                final List<ProtocolFinder> oldList = portUnification.getProtocolFinder();
                List<ProtocolFinder> newList = new ArrayList<ProtocolFinder>();
                for (final ProtocolFinder finder : oldList) {
                    if (!name.equals(finder.getName())) {
                        newList.add(finder);
                    }
                }
                if (oldList.size() == newList.size()) {
                    throw new RuntimeException(String.format("No finder named %s found for protocol %s", name, protocolName));
                }
                if (newList.isEmpty()) {
                    prot.setPortUnification(null);
                } else {
                    portUnification.setProtocolFinder(newList);
                }
                return null;
            }
        }, protocol, pu);
        cleanPortUnification(pu);
    } catch (ValidationFailureException e) {
        return;
    } catch (Exception e) {
        e.printStackTrace();
        report.setMessage(MessageFormat.format(rb.getString(LogFacade.DELETE_FAIL), name, e.getMessage() == null ? "No reason given" : e.getMessage()));
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        report.setFailureCause(e);
        return;
    }
}
Also used : Protocols(org.glassfish.grizzly.config.dom.Protocols) PortUnification(org.glassfish.grizzly.config.dom.PortUnification) Config(com.sun.enterprise.config.serverbeans.Config) ProtocolFinder(org.glassfish.grizzly.config.dom.ProtocolFinder) Target(org.glassfish.internal.api.Target) CommandTarget(org.glassfish.config.support.CommandTarget) ConfigBeanProxy(org.jvnet.hk2.config.ConfigBeanProxy) SingleConfigCode(org.jvnet.hk2.config.SingleConfigCode) ConfigCode(org.jvnet.hk2.config.ConfigCode) ArrayList(java.util.ArrayList) List(java.util.List) Protocol(org.glassfish.grizzly.config.dom.Protocol)

Example 5 with PortUnification

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

PortUnification (org.glassfish.grizzly.config.dom.PortUnification)5 Protocol (org.glassfish.grizzly.config.dom.Protocol)4 Config (com.sun.enterprise.config.serverbeans.Config)3 List (java.util.List)3 CommandTarget (org.glassfish.config.support.CommandTarget)3 ProtocolFinder (org.glassfish.grizzly.config.dom.ProtocolFinder)3 Target (org.glassfish.internal.api.Target)3 ArrayList (java.util.ArrayList)2 Protocols (org.glassfish.grizzly.config.dom.Protocols)2 SingleConfigCode (org.jvnet.hk2.config.SingleConfigCode)2 PropertyVetoException (java.beans.PropertyVetoException)1 IOException (java.io.IOException)1 ActionReport (org.glassfish.api.ActionReport)1 Http (org.glassfish.grizzly.config.dom.Http)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