Search in sources :

Example 6 with SingleConfigCode

use of org.jvnet.hk2.config.SingleConfigCode in project Payara by payara.

the class DeleteHttp 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 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-redirect 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.setHttp(null);
                return null;
            }
        }, protocolToBeRemoved);
    } catch (TransactionFailure e) {
        report.setMessage(MessageFormat.format(rb.getString(LogFacade.DELETE_HTTP_REDIRECT_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) ActionReport(org.glassfish.api.ActionReport) Protocol(org.glassfish.grizzly.config.dom.Protocol) NetworkListener(org.glassfish.grizzly.config.dom.NetworkListener)

Example 7 with SingleConfigCode

use of org.jvnet.hk2.config.SingleConfigCode in project Payara by payara.

the class DeleteProtocol 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 networkConfig = config.getNetworkConfig();
    Protocols protocols = networkConfig.getProtocols();
    try {
        protocol = protocols.findProtocol(protocolName);
        if (protocol == null) {
            report.setMessage(MessageFormat.format(rb.getString(LogFacade.DELETE_PROTOCOL_NOT_EXISTS), protocolName));
            report.setActionExitCode(ActionReport.ExitCode.FAILURE);
            return;
        }
        // check if the protocol to be deleted is being used by
        // any network listener
        List<NetworkListener> nwlsnrList = protocol.findNetworkListeners();
        for (NetworkListener nwlsnr : nwlsnrList) {
            if (protocol.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<Protocols>() {

            public Object run(Protocols param) {
                param.getProtocol().remove(protocol);
                return protocol;
            }
        }, protocols);
    } catch (TransactionFailure e) {
        report.setMessage(MessageFormat.format(rb.getString(LogFacade.DELETE_PROTOCOL_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) ActionReport(org.glassfish.api.ActionReport) NetworkListener(org.glassfish.grizzly.config.dom.NetworkListener)

Example 8 with SingleConfigCode

use of org.jvnet.hk2.config.SingleConfigCode 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 9 with SingleConfigCode

use of org.jvnet.hk2.config.SingleConfigCode in project Payara by payara.

the class WebSslConfigHandler method create.

@Override
public void create(final CreateSsl command, ActionReport report) {
    NetworkConfig netConfig = command.config.getNetworkConfig();
    // ensure we have the specified listener
    NetworkListener listener = netConfig.getNetworkListener(command.listenerId);
    Protocol httpProtocol;
    try {
        if (listener == null) {
            report.setMessage(MessageFormat.format(rb.getString(LogFacade.CREATE_SSL_HTTP_NOT_FOUND), command.listenerId));
            httpProtocol = command.findOrCreateProtocol(command.listenerId);
        } else {
            httpProtocol = listener.findHttpProtocol();
            Ssl ssl = httpProtocol.getSsl();
            if (ssl != null) {
                report.setMessage(MessageFormat.format(rb.getString(LogFacade.CREATE_SSL_HTTP_ALREADY_EXISTS), command.listenerId));
                report.setActionExitCode(ActionReport.ExitCode.FAILURE);
                return;
            }
        }
        ConfigSupport.apply(new SingleConfigCode<Protocol>() {

            public Object run(Protocol param) throws TransactionFailure {
                Ssl newSsl = param.createChild(Ssl.class);
                command.populateSslElement(newSsl);
                param.setSsl(newSsl);
                return newSsl;
            }
        }, httpProtocol);
    } catch (TransactionFailure e) {
        command.reportError(report, e);
    }
    command.reportSuccess(report);
}
Also used : TransactionFailure(org.jvnet.hk2.config.TransactionFailure) NetworkConfig(org.glassfish.grizzly.config.dom.NetworkConfig) Protocol(org.glassfish.grizzly.config.dom.Protocol) CreateSsl(com.sun.enterprise.admin.commands.CreateSsl) DeleteSsl(com.sun.enterprise.admin.commands.DeleteSsl) Ssl(org.glassfish.grizzly.config.dom.Ssl) NetworkListener(org.glassfish.grizzly.config.dom.NetworkListener)

Example 10 with SingleConfigCode

use of org.jvnet.hk2.config.SingleConfigCode in project Payara by payara.

the class SetEnvironmentWarningConfigurationCommand method execute.

@Override
public void execute(AdminCommandContext acc) {
    Config config = targetUtil.getConfig(target);
    ActionReport actionReport = acc.getActionReport();
    EnvironmentWarningConfiguration environmentWarningConfiguration = config.getExtensionByType(EnvironmentWarningConfiguration.class);
    if (environmentWarningConfiguration != null) {
        try {
            ConfigSupport.apply(new SingleConfigCode<EnvironmentWarningConfiguration>() {

                @Override
                public Object run(EnvironmentWarningConfiguration config) throws PropertyVetoException {
                    if (enabled != null) {
                        config.setEnabled(enabled);
                    }
                    if (message != null) {
                        config.setMessage(message);
                    }
                    if (backgroundColour != null) {
                        if (backgroundColour.matches("^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$")) {
                            config.setBackgroundColour(backgroundColour);
                        } else {
                            throw new PropertyVetoException("Invalid data for background colour, must be a hex value.", new PropertyChangeEvent(config, "backgroundColour", config.getBackgroundColour(), backgroundColour));
                        }
                    }
                    if (textColour != null) {
                        if (textColour.matches("^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$")) {
                            config.setTextColour(textColour);
                        } else {
                            throw new PropertyVetoException("Invalid data for text colour, must be a hex value.", new PropertyChangeEvent(config, "textColour", config.getTextColour(), textColour));
                        }
                    }
                    return null;
                }
            }, environmentWarningConfiguration);
        } catch (TransactionFailure ex) {
            // Set failure
            actionReport.failure(Logger.getLogger(SetEnvironmentWarningConfigurationCommand.class.getName()), "Failed to update configuration", ex);
        }
    }
}
Also used : PropertyVetoException(java.beans.PropertyVetoException) TransactionFailure(org.jvnet.hk2.config.TransactionFailure) PropertyChangeEvent(java.beans.PropertyChangeEvent) Config(com.sun.enterprise.config.serverbeans.Config) ActionReport(org.glassfish.api.ActionReport) EnvironmentWarningConfiguration(fish.payara.appserver.environment.warning.config.EnvironmentWarningConfiguration)

Aggregations

TransactionFailure (org.jvnet.hk2.config.TransactionFailure)139 PropertyVetoException (java.beans.PropertyVetoException)117 ActionReport (org.glassfish.api.ActionReport)66 Config (com.sun.enterprise.config.serverbeans.Config)37 Property (org.jvnet.hk2.config.types.Property)28 Resources (com.sun.enterprise.config.serverbeans.Resources)25 List (java.util.List)19 ResourceStatus (org.glassfish.resourcebase.resources.api.ResourceStatus)17 SingleConfigCode (org.jvnet.hk2.config.SingleConfigCode)16 Protocol (org.glassfish.grizzly.config.dom.Protocol)15 Test (org.junit.Test)15 CommandTarget (org.glassfish.config.support.CommandTarget)14 NetworkListener (org.glassfish.grizzly.config.dom.NetworkListener)14 Target (org.glassfish.internal.api.Target)14 NetworkConfig (org.glassfish.grizzly.config.dom.NetworkConfig)12 Protocols (org.glassfish.grizzly.config.dom.Protocols)11 Resource (com.sun.enterprise.config.serverbeans.Resource)9 SecurityService (com.sun.enterprise.config.serverbeans.SecurityService)9 Properties (java.util.Properties)8 HttpService (com.sun.enterprise.config.serverbeans.HttpService)6