Search in sources :

Example 11 with Protocols

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

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

Example 13 with Protocols

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

the class InstanceReaderImpl method getListeners.

/**
 * Enlists both http and https listeners of this server instance
 * It will be form "http:<hostname>:<port> https:<hostname>:<port>"
 *
 * @return String   Listener(s) info.
 */
@Override
public String getListeners() throws LbReaderException {
    StringBuffer listenerStr = new StringBuffer();
    Config config = _domain.getConfigNamed(_server.getConfigRef());
    NetworkConfig networkConfig = config.getNetworkConfig();
    Protocols protocols = networkConfig.getProtocols();
    NetworkListeners nls = networkConfig.getNetworkListeners();
    Iterator<NetworkListener> listenerIter = nls.getNetworkListener().iterator();
    int i = 0;
    PropertyResolver resolver = new PropertyResolver(_domain, _server.getName());
    while (listenerIter.hasNext()) {
        NetworkListener listener = listenerIter.next();
        NetworkListener rawListener = GlassFishConfigBean.getRawView(listener);
        if (rawListener.getName().equals(ADMIN_LISTENER)) {
            continue;
        }
        String prot = rawListener.getProtocol();
        Protocol protocol = protocols.findProtocol(prot);
        if (i > 0) {
            // space between listener names
            listenerStr.append(' ');
        }
        i++;
        if (Boolean.valueOf(protocol.getHttp().getJkEnabled())) {
            listenerStr.append(AJP_PROTO);
        } else {
            if (Boolean.valueOf(protocol.getSecurityEnabled()).booleanValue()) {
                listenerStr.append(HTTPS_PROTO);
            } else {
                listenerStr.append(HTTP_PROTO);
            }
        }
        String hostName = getResolvedHostName(rawListener.getAddress());
        listenerStr.append(hostName);
        listenerStr.append(':');
        // resolve the port name
        String port = rawListener.getPort();
        // If it is system variable, resolve it
        if ((port != null) && (port.length() > 1) && (port.charAt(0) == '$') && (port.charAt(1) == '{') && (port.charAt(port.length() - 1) == '}')) {
            String portVar = port.substring(2, port.length() - 1);
            port = resolver.getPropertyValue(portVar);
            if (port == null) {
                throw new LbReaderException(LbLogUtil.getStringManager().getString("UnableToResolveSystemProperty", portVar, _server.getName()));
            }
        }
        listenerStr.append(port);
    }
    return listenerStr.toString();
}
Also used : 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) NetworkListeners(org.glassfish.grizzly.config.dom.NetworkListeners) PropertyResolver(org.glassfish.config.support.PropertyResolver) Protocol(org.glassfish.grizzly.config.dom.Protocol) LbReaderException(org.glassfish.loadbalancer.admin.cli.reader.api.LbReaderException) NetworkListener(org.glassfish.grizzly.config.dom.NetworkListener)

Example 14 with Protocols

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

the class CreateSsl method findOrCreateProtocol.

public Protocol findOrCreateProtocol(final String name, final boolean create) throws TransactionFailure {
    NetworkConfig networkConfig = config.getNetworkConfig();
    Protocol protocol = networkConfig.findProtocol(name);
    if (protocol == null && create) {
        protocol = (Protocol) ConfigSupport.apply(new SingleConfigCode<Protocols>() {

            @Override
            public Object run(Protocols param) throws TransactionFailure {
                Protocol newProtocol = param.createChild(Protocol.class);
                newProtocol.setName(name);
                newProtocol.setSecurityEnabled("true");
                param.getProtocol().add(newProtocol);
                return newProtocol;
            }
        }, habitat.<Protocols>getService(Protocols.class));
    }
    return protocol;
}
Also used : TransactionFailure(org.jvnet.hk2.config.TransactionFailure) Protocols(org.glassfish.grizzly.config.dom.Protocols) NetworkConfig(org.glassfish.grizzly.config.dom.NetworkConfig) Protocol(org.glassfish.grizzly.config.dom.Protocol)

Example 15 with Protocols

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

the class AdminRESTConfigUpgrade method postConstruct.

@Override
public void postConstruct() {
    for (Config config : configs.getConfig()) {
        // we only want to handle configs that have an admin listener
        try {
            if (config.getAdminListener() == null) {
                LogRecord lr = new LogRecord(Level.FINE, String.format("Skipping config %s. No admin listener.", config.getName()));
                lr.setLoggerName(getClass().getName());
                EarlyLogHandler.earlyMessages.add(lr);
                continue;
            }
        } catch (IllegalStateException ise) {
            /*
                 * I've only seen the exception rather than
                 * getAdminListener returning null. This should
                 * typically happen for any config besides
                 * <server-config>, but we'll proceed if any
                 * config has an admin listener.
                 */
            LogRecord lr = new LogRecord(Level.FINE, String.format("Skipping config %s. getAdminListener threw: %s", config.getName(), ise.getLocalizedMessage()));
            lr.setLoggerName(getClass().getName());
            EarlyLogHandler.earlyMessages.add(lr);
            continue;
        }
        Protocols ps = config.getNetworkConfig().getProtocols();
        if (ps != null) {
            for (Protocol p : ps.getProtocol()) {
                Http h = p.getHttp();
                if (h != null && "__asadmin".equals(h.getDefaultVirtualServer())) {
                    try {
                        ConfigSupport.apply(new HttpConfigCode(), h);
                    } catch (TransactionFailure tf) {
                        LogRecord lr = new LogRecord(Level.SEVERE, "Could not upgrade http element for admin console: " + tf);
                        lr.setLoggerName(getClass().getName());
                        EarlyLogHandler.earlyMessages.add(lr);
                    }
                }
            }
        }
    }
}
Also used : TransactionFailure(org.jvnet.hk2.config.TransactionFailure) Protocols(org.glassfish.grizzly.config.dom.Protocols) LogRecord(java.util.logging.LogRecord) Config(com.sun.enterprise.config.serverbeans.Config) Http(org.glassfish.grizzly.config.dom.Http) Protocol(org.glassfish.grizzly.config.dom.Protocol)

Aggregations

Protocols (org.glassfish.grizzly.config.dom.Protocols)16 Protocol (org.glassfish.grizzly.config.dom.Protocol)15 Config (com.sun.enterprise.config.serverbeans.Config)12 TransactionFailure (org.jvnet.hk2.config.TransactionFailure)12 CommandTarget (org.glassfish.config.support.CommandTarget)10 Target (org.glassfish.internal.api.Target)10 NetworkListener (org.glassfish.grizzly.config.dom.NetworkListener)7 ActionReport (org.glassfish.api.ActionReport)6 NetworkConfig (org.glassfish.grizzly.config.dom.NetworkConfig)6 PropertyVetoException (java.beans.PropertyVetoException)5 List (java.util.List)4 Http (org.glassfish.grizzly.config.dom.Http)4 NetworkListeners (org.glassfish.grizzly.config.dom.NetworkListeners)3 ArrayList (java.util.ArrayList)2 VirtualServer (org.glassfish.embeddable.web.VirtualServer)2 PortUnification (org.glassfish.grizzly.config.dom.PortUnification)2 ProtocolChain (org.glassfish.grizzly.config.dom.ProtocolChain)2 ProtocolChainInstanceHandler (org.glassfish.grizzly.config.dom.ProtocolChainInstanceHandler)2 ProtocolFilter (org.glassfish.grizzly.config.dom.ProtocolFilter)2 ProtocolFinder (org.glassfish.grizzly.config.dom.ProtocolFinder)2