Search in sources :

Example 1 with Transports

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

the class DeleteTransport 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();
    Transports transports = networkConfig.getTransports();
    try {
        for (Transport transport : transports.getTransport()) {
            if (transportName.equalsIgnoreCase(transport.getName())) {
                transportToBeRemoved = transport;
            }
        }
        if (transportToBeRemoved == null) {
            report.setMessage(MessageFormat.format(rb.getString(LogFacade.DELETE_TRANSPORT_NOT_EXISTS), transportName));
            report.setActionExitCode(ActionReport.ExitCode.FAILURE);
            return;
        }
        // check if the transport to be deleted is being used by
        // any network listener
        List<NetworkListener> nwlsnrList = transportToBeRemoved.findNetworkListeners();
        for (NetworkListener nwlsnr : nwlsnrList) {
            if (transportToBeRemoved.getName().equals(nwlsnr.getTransport())) {
                report.setMessage(MessageFormat.format(rb.getString(LogFacade.DELETE_TRANSPORT_BEINGUSED), transportName, nwlsnr.getName()));
                report.setActionExitCode(ActionReport.ExitCode.FAILURE);
                return;
            }
        }
        ConfigSupport.apply(new SingleConfigCode<Transports>() {

            public Object run(Transports param) {
                param.getTransport().remove(transportToBeRemoved);
                return transportToBeRemoved;
            }
        }, transports);
    } catch (TransactionFailure e) {
        report.setMessage(MessageFormat.format(rb.getString(LogFacade.DELETE_TRANSPORT_FAIL), transportName) + "  " + 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) 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) NetworkListener(org.glassfish.grizzly.config.dom.NetworkListener)

Example 2 with Transports

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

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

the class WebContainerImpl method bind.

private void bind(Port port, WebListener webListener, String vsId) {
    String protocol = Port.HTTP_PROTOCOL;
    final int portNumber = port.getPortNumber();
    final String defaultVS = vsId;
    final WebListener listener = webListener;
    if (webListener == null) {
        listenerName = getListenerName();
        webListener = new HttpListener();
        webListener.setId(listenerName);
        webListener.setPort(portNumber);
    } else {
        listenerName = webListener.getId();
        protocol = webListener.getProtocol();
    }
    listeners.add(webListener);
    if (protocol.equals(Port.HTTP_PROTOCOL)) {
        securityEnabled = "false";
    } else if (protocol.equals(Port.HTTPS_PROTOCOL)) {
        securityEnabled = "true";
    }
    try {
        ConfigSupport.apply(new SingleConfigCode<Protocols>() {

            public Object run(Protocols param) throws TransactionFailure {
                final Protocol protocol = param.createChild(Protocol.class);
                protocol.setName(listenerName);
                protocol.setSecurityEnabled(securityEnabled);
                param.getProtocol().add(protocol);
                final Http http = protocol.createChild(Http.class);
                http.setDefaultVirtualServer(defaultVS);
                http.setFileCache(http.createChild(FileCache.class));
                protocol.setHttp(http);
                return protocol;
            }
        }, networkConfig.getProtocols());
        ConfigSupport.apply(new ConfigCode() {

            public Object run(ConfigBeanProxy... params) throws TransactionFailure {
                NetworkListeners nls = (NetworkListeners) params[0];
                Transports transports = (Transports) params[1];
                final NetworkListener listener = nls.createChild(NetworkListener.class);
                listener.setName(listenerName);
                listener.setPort(Integer.toString(portNumber));
                listener.setProtocol(listenerName);
                listener.setThreadPool("http-thread-pool");
                if (listener.findThreadPool() == null) {
                    final ThreadPool pool = nls.createChild(ThreadPool.class);
                    pool.setName(listenerName);
                    listener.setThreadPool(listenerName);
                }
                listener.setTransport("tcp");
                if (listener.findTransport() == null) {
                    final Transport transport = transports.createChild(Transport.class);
                    transport.setName(listenerName);
                    listener.setTransport(listenerName);
                }
                nls.getNetworkListener().add(listener);
                return listener;
            }
        }, networkConfig.getNetworkListeners(), networkConfig.getTransports());
        if (webListener.getProtocol().equals("https")) {
            NetworkListener networkListener = networkConfig.getNetworkListener(listenerName);
            Protocol httpProtocol = networkListener.findHttpProtocol();
            ConfigSupport.apply(new SingleConfigCode<Protocol>() {

                public Object run(Protocol param) throws TransactionFailure {
                    Ssl newSsl = param.createChild(Ssl.class);
                    populateSslElement(newSsl, listener);
                    System.out.println("SSL " + newSsl.getKeyStore() + " " + newSsl.getKeyStorePassword() + " " + newSsl.getTrustStore() + " " + newSsl.getTrustStorePassword());
                    param.setSsl(newSsl);
                    return newSsl;
                }
            }, httpProtocol);
        }
        com.sun.enterprise.config.serverbeans.VirtualServer vs = httpService.getVirtualServerByName(config.getVirtualServerId());
        ConfigSupport.apply(new SingleConfigCode<com.sun.enterprise.config.serverbeans.VirtualServer>() {

            public Object run(com.sun.enterprise.config.serverbeans.VirtualServer avs) throws PropertyVetoException {
                avs.addNetworkListener(listenerName);
                return avs;
            }
        }, vs);
    } catch (Exception e) {
        if (listeners.contains(webListener)) {
            listeners.remove(webListener);
        }
        e.printStackTrace();
    }
}
Also used : Protocols(org.glassfish.grizzly.config.dom.Protocols) ThreadPool(org.glassfish.grizzly.config.dom.ThreadPool) Http(org.glassfish.grizzly.config.dom.Http) NetworkListeners(org.glassfish.grizzly.config.dom.NetworkListeners) HttpListener(org.glassfish.embeddable.web.HttpListener) Protocol(org.glassfish.grizzly.config.dom.Protocol) Transports(org.glassfish.grizzly.config.dom.Transports) Ssl(org.glassfish.grizzly.config.dom.Ssl) VirtualServer(org.glassfish.embeddable.web.VirtualServer) PropertyVetoException(java.beans.PropertyVetoException) ConfigException(org.glassfish.embeddable.web.ConfigException) GlassFishException(org.glassfish.embeddable.GlassFishException) PropertyVetoException(java.beans.PropertyVetoException) WebListener(org.glassfish.embeddable.web.WebListener) Transport(org.glassfish.grizzly.config.dom.Transport) org.jvnet.hk2.config(org.jvnet.hk2.config) NetworkListener(org.glassfish.grizzly.config.dom.NetworkListener)

Example 4 with Transports

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

the class GenericGrizzlyListener method getSelectionKeyHandlerByName.

private static SelectionKeyHandler getSelectionKeyHandlerByName(final String name, final Transport transportConfig) {
    Transports transports = transportConfig.getParent();
    List<SelectionKeyHandler> handlers = transports.getSelectionKeyHandler();
    if (!handlers.isEmpty()) {
        for (SelectionKeyHandler handler : handlers) {
            if (handler.getName().equals(name)) {
                return handler;
            }
        }
    }
    return null;
}
Also used : Transports(org.glassfish.grizzly.config.dom.Transports) SelectionKeyHandler(org.glassfish.grizzly.config.dom.SelectionKeyHandler)

Aggregations

Transports (org.glassfish.grizzly.config.dom.Transports)4 Transport (org.glassfish.grizzly.config.dom.Transport)3 Config (com.sun.enterprise.config.serverbeans.Config)2 PropertyVetoException (java.beans.PropertyVetoException)2 ActionReport (org.glassfish.api.ActionReport)2 CommandTarget (org.glassfish.config.support.CommandTarget)2 NetworkConfig (org.glassfish.grizzly.config.dom.NetworkConfig)2 NetworkListener (org.glassfish.grizzly.config.dom.NetworkListener)2 Target (org.glassfish.internal.api.Target)2 TransactionFailure (org.jvnet.hk2.config.TransactionFailure)2 GlassFishException (org.glassfish.embeddable.GlassFishException)1 ConfigException (org.glassfish.embeddable.web.ConfigException)1 HttpListener (org.glassfish.embeddable.web.HttpListener)1 VirtualServer (org.glassfish.embeddable.web.VirtualServer)1 WebListener (org.glassfish.embeddable.web.WebListener)1 Http (org.glassfish.grizzly.config.dom.Http)1 NetworkListeners (org.glassfish.grizzly.config.dom.NetworkListeners)1 Protocol (org.glassfish.grizzly.config.dom.Protocol)1 Protocols (org.glassfish.grizzly.config.dom.Protocols)1 SelectionKeyHandler (org.glassfish.grizzly.config.dom.SelectionKeyHandler)1