Search in sources :

Example 21 with Protocol

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

the class GrizzlyConfigSchemaMigrator method addAsadminProtocol.

private void addAsadminProtocol(NetworkConfig config) throws TransactionFailure {
    ensureAdminThreadPool();
    final Protocols protocols = getProtocols(config);
    Protocol adminProtocol = protocols.findProtocol(ASADMIN_LISTENER);
    if (adminProtocol == null) {
        adminProtocol = (Protocol) ConfigSupport.apply(new SingleConfigCode<Protocols>() {

            @Override
            public Object run(Protocols param) throws TransactionFailure {
                final Protocol protocol = param.createChild(Protocol.class);
                param.getProtocol().add(protocol);
                protocol.setName(ASADMIN_LISTENER);
                Http http = protocol.createChild(Http.class);
                http.setFileCache(http.createChild(FileCache.class));
                protocol.setHttp(http);
                http.setDefaultVirtualServer(ASADMIN_VIRTUAL_SERVER);
                http.setMaxConnections("250");
                return protocol;
            }
        }, protocols);
    }
    for (NetworkListener listener : adminProtocol.findNetworkListeners()) {
        ConfigSupport.apply(new SingleConfigCode<NetworkListener>() {

            @Override
            public Object run(NetworkListener param) {
                param.setThreadPool("admin-thread-pool");
                return null;
            }
        }, listener);
    }
}
Also used : TransactionFailure(org.jvnet.hk2.config.TransactionFailure) Protocols(org.glassfish.grizzly.config.dom.Protocols) Http(org.glassfish.grizzly.config.dom.Http) Protocol(org.glassfish.grizzly.config.dom.Protocol) NetworkListener(org.glassfish.grizzly.config.dom.NetworkListener)

Example 22 with Protocol

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

the class SecureAdminUpgradeHelper method ensureConfigReady.

private boolean ensureConfigReady(final Config c) throws TransactionFailure {
    /*
         * See if this config is already set up for secure admin.
         */
    final NetworkConfig nc = c.getNetworkConfig();
    if (nc == null) {
        /*
             * If there is no network config for this configuration then it is
             * probably a test configuration of some sort.  In any case, there
             * is no lower-level network protocols to verify so declare this
             * config to be OK.
             */
        return true;
    }
    Protocol secAdminProtocol = nc.getProtocols().findProtocol(SecureAdminCommand.SEC_ADMIN_LISTENER_PROTOCOL_NAME);
    if (secAdminProtocol != null) {
        return true;
    }
    final EnableSecureAdminCommand enableCmd = new EnableSecureAdminCommand();
    final Config c_w = transaction().enroll(c);
    ConfigLevelContext configLevelContext = new ConfigLevelContext(topLevelContext(), c_w);
    for (Iterator<Work<ConfigLevelContext>> it = enableCmd.perConfigSteps(); it.hasNext(); ) {
        final Work<ConfigLevelContext> step = it.next();
        if (!step.run(configLevelContext)) {
            rollback();
            return false;
        }
    }
    return true;
}
Also used : ConfigLevelContext(com.sun.enterprise.security.admin.cli.SecureAdminCommand.ConfigLevelContext) Config(com.sun.enterprise.config.serverbeans.Config) NetworkConfig(org.glassfish.grizzly.config.dom.NetworkConfig) NetworkConfig(org.glassfish.grizzly.config.dom.NetworkConfig) Work(com.sun.enterprise.security.admin.cli.SecureAdminCommand.Work) Protocol(org.glassfish.grizzly.config.dom.Protocol)

Example 23 with Protocol

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

the class WebContainerImpl method removeListener.

private void removeListener(String name) {
    try {
        NetworkListeners networkListeners = networkConfig.getNetworkListeners();
        final NetworkListener listenerToBeRemoved = networkConfig.getNetworkListener(name);
        final Protocols protocols = networkConfig.getProtocols();
        final Protocol protocol = networkConfig.findProtocol(name);
        if (listenerToBeRemoved == null) {
            log.severe("Network Listener " + name + " doesn't exist");
        } else {
            final com.sun.enterprise.config.serverbeans.VirtualServer virtualServer = httpService.getVirtualServerByName(listenerToBeRemoved.findHttpProtocol().getHttp().getDefaultVirtualServer());
            ConfigSupport.apply(new ConfigCode() {

                public Object run(ConfigBeanProxy... params) throws PropertyVetoException {
                    final NetworkListeners listeners = (NetworkListeners) params[0];
                    final com.sun.enterprise.config.serverbeans.VirtualServer server = (com.sun.enterprise.config.serverbeans.VirtualServer) params[1];
                    listeners.getNetworkListener().remove(listenerToBeRemoved);
                    server.removeNetworkListener(listenerToBeRemoved.getName());
                    return listenerToBeRemoved;
                }
            }, networkListeners, virtualServer);
            ConfigSupport.apply(new ConfigCode() {

                public Object run(ConfigBeanProxy... params) throws PropertyVetoException {
                    final Protocols protocols = (Protocols) params[0];
                    final Protocol protocol = (Protocol) params[1];
                    protocols.getProtocol().remove(protocol);
                    return protocol;
                }
            }, protocols, protocol);
        }
    } catch (TransactionFailure e) {
        log.severe("Remove listener " + name + " failed " + e.getMessage());
    }
}
Also used : Protocols(org.glassfish.grizzly.config.dom.Protocols) VirtualServer(org.glassfish.embeddable.web.VirtualServer) PropertyVetoException(java.beans.PropertyVetoException) NetworkListeners(org.glassfish.grizzly.config.dom.NetworkListeners) Protocol(org.glassfish.grizzly.config.dom.Protocol) org.jvnet.hk2.config(org.jvnet.hk2.config) NetworkListener(org.glassfish.grizzly.config.dom.NetworkListener)

Example 24 with Protocol

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

the class CreateNetworkListener method findVirtualServer.

private VirtualServer findVirtualServer(Protocol protocol) {
    String name = null;
    final Http http = protocol.getHttp();
    if (http != null) {
        name = http.getDefaultVirtualServer();
    } else {
        final List<ProtocolFinder> finders = protocol.getPortUnification().getProtocolFinder();
        for (ProtocolFinder finder : finders) {
            if (name == null) {
                final Protocol p = finder.findProtocol();
                if (p.getHttp() != null) {
                    name = p.getHttp().getDefaultVirtualServer();
                }
            }
        }
    }
    return config.getHttpService().getVirtualServerByName(name);
}
Also used : Http(org.glassfish.grizzly.config.dom.Http) Protocol(org.glassfish.grizzly.config.dom.Protocol) ProtocolFinder(org.glassfish.grizzly.config.dom.ProtocolFinder)

Example 25 with Protocol

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

the class CreateProtocolFilter 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);
        final Class<?> filterClass = Thread.currentThread().getContextClassLoader().loadClass(classname);
        if (!org.glassfish.grizzly.filterchain.Filter.class.isAssignableFrom(filterClass)) {
            report.setMessage(MessageFormat.format(rb.getString(LogFacade.CREATE_PORTUNIF_FAIL_NOTFILTER), name, classname));
            report.setActionExitCode(ActionReport.ExitCode.FAILURE);
            return;
        }
        ProtocolChainInstanceHandler handler = getHandler(protocol);
        ProtocolChain chain = getChain(handler);
        ConfigSupport.apply(new SingleConfigCode<ProtocolChain>() {

            @Override
            public Object run(ProtocolChain param) throws PropertyVetoException, TransactionFailure {
                final List<ProtocolFilter> list = param.getProtocolFilter();
                for (ProtocolFilter filter : list) {
                    if (name.equals(filter.getName())) {
                        throw new TransactionFailure(String.format("A protocol filter named %s already exists.", name));
                    }
                }
                final ProtocolFilter filter = param.createChild(ProtocolFilter.class);
                filter.setName(name);
                filter.setClassname(classname);
                list.add(filter);
                return null;
            }
        }, chain);
    } 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) Config(com.sun.enterprise.config.serverbeans.Config) PropertyVetoException(java.beans.PropertyVetoException) PropertyVetoException(java.beans.PropertyVetoException) Target(org.glassfish.internal.api.Target) CommandTarget(org.glassfish.config.support.CommandTarget) 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) Protocol(org.glassfish.grizzly.config.dom.Protocol) ProtocolFilter(org.glassfish.grizzly.config.dom.ProtocolFilter)

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