Search in sources :

Example 1 with ProtocolFinder

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

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

Example 3 with ProtocolFinder

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

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

the class DeleteProtocolFinder 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);
        PortUnification pu = getPortUnification(protocol);
        ConfigSupport.apply(new ConfigCode() {

            @Override
            public Object run(ConfigBeanProxy... params) {
                final Protocol prot = (Protocol) params[0];
                final PortUnification portUnification = (PortUnification) params[1];
                final List<ProtocolFinder> oldList = portUnification.getProtocolFinder();
                List<ProtocolFinder> newList = new ArrayList<ProtocolFinder>();
                for (final ProtocolFinder finder : oldList) {
                    if (!name.equals(finder.getName())) {
                        newList.add(finder);
                    }
                }
                if (oldList.size() == newList.size()) {
                    throw new RuntimeException(String.format("No finder named %s found for protocol %s", name, protocolName));
                }
                if (newList.isEmpty()) {
                    prot.setPortUnification(null);
                } else {
                    portUnification.setProtocolFinder(newList);
                }
                return null;
            }
        }, protocol, pu);
        cleanPortUnification(pu);
    } catch (ValidationFailureException e) {
        return;
    } catch (Exception e) {
        e.printStackTrace();
        report.setMessage(MessageFormat.format(rb.getString(LogFacade.DELETE_FAIL), name, e.getMessage() == null ? "No reason given" : e.getMessage()));
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        report.setFailureCause(e);
        return;
    }
}
Also used : Protocols(org.glassfish.grizzly.config.dom.Protocols) PortUnification(org.glassfish.grizzly.config.dom.PortUnification) Config(com.sun.enterprise.config.serverbeans.Config) ProtocolFinder(org.glassfish.grizzly.config.dom.ProtocolFinder) Target(org.glassfish.internal.api.Target) CommandTarget(org.glassfish.config.support.CommandTarget) ConfigBeanProxy(org.jvnet.hk2.config.ConfigBeanProxy) SingleConfigCode(org.jvnet.hk2.config.SingleConfigCode) ConfigCode(org.jvnet.hk2.config.ConfigCode) ArrayList(java.util.ArrayList) List(java.util.List) Protocol(org.glassfish.grizzly.config.dom.Protocol)

Aggregations

Protocol (org.glassfish.grizzly.config.dom.Protocol)4 ProtocolFinder (org.glassfish.grizzly.config.dom.ProtocolFinder)4 Config (com.sun.enterprise.config.serverbeans.Config)3 CommandTarget (org.glassfish.config.support.CommandTarget)3 PortUnification (org.glassfish.grizzly.config.dom.PortUnification)3 Target (org.glassfish.internal.api.Target)3 List (java.util.List)2 Protocols (org.glassfish.grizzly.config.dom.Protocols)2 SingleConfigCode (org.jvnet.hk2.config.SingleConfigCode)2 PropertyVetoException (java.beans.PropertyVetoException)1 ArrayList (java.util.ArrayList)1 ActionReport (org.glassfish.api.ActionReport)1 Http (org.glassfish.grizzly.config.dom.Http)1 ConfigBeanProxy (org.jvnet.hk2.config.ConfigBeanProxy)1 ConfigCode (org.jvnet.hk2.config.ConfigCode)1 TransactionFailure (org.jvnet.hk2.config.TransactionFailure)1