Search in sources :

Example 6 with TransactionFailure

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

the class CreateTransport 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;
    }
    final ActionReport report = context.getActionReport();
    // check for duplicates
    NetworkConfig networkConfig = config.getNetworkConfig();
    Transports transports = networkConfig.getTransports();
    for (Transport transport : transports.getTransport()) {
        if (transportName != null && transportName.equalsIgnoreCase(transport.getName())) {
            report.setMessage(MessageFormat.format(rb.getString(LogFacade.CREATE_TRANSPORT_FAIL_DUPLICATE), transportName));
            report.setActionExitCode(ActionReport.ExitCode.FAILURE);
            return;
        }
    }
    // Add to the <network-config>
    try {
        ConfigSupport.apply(new SingleConfigCode<Transports>() {

            public Object run(Transports param) throws PropertyVetoException, TransactionFailure {
                boolean docrootAdded = false;
                boolean accessLogAdded = false;
                Transport newTransport = param.createChild(Transport.class);
                newTransport.setName(transportName);
                newTransport.setAcceptorThreads(acceptorThreads);
                newTransport.setBufferSizeBytes(bufferSizeBytes);
                newTransport.setByteBufferType(byteBufferType);
                newTransport.setClassname(className);
                newTransport.setDisplayConfiguration(displayConfiguration.toString());
                newTransport.setIdleKeyTimeoutSeconds(idleKeyTimeoutSeconds);
                newTransport.setMaxConnectionsCount(maxConnectionsCount);
                newTransport.setName(transportName);
                newTransport.setReadTimeoutMillis(readTimeoutMillis);
                newTransport.setSelectionKeyHandler(selectionKeyHandler);
                newTransport.setSelectorPollTimeoutMillis(selectorPollTimeoutMillis);
                newTransport.setWriteTimeoutMillis(writeTimeoutMillis);
                newTransport.setTcpNoDelay(tcpNoDelay.toString());
                param.getTransport().add(newTransport);
                return newTransport;
            }
        }, transports);
    } catch (TransactionFailure e) {
        report.setMessage(MessageFormat.format(rb.getString(LogFacade.CREATE_TRANSPORT_FAIL), transportName));
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        report.setFailureCause(e);
        return;
    }
    report.setActionExitCode(ActionReport.ExitCode.SUCCESS);
}
Also used : PropertyVetoException(java.beans.PropertyVetoException) 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) Transports(org.glassfish.grizzly.config.dom.Transports) NetworkConfig(org.glassfish.grizzly.config.dom.NetworkConfig) ActionReport(org.glassfish.api.ActionReport) Transport(org.glassfish.grizzly.config.dom.Transport)

Example 7 with TransactionFailure

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

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

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

the class CreateProtocol 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;
    }
    final ActionReport report = context.getActionReport();
    // check for duplicates
    NetworkConfig networkConfig = config.getNetworkConfig();
    Protocols protocols = networkConfig.getProtocols();
    for (Protocol protocol : protocols.getProtocol()) {
        if (protocolName != null && protocolName.equalsIgnoreCase(protocol.getName())) {
            report.setMessage(MessageFormat.format(rb.getString(LogFacade.CREATE_PROTOCOL_FAIL_DUPLICATE), protocolName));
            report.setActionExitCode(ActionReport.ExitCode.FAILURE);
            return;
        }
    }
    // Add to the <network-config>
    try {
        create(protocols, protocolName, securityEnabled);
    } catch (TransactionFailure e) {
        report.setMessage(MessageFormat.format(rb.getString(LogFacade.CREATE_PROTOCOL_FAIL), protocolName));
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        report.setFailureCause(e);
        return;
    } catch (Exception e) {
        report.setMessage(MessageFormat.format(rb.getString(LogFacade.CREATE_PROTOCOL_FAIL), protocolName));
        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)

Example 10 with TransactionFailure

use of org.jvnet.hk2.config.TransactionFailure 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)

Aggregations

TransactionFailure (org.jvnet.hk2.config.TransactionFailure)191 PropertyVetoException (java.beans.PropertyVetoException)132 ActionReport (org.glassfish.api.ActionReport)86 Property (org.jvnet.hk2.config.types.Property)61 Config (com.sun.enterprise.config.serverbeans.Config)52 HashMap (java.util.HashMap)30 Test (org.junit.Test)27 Resources (com.sun.enterprise.config.serverbeans.Resources)25 Map (java.util.Map)25 List (java.util.List)21 CommandTarget (org.glassfish.config.support.CommandTarget)21 NetworkListener (org.glassfish.grizzly.config.dom.NetworkListener)21 Target (org.glassfish.internal.api.Target)21 NetworkConfig (org.glassfish.grizzly.config.dom.NetworkConfig)20 Protocol (org.glassfish.grizzly.config.dom.Protocol)20 ConfigBean (org.jvnet.hk2.config.ConfigBean)20 ConfigBeanProxy (org.jvnet.hk2.config.ConfigBeanProxy)18 ResourceStatus (org.glassfish.resourcebase.resources.api.ResourceStatus)17 SingleConfigCode (org.jvnet.hk2.config.SingleConfigCode)16 ParameterMap (org.glassfish.api.admin.ParameterMap)14