Search in sources :

Example 21 with Target

use of org.glassfish.internal.api.Target in project Payara by payara.

the class CreateHttpListener method execute.

/**
 * Executes the command with the command parameters passed as Properties where the keys are the paramter names and
 * the values the parameter values
 *
 * @param context information
 */
public void execute(AdminCommandContext context) {
    final ActionReport report = context.getActionReport();
    if (!validateInputs(report)) {
        return;
    }
    Target targetUtil = services.getService(Target.class);
    Config newConfig = targetUtil.getConfig(target);
    if (newConfig != null) {
        config = newConfig;
    }
    networkConfig = config.getNetworkConfig();
    HttpService httpService = config.getHttpService();
    if (!(verifyUniqueName(report, networkConfig) && verifyUniquePort(report, networkConfig) && verifyDefaultVirtualServer(report))) {
        return;
    }
    VirtualServer vs = httpService.getVirtualServerByName(defaultVirtualServer);
    boolean listener = false;
    boolean protocol = false;
    boolean transport = false;
    try {
        transport = createOrGetTransport(null);
        protocol = createProtocol(context);
        createHttp(context);
        final ThreadPool threadPool = getThreadPool(networkConfig);
        listener = createNetworkListener(networkConfig, transport, threadPool);
        updateVirtualServer(vs);
    } catch (TransactionFailure e) {
        try {
            if (listener) {
                deleteListener(context);
            }
            if (protocol) {
                deleteProtocol(context);
            }
            if (transport) {
                deleteTransport(context);
            }
        } catch (Exception e1) {
            if (logger.isLoggable(Level.INFO)) {
                logger.log(Level.INFO, e.getMessage(), e);
            }
            throw new RuntimeException(e.getMessage());
        }
        if (logger.isLoggable(Level.INFO)) {
            logger.log(Level.INFO, e.getMessage(), e);
        }
        report.setMessage(MessageFormat.format(rb.getString(LogFacade.CREATE_HTTP_LISTENER_FAIL), listenerId, 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) Config(com.sun.enterprise.config.serverbeans.Config) NetworkConfig(org.glassfish.grizzly.config.dom.NetworkConfig) HttpService(com.sun.enterprise.config.serverbeans.HttpService) ThreadPool(org.glassfish.grizzly.config.dom.ThreadPool) ActionReport(org.glassfish.api.ActionReport) VirtualServer(com.sun.enterprise.config.serverbeans.VirtualServer) PropertyVetoException(java.beans.PropertyVetoException)

Example 22 with Target

use of org.glassfish.internal.api.Target 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)

Example 23 with Target

use of org.glassfish.internal.api.Target in project Payara by payara.

the class DeleteHttpRedirect method execute.

// ----------------------------------------------- Methods from AdminCommand
@Override
public void execute(AdminCommandContext context) {
    Target targetUtil = services.getService(Target.class);
    Config newConfig = targetUtil.getConfig(target);
    if (newConfig != null) {
        config = newConfig;
    }
    Protocol protocolToBeRemoved = null;
    ActionReport report = context.getActionReport();
    NetworkConfig networkConfig = config.getNetworkConfig();
    Protocols protocols = networkConfig.getProtocols();
    try {
        for (Protocol protocol : protocols.getProtocol()) {
            if (protocolName.equalsIgnoreCase(protocol.getName())) {
                protocolToBeRemoved = protocol;
            }
        }
        if (protocolToBeRemoved == null) {
            report.setMessage(MessageFormat.format(rb.getString(LogFacade.DELETE_HTTP_NOTEXISTS), protocolName));
            report.setActionExitCode(ActionReport.ExitCode.FAILURE);
            return;
        }
        // check if the protocol whose http to be deleted is being used by
        // any network listener, then do not delete it.
        List<NetworkListener> nwlsnrList = protocolToBeRemoved.findNetworkListeners();
        for (NetworkListener nwlsnr : nwlsnrList) {
            if (protocolToBeRemoved.getName().equals(nwlsnr.getProtocol())) {
                report.setMessage(MessageFormat.format(rb.getString(LogFacade.DELETE_PROTOCOL_BEING_USED), protocolName, nwlsnr.getName()));
                report.setActionExitCode(ActionReport.ExitCode.FAILURE);
                return;
            }
        }
        ConfigSupport.apply(new SingleConfigCode<Protocol>() {

            public Object run(Protocol param) {
                param.setHttpRedirect(null);
                return null;
            }
        }, protocolToBeRemoved);
    } catch (TransactionFailure e) {
        report.setMessage(MessageFormat.format(rb.getString(LogFacade.DELETE_HTTP_FAIL), protocolName) + e.getLocalizedMessage());
        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) NetworkConfig(org.glassfish.grizzly.config.dom.NetworkConfig) NetworkConfig(org.glassfish.grizzly.config.dom.NetworkConfig) Protocol(org.glassfish.grizzly.config.dom.Protocol) ActionReport(org.glassfish.api.ActionReport) NetworkListener(org.glassfish.grizzly.config.dom.NetworkListener)

Example 24 with Target

use of org.glassfish.internal.api.Target in project Payara by payara.

the class DeleteHttpListener method execute.

/**
 * Executes the command with the command parameters passed as Properties where the keys are the paramter 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;
    }
    ActionReport report = context.getActionReport();
    networkConfig = config.getNetworkConfig();
    if (!exists()) {
        report.setMessage(MessageFormat.format(rb.getString(LogFacade.DELETE_HTTP_LISTENER_NOT_EXISTS), listenerId));
        report.setActionExitCode(ExitCode.FAILURE);
        return;
    }
    try {
        NetworkListener ls = networkConfig.getNetworkListener(listenerId);
        final String name = ls.getProtocol();
        VirtualServer vs = config.getHttpService().getVirtualServerByName(ls.findHttpProtocol().getHttp().getDefaultVirtualServer());
        ConfigSupport.apply(new DeleteNetworkListener(), networkConfig.getNetworkListeners());
        ConfigSupport.apply(new UpdateVirtualServer(), vs);
        cleanUp(name);
        report.setActionExitCode(ExitCode.SUCCESS);
    } catch (TransactionFailure e) {
        report.setMessage(MessageFormat.format(rb.getString(LogFacade.DELETE_HTTP_LISTENER_FAIL), listenerId));
        report.setActionExitCode(ExitCode.FAILURE);
        report.setFailureCause(e);
    }
}
Also used : TransactionFailure(org.jvnet.hk2.config.TransactionFailure) Target(org.glassfish.internal.api.Target) CommandTarget(org.glassfish.config.support.CommandTarget) Config(com.sun.enterprise.config.serverbeans.Config) NetworkConfig(org.glassfish.grizzly.config.dom.NetworkConfig) ActionReport(org.glassfish.api.ActionReport) VirtualServer(com.sun.enterprise.config.serverbeans.VirtualServer) NetworkListener(org.glassfish.grizzly.config.dom.NetworkListener)

Example 25 with Target

use of org.glassfish.internal.api.Target in project Payara by payara.

the class DeleteNetworkListener method execute.

/**
 * Executes the command with the command parameters passed as Properties where the keys are the paramter 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;
    }
    ActionReport report = context.getActionReport();
    NetworkListeners networkListeners = config.getNetworkConfig().getNetworkListeners();
    try {
        if (findListener(networkListeners, report)) {
            final Protocol httpProtocol = listenerToBeRemoved.findHttpProtocol();
            final VirtualServer virtualServer = config.getHttpService().getVirtualServerByName(httpProtocol.getHttp().getDefaultVirtualServer());
            ConfigSupport.apply(new ConfigCode() {

                public Object run(ConfigBeanProxy... params) throws PropertyVetoException {
                    final NetworkListeners listeners = (NetworkListeners) params[0];
                    final VirtualServer server = (VirtualServer) params[1];
                    listeners.getNetworkListener().remove(listenerToBeRemoved);
                    server.removeNetworkListener(listenerToBeRemoved.getName());
                    return listenerToBeRemoved;
                }
            }, networkListeners, virtualServer);
        }
        report.setActionExitCode(ActionReport.ExitCode.SUCCESS);
    } catch (TransactionFailure e) {
        report.setMessage(MessageFormat.format(rb.getString(LogFacade.DELETE_NETWORK_LISTENER_FAIL), networkListenerName));
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        report.setFailureCause(e);
    }
}
Also used : PropertyVetoException(java.beans.PropertyVetoException) TransactionFailure(org.jvnet.hk2.config.TransactionFailure) Target(org.glassfish.internal.api.Target) CommandTarget(org.glassfish.config.support.CommandTarget) ConfigBeanProxy(org.jvnet.hk2.config.ConfigBeanProxy) ConfigCode(org.jvnet.hk2.config.ConfigCode) Config(com.sun.enterprise.config.serverbeans.Config) NetworkListeners(org.glassfish.grizzly.config.dom.NetworkListeners) ActionReport(org.glassfish.api.ActionReport) Protocol(org.glassfish.grizzly.config.dom.Protocol) VirtualServer(com.sun.enterprise.config.serverbeans.VirtualServer)

Aggregations

Target (org.glassfish.internal.api.Target)39 CommandTarget (org.glassfish.config.support.CommandTarget)35 Config (com.sun.enterprise.config.serverbeans.Config)32 ActionReport (org.glassfish.api.ActionReport)32 TransactionFailure (org.jvnet.hk2.config.TransactionFailure)22 Protocol (org.glassfish.grizzly.config.dom.Protocol)15 PropertyVetoException (java.beans.PropertyVetoException)11 NetworkConfig (org.glassfish.grizzly.config.dom.NetworkConfig)11 Protocols (org.glassfish.grizzly.config.dom.Protocols)10 NetworkListener (org.glassfish.grizzly.config.dom.NetworkListener)9 List (java.util.List)8 VirtualServer (com.sun.enterprise.config.serverbeans.VirtualServer)5 HttpService (com.sun.enterprise.config.serverbeans.HttpService)4 SystemPropertyConstants (com.sun.enterprise.util.SystemPropertyConstants)3 ArrayList (java.util.ArrayList)3 Properties (java.util.Properties)3 Logger (java.util.logging.Logger)3 Inject (javax.inject.Inject)3 I18n (org.glassfish.api.I18n)3 Param (org.glassfish.api.Param)3