Search in sources :

Example 16 with Protocol

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

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

the class CreateNetworkListener 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();
    NetworkConfig networkConfig = config.getNetworkConfig();
    NetworkListeners nls = networkConfig.getNetworkListeners();
    // ensure we don't have one of this name already
    for (NetworkListener networkListener : nls.getNetworkListener()) {
        if (networkListener.getName().equals(listenerName)) {
            report.setMessage(MessageFormat.format(rb.getString(LogFacade.CREATE_NETWORK_LISTENER_FAIL_DUPLICATE), listenerName));
            report.setActionExitCode(ActionReport.ExitCode.FAILURE);
            return;
        }
    }
    if (!verifyUniquePort(networkConfig)) {
        report.setMessage(MessageFormat.format(rb.getString(LogFacade.PORT_IN_USE), port, address));
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        return;
    }
    Protocol prot = networkConfig.findProtocol(protocol);
    if (prot == null) {
        report.setMessage(MessageFormat.format(rb.getString(LogFacade.CREATE_HTTP_FAIL_PROTOCOL_NOT_FOUND), protocol));
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        return;
    }
    if (prot.getHttp() == null && prot.getPortUnification() == null) {
        report.setMessage(MessageFormat.format(rb.getString(LogFacade.CREATE_NETWORK_LISTENER_FAIL_BAD_PROTOCOL), protocol));
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        return;
    }
    try {
        ConfigSupport.apply(new ConfigCode() {

            public Object run(ConfigBeanProxy... params) throws TransactionFailure, PropertyVetoException {
                NetworkListeners listeners = (NetworkListeners) params[0];
                NetworkListener newNetworkListener = listeners.createChild(NetworkListener.class);
                newNetworkListener.setProtocol(protocol);
                newNetworkListener.setTransport(transport);
                newNetworkListener.setEnabled(enabled.toString());
                newNetworkListener.setJkEnabled(jkEnabled.toString());
                newNetworkListener.setPort(port);
                if (portRange != null) {
                    newNetworkListener.setPortRange(portRange);
                }
                newNetworkListener.setThreadPool(threadPool);
                newNetworkListener.setName(listenerName);
                newNetworkListener.setAddress(address);
                listeners.getNetworkListener().add(newNetworkListener);
                ((VirtualServer) params[1]).addNetworkListener(listenerName);
                return newNetworkListener;
            }
        }, nls, findVirtualServer(prot));
    } catch (TransactionFailure e) {
        e.printStackTrace();
        report.setMessage(MessageFormat.format(rb.getString(LogFacade.CREATE_NETWORK_LISTENER_FAIL), listenerName) + (e.getMessage() == null ? "No reason given" : e.getMessage()));
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        report.setFailureCause(e);
        return;
    }
    report.setActionExitCode(ActionReport.ExitCode.SUCCESS);
}
Also used : TransactionFailure(org.jvnet.hk2.config.TransactionFailure) PropertyVetoException(java.beans.PropertyVetoException) 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) NetworkConfig(org.glassfish.grizzly.config.dom.NetworkConfig) NetworkConfig(org.glassfish.grizzly.config.dom.NetworkConfig) NetworkListeners(org.glassfish.grizzly.config.dom.NetworkListeners) ActionReport(org.glassfish.api.ActionReport) Protocol(org.glassfish.grizzly.config.dom.Protocol) NetworkListener(org.glassfish.grizzly.config.dom.NetworkListener)

Example 18 with Protocol

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

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

the class ListProtocolFilters 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 && protocol.getProtocolChainInstanceHandler() != null) {
        final ProtocolChain chain = protocol.getProtocolChainInstanceHandler().getProtocolChain();
        if (chain != null) {
            for (ProtocolFilter filter : chain.getProtocolFilter()) {
                report.getTopMessagePart().addChild().setMessage(filter.getName());
            }
        }
    }
    report.setActionExitCode(ActionReport.ExitCode.SUCCESS);
}
Also used : Target(org.glassfish.internal.api.Target) CommandTarget(org.glassfish.config.support.CommandTarget) Config(com.sun.enterprise.config.serverbeans.Config) ProtocolChain(org.glassfish.grizzly.config.dom.ProtocolChain) ActionReport(org.glassfish.api.ActionReport) Protocol(org.glassfish.grizzly.config.dom.Protocol) ProtocolFilter(org.glassfish.grizzly.config.dom.ProtocolFilter)

Example 20 with Protocol

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

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