Search in sources :

Example 11 with Config

use of com.sun.enterprise.config.serverbeans.Config in project Payara by payara.

the class GlassFishTldProvider method postConstruct.

public void postConstruct() {
    /*
         * Check whether JSP caching has been enabled
         */
    Config cfg = serverContext.getDefaultServices().getService(Config.class, ServerEnvironment.DEFAULT_INSTANCE_NAME);
    WebContainer webContainer = cfg.getExtensionByType(WebContainer.class);
    if (webContainer == null) {
        return;
    }
    if (!Boolean.valueOf(webContainer.getJspCachingEnabled())) {
        return;
    }
    /*
         * JSP caching has been enabled
         */
    Class jspCachingImplClass = CacheTag.class;
    URI[] uris = null;
    Module m = null;
    if (jspCachingImplClass != null) {
        m = registry.find(jspCachingImplClass);
    }
    if (m != null) {
        uris = m.getModuleDefinition().getLocations();
    } else {
        ClassLoader classLoader = getClass().getClassLoader();
        if (classLoader instanceof URLClassLoader) {
            URL[] urls = ((URLClassLoader) classLoader).getURLs();
            if (urls != null && urls.length > 0) {
                uris = new URI[urls.length];
                for (int i = 0; i < urls.length; i++) {
                    try {
                        uris[i] = urls[i].toURI();
                    } catch (URISyntaxException e) {
                        String msg = rb.getString(LogFacade.TLD_PROVIDER_IGNORE_URL);
                        msg = MessageFormat.format(msg, urls[i]);
                        logger.log(Level.WARNING, msg, e);
                    }
                }
            }
        } else {
            logger.log(Level.WARNING, LogFacade.UNABLE_TO_DETERMINE_TLD_RESOURCES, new Object[] { "JSP Caching", classLoader, GlassFishTldProvider.class.getName() });
        }
    }
    if (uris != null && uris.length > 0) {
        Pattern pattern = Pattern.compile("META-INF/.*\\.tld");
        for (URI uri : uris) {
            List<String> entries = JarURIPattern.getJarEntries(uri, pattern);
            if (entries != null && entries.size() > 0) {
                tldMap.put(uri, entries);
            }
        }
    }
}
Also used : JarURIPattern(com.sun.enterprise.util.net.JarURIPattern) Pattern(java.util.regex.Pattern) Config(com.sun.enterprise.config.serverbeans.Config) WebContainer(org.glassfish.web.config.serverbeans.WebContainer) CacheTag(com.sun.appserv.web.taglibs.cache.CacheTag) Module(com.sun.enterprise.module.Module)

Example 12 with Config

use of com.sun.enterprise.config.serverbeans.Config in project Payara by payara.

the class CreateHttp method execute.

/**
 * Executes the command with the command parameters passed as Properties
 * where the keys are the parameter 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
    Protocols protocols = config.getNetworkConfig().getProtocols();
    Protocol protocol = null;
    for (Protocol p : protocols.getProtocol()) {
        if (protocolName.equals(p.getName())) {
            protocol = p;
        }
    }
    if (protocol == null) {
        report.setMessage(MessageFormat.format(rb.getString(LogFacade.CREATE_HTTP_FAIL_PROTOCOL_NOT_FOUND), protocolName));
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        return;
    }
    if (protocol.getHttp() != null) {
        report.setMessage(MessageFormat.format(rb.getString(LogFacade.CREATE_HTTP_FAIL_DUPLICATE), protocolName));
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        return;
    }
    // Add to the <network-config>
    try {
        ConfigSupport.apply(new SingleConfigCode<Protocol>() {

            public Object run(Protocol param) throws TransactionFailure {
                Http http = param.createChild(Http.class);
                final FileCache cache = http.createChild(FileCache.class);
                cache.setEnabled("false");
                http.setFileCache(cache);
                http.setDefaultVirtualServer(defaultVirtualServer);
                http.setDnsLookupEnabled(dnsLookupEnabled == null ? null : dnsLookupEnabled.toString());
                http.setMaxConnections(maxConnections);
                http.setRequestTimeoutSeconds(requestTimeoutSeconds);
                http.setTimeoutSeconds(timeoutSeconds);
                http.setXpoweredBy(xPoweredBy == null ? null : xPoweredBy.toString());
                http.setServerHeader(serverHeader == null ? null : serverHeader.toString());
                http.setXframeOptions(xFrameOptions == null ? null : xFrameOptions.toString());
                http.setServerName(serverName);
                // HTTP2 options
                http.setHttp2Enabled(http2Enabled);
                if (http2MaxConcurrentStreams != null) {
                    http.setHttp2MaxConcurrentStreams(http2MaxConcurrentStreams);
                }
                if (http2InitialWindowSizeInBytes != null) {
                    http.setHttp2InitialWindowSizeInBytes(http2InitialWindowSizeInBytes);
                }
                if (http2MaxFramePayloadSizeInBytes != null) {
                    http.setHttp2MaxFramePayloadSizeInBytes(http2MaxFramePayloadSizeInBytes);
                }
                if (http2MaxHeaderListSizeInBytes != null) {
                    http.setHttp2MaxHeaderListSizeInBytes(http2MaxHeaderListSizeInBytes);
                }
                if (http2StreamsHighWaterMark != null) {
                    http.setHttp2StreamsHighWaterMark(http2StreamsHighWaterMark.toString());
                }
                if (http2CleanPercentage != null) {
                    http.setHttp2CleanPercentage(http2CleanPercentage.toString());
                }
                if (http2CleanFrequencyCheck != null) {
                    http.setHttp2CleanFrequencyCheck(http2CleanFrequencyCheck);
                }
                if (http2DisableCipherCheck != null) {
                    http.setHttp2DisableCipherCheck(http2DisableCipherCheck);
                }
                if (http2PushEnabled != null) {
                    http.setHttp2PushEnabled(http2PushEnabled);
                }
                param.setHttp(http);
                return http;
            }
        }, protocol);
    } catch (TransactionFailure e) {
        report.setMessage(MessageFormat.format(rb.getString(LogFacade.CREATE_HTTP_REDIRECT_FAIL), protocolName, 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) 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) Http(org.glassfish.grizzly.config.dom.Http) ActionReport(org.glassfish.api.ActionReport) Protocol(org.glassfish.grizzly.config.dom.Protocol) FileCache(org.glassfish.grizzly.config.dom.FileCache)

Example 13 with Config

use of com.sun.enterprise.config.serverbeans.Config 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);
                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 14 with Config

use of com.sun.enterprise.config.serverbeans.Config 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 15 with Config

use of com.sun.enterprise.config.serverbeans.Config 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)

Aggregations

Config (com.sun.enterprise.config.serverbeans.Config)152 ActionReport (org.glassfish.api.ActionReport)73 TransactionFailure (org.jvnet.hk2.config.TransactionFailure)50 PropertyVetoException (java.beans.PropertyVetoException)34 Target (org.glassfish.internal.api.Target)31 CommandTarget (org.glassfish.config.support.CommandTarget)30 Properties (java.util.Properties)28 NetworkConfig (org.glassfish.grizzly.config.dom.NetworkConfig)23 Protocol (org.glassfish.grizzly.config.dom.Protocol)20 HashMap (java.util.HashMap)17 Server (com.sun.enterprise.config.serverbeans.Server)15 NetworkListener (org.glassfish.grizzly.config.dom.NetworkListener)15 Logger (java.util.logging.Logger)14 ColumnFormatter (com.sun.enterprise.util.ColumnFormatter)13 Protocols (org.glassfish.grizzly.config.dom.Protocols)12 ArrayList (java.util.ArrayList)11 List (java.util.List)11 BlockingQueueHandler (fish.payara.nucleus.notification.BlockingQueueHandler)10 Level (java.util.logging.Level)10 LogRecord (java.util.logging.LogRecord)10