Search in sources :

Example 11 with NetworkListeners

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

the class WebContainer method postConstruct.

@Override
public void postConstruct() {
    final ReentrantReadWriteLock mapperLock = grizzlyService.obtainMapperLock();
    mapperLock.writeLock().lock();
    try {
        createProbeProviders();
        injectionMgr = habitat.getService(InjectionManager.class);
        invocationMgr = habitat.getService(InvocationManager.class);
        tldProviders = habitat.getAllServices(TldProvider.class);
        createStatsProviders();
        setJspFactory();
        _appsWorkRoot = instance.getApplicationCompileJspPath().getAbsolutePath();
        _modulesRoot = instance.getApplicationRepositoryPath();
        // START S1AS 6178005
        appsStubRoot = instance.getApplicationStubPath().getAbsolutePath();
        // END S1AS 6178005
        // TODO: ParserUtils should become a @Service and it should initialize itself.
        // TODO: there should be only one EntityResolver for both DigesterFactory
        // and ParserUtils
        File root = _serverContext.getInstallRoot();
        File libRoot = new File(root, "lib");
        File schemas = new File(libRoot, "schemas");
        File dtds = new File(libRoot, "dtds");
        try {
            ParserUtils.setSchemaResourcePrefix(schemas.toURI().toURL().toString());
            ParserUtils.setDtdResourcePrefix(dtds.toURI().toURL().toString());
            ParserUtils.setEntityResolver(habitat.<EntityResolver>getService(EntityResolver.class, "web"));
        } catch (MalformedURLException e) {
            logger.log(Level.SEVERE, LogFacade.EXCEPTION_SET_SCHEMAS_DTDS_LOCATION, e);
        }
        instanceName = _serverContext.getInstanceName();
        webContainerFeatureFactory = getWebContainerFeatureFactory();
        configureDynamicReloadingSettings();
        setDebugLevel();
        String maxDepth = null;
        org.glassfish.web.config.serverbeans.WebContainer configWC = serverConfig.getExtensionByType(org.glassfish.web.config.serverbeans.WebContainer.class);
        if (configWC != null)
            maxDepth = configWC.getPropertyValue(DISPATCHER_MAX_DEPTH);
        if (maxDepth != null) {
            int depth = -1;
            try {
                depth = Integer.parseInt(maxDepth);
            } catch (NumberFormatException e) {
            }
            if (depth > 0) {
                Request.setMaxDispatchDepth(depth);
                if (logger.isLoggable(Level.FINE)) {
                    logger.log(Level.FINE, LogFacade.MAX_DISPATCH_DEPTH_SET, maxDepth);
                }
            }
        }
        File currentLogFile = loggingRuntime.getCurrentLogFile();
        if (currentLogFile != null) {
            logServiceFile = currentLogFile.getAbsolutePath();
        }
        Level level = Logger.getLogger("org.apache.catalina.level").getLevel();
        if (level != null) {
            logLevel = level.getName();
        }
        _embedded = habitat.getService(EmbeddedWebContainer.class);
        _embedded.setWebContainer(this);
        _embedded.setLogServiceFile(logServiceFile);
        _embedded.setLogLevel(logLevel);
        _embedded.setFileLoggerHandlerFactory(fileLoggerHandlerFactory);
        _embedded.setWebContainerFeatureFactory(webContainerFeatureFactory);
        _embedded.setCatalinaHome(instance.getDomainRoot().getAbsolutePath());
        _embedded.setCatalinaBase(instance.getDomainRoot().getAbsolutePath());
        _embedded.setUseNaming(false);
        if (_debug > 1)
            _embedded.setDebug(_debug);
        _embedded.setLogger(new IASLogger(logger));
        engine = _embedded.createEngine();
        engine.setParentClassLoader(EmbeddedWebContainer.class.getClassLoader());
        engine.setService(_embedded);
        _embedded.addEngine(engine);
        ((StandardEngine) engine).setDomain(_serverContext.getDefaultDomainName());
        engine.setName(_serverContext.getDefaultDomainName());
        /*
            * Set the server info.
            * By default, the server info is taken from Version#getVersion.
            * However, customers may override it via the product.name system
            * property.
            * Some customers prefer not to disclose the server info
            * for security reasons, in which case they would set the value of the
            * product.name system property to the empty string. In this case,
            * the server name will not be publicly disclosed via the "Server"
            * HTTP response header (which will be suppressed) or any container
            * generated error pages. However, it will still appear in the
            * server logs (see IT 6900).
            */
        String serverInfo = System.getProperty("product.name");
        if (serverInfo == null) {
            ServerInfo.setServerInfo(Version.getVersion());
            ServerInfo.setPublicServerInfo(Version.getVersion());
        } else if (serverInfo.isEmpty()) {
            ServerInfo.setServerInfo(Version.getVersion());
            ServerInfo.setPublicServerInfo(serverInfo);
        } else {
            ServerInfo.setServerInfo(serverInfo);
            ServerInfo.setPublicServerInfo(serverInfo);
        }
        initInstanceSessionProperties();
        configListener = addAndGetWebConfigListener();
        ObservableBean bean = (ObservableBean) ConfigSupport.getImpl(serverConfig.getHttpService());
        bean.addListener(configListener);
        bean = (ObservableBean) ConfigSupport.getImpl(serverConfig.getNetworkConfig().getNetworkListeners());
        bean.addListener(configListener);
        if (serverConfig.getAvailabilityService() != null) {
            bean = (ObservableBean) ConfigSupport.getImpl(serverConfig.getAvailabilityService());
            bean.addListener(configListener);
        }
        transactions.addListenerForType(SystemProperty.class, configListener);
        configListener.setNetworkConfig(serverConfig.getNetworkConfig());
        // embedded mode does not have manager-propertie in domain.xml
        if (configListener.managerProperties != null) {
            ObservableBean managerBean = (ObservableBean) ConfigSupport.getImpl(configListener.managerProperties);
            managerBean.addListener(configListener);
        }
        if (serverConfig.getJavaConfig() != null) {
            ((ObservableBean) ConfigSupport.getImpl(serverConfig.getJavaConfig())).addListener(configListener);
        }
        configListener.setContainer(this);
        configListener.setLogger(logger);
        events.register(this);
        grizzlyService.addMapperUpdateListener(configListener);
        HttpService httpService = serverConfig.getHttpService();
        NetworkConfig networkConfig = serverConfig.getNetworkConfig();
        if (networkConfig != null) {
            // continue;
            securityService = serverConfig.getSecurityService();
            // Configure HTTP listeners
            NetworkListeners networkListeners = networkConfig.getNetworkListeners();
            if (networkListeners != null) {
                List<NetworkListener> listeners = networkListeners.getNetworkListener();
                for (NetworkListener listener : listeners) {
                    createHttpListener(listener, httpService);
                }
            }
            setDefaultRedirectPort(defaultRedirectPort);
            // Configure virtual servers
            createHosts(httpService, securityService);
        }
        loadSystemDefaultWebModules();
        // _lifecycle.fireLifecycleEvent(START_EVENT, null);
        _started = true;
        /*
             * Start the embedded container.
             * Make sure to set the thread's context classloader to the
             * classloader of this class (see IT 8866 for details)
             */
        ClassLoader current = Thread.currentThread().getContextClassLoader();
        Thread.currentThread().setContextClassLoader(getClass().getClassLoader());
        try {
            /*
                 * Trigger a call to sun.awt.AppContext.getAppContext().
                 * This will pin the classloader of this class in memory
                 * and fix a memory leak affecting instances of WebappClassLoader
                 * that was caused by a JRE implementation change in 1.6.0_15
                 * onwards. See IT 11110
                 */
            ImageIO.getCacheDirectory();
            _embedded.start();
        } catch (LifecycleException le) {
            logger.log(Level.SEVERE, LogFacade.UNABLE_TO_START_WEB_CONTAINER, le);
            return;
        } finally {
            // Restore original context classloader
            Thread.currentThread().setContextClassLoader(current);
        }
    } finally {
        mapperLock.writeLock().unlock();
    }
}
Also used : MalformedURLException(java.net.MalformedURLException) InvocationManager(org.glassfish.api.invocation.InvocationManager) ReentrantReadWriteLock(java.util.concurrent.locks.ReentrantReadWriteLock) StandardEngine(org.apache.catalina.core.StandardEngine) NetworkListeners(org.glassfish.grizzly.config.dom.NetworkListeners) WebappClassLoader(org.glassfish.web.loader.WebappClassLoader) TldProvider(org.glassfish.api.web.TldProvider) LifecycleException(org.apache.catalina.LifecycleException) NetworkConfig(org.glassfish.grizzly.config.dom.NetworkConfig) EntityResolver(org.xml.sax.EntityResolver) HttpService(com.sun.enterprise.config.serverbeans.HttpService) IASLogger(com.sun.enterprise.web.logger.IASLogger) Level(java.util.logging.Level) ObservableBean(org.jvnet.hk2.config.ObservableBean) File(java.io.File) InjectionManager(com.sun.enterprise.container.common.spi.util.InjectionManager) NetworkListener(org.glassfish.grizzly.config.dom.NetworkListener)

Example 12 with NetworkListeners

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

the class ConfigAttributeSetTest method simpleAttributeSetTest.

@Test
public void simpleAttributeSetTest() {
    CommandRunnerImpl runner = habitat.getService(CommandRunnerImpl.class);
    assertNotNull(runner);
    // let's find our target
    NetworkListener listener = null;
    NetworkListeners service = habitat.getService(NetworkListeners.class);
    for (NetworkListener l : service.getNetworkListener()) {
        if ("http-listener-1".equals(l.getName())) {
            listener = l;
            break;
        }
    }
    assertNotNull(listener);
    // Let's register a listener
    ObservableBean bean = (ObservableBean) ConfigSupport.getImpl(listener);
    bean.addListener(this);
    // parameters to the command
    ParameterMap parameters = new ParameterMap();
    parameters.set("value", "8090");
    parameters.set("DEFAULT", "configs.config.server-config.http-service.http-listener.http-listener-1.port");
    // execute the set command.
    runner.getCommandInvocation("set", new HTMLActionReporter(), adminSubject()).parameters(parameters).execute();
    // check the result.
    String port = listener.getPort();
    assertEquals(port, "8090");
    // ensure events are delivered.
    habitat.<Transactions>getService(Transactions.class).waitForDrain();
    // finally
    bean.removeListener(this);
    // check we recevied the event
    assertNotNull(event);
    assertEquals("8080", event.getOldValue());
    assertEquals("8090", event.getNewValue());
    assertEquals("port", event.getPropertyName());
}
Also used : Transactions(org.jvnet.hk2.config.Transactions) HTMLActionReporter(com.sun.enterprise.v3.common.HTMLActionReporter) NetworkListeners(org.glassfish.grizzly.config.dom.NetworkListeners) ObservableBean(org.jvnet.hk2.config.ObservableBean) NetworkListener(org.glassfish.grizzly.config.dom.NetworkListener) Test(org.junit.Test) ConfigApiTest(org.glassfish.tests.utils.ConfigApiTest)

Example 13 with NetworkListeners

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

the class PersistenceTest method doTest.

public void doTest() throws TransactionFailure {
    NetworkListeners service = getHabitat().getService(NetworkListeners.class);
    // now do a transaction
    ConfigSupport.apply(new SingleConfigCode<Transport>() {

        public Object run(Transport param) {
            param.setAcceptorThreads("8989");
            return null;
        }
    }, service.getNetworkListener().get(0).findTransport());
// To change body of implemented methods use File | Settings | File Templates.
}
Also used : NetworkListeners(org.glassfish.grizzly.config.dom.NetworkListeners) Transport(org.glassfish.grizzly.config.dom.Transport)

Example 14 with NetworkListeners

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

the class GrizzlyConfigSchemaMigrator method normalizeThreadPools.

private void normalizeThreadPools() throws TransactionFailure {
    ThreadPools threadPools = currentConfig.getThreadPools();
    if (threadPools == null) {
        threadPools = createThreadPools();
    } else {
        final List<ThreadPool> list = threadPools.getThreadPool();
        boolean httpListenerFound = false;
        for (ThreadPool pool : list) {
            httpListenerFound |= HTTP_THREAD_POOL.equals(pool.getThreadPoolId()) || HTTP_THREAD_POOL.equals(pool.getName());
            if (pool.getName() == null) {
                ConfigSupport.apply(new SingleConfigCode<ThreadPool>() {

                    public Object run(ThreadPool param) {
                        param.setName(param.getThreadPoolId());
                        param.setThreadPoolId(null);
                        if (param.getMinThreadPoolSize() == null || Integer.parseInt(param.getMinThreadPoolSize()) < 2) {
                            param.setMinThreadPoolSize("2");
                        }
                        return null;
                    }
                }, pool);
            }
        }
        if (!httpListenerFound) {
            ConfigSupport.apply(new SingleConfigCode<ThreadPools>() {

                public Object run(ThreadPools param) throws TransactionFailure {
                    final ThreadPool pool = param.createChild(ThreadPool.class);
                    pool.setName(HTTP_THREAD_POOL);
                    param.getThreadPool().add(pool);
                    return null;
                }
            }, threadPools);
        }
    }
    final NetworkConfig networkConfig = currentConfig.getNetworkConfig();
    if (networkConfig != null) {
        final NetworkListeners networkListeners = networkConfig.getNetworkListeners();
        if (networkListeners != null) {
            if (networkListeners.getThreadPool() != null && !networkListeners.getThreadPool().isEmpty()) {
                ConfigSupport.apply(new SingleConfigCode<ThreadPools>() {

                    public Object run(ThreadPools param) throws TransactionFailure {
                        migrateThreadPools(param);
                        return null;
                    }
                }, threadPools);
            }
        }
    }
}
Also used : ThreadPools(com.sun.enterprise.config.serverbeans.ThreadPools) TransactionFailure(org.jvnet.hk2.config.TransactionFailure) ThreadPool(org.glassfish.grizzly.config.dom.ThreadPool) NetworkConfig(org.glassfish.grizzly.config.dom.NetworkConfig) NetworkListeners(org.glassfish.grizzly.config.dom.NetworkListeners)

Example 15 with NetworkListeners

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

the class HttpListenerTest method setup.

@Before
public void setup() {
    NetworkListeners service = getHabitat().getService(NetworkListeners.class);
    assertTrue(service != null);
    for (NetworkListener item : service.getNetworkListener()) {
        if ("http-listener-1".equals(item.getName())) {
            listener = item;
            break;
        }
    }
    logger.fine("listener = " + listener);
    assertTrue(listener != null);
}
Also used : NetworkListeners(org.glassfish.grizzly.config.dom.NetworkListeners) NetworkListener(org.glassfish.grizzly.config.dom.NetworkListener) Before(org.junit.Before)

Aggregations

NetworkListeners (org.glassfish.grizzly.config.dom.NetworkListeners)16 NetworkListener (org.glassfish.grizzly.config.dom.NetworkListener)12 NetworkConfig (org.glassfish.grizzly.config.dom.NetworkConfig)5 Protocol (org.glassfish.grizzly.config.dom.Protocol)5 TransactionFailure (org.jvnet.hk2.config.TransactionFailure)5 Config (com.sun.enterprise.config.serverbeans.Config)4 PropertyVetoException (java.beans.PropertyVetoException)4 Protocols (org.glassfish.grizzly.config.dom.Protocols)3 Test (org.junit.Test)3 ConfigBeanProxy (org.jvnet.hk2.config.ConfigBeanProxy)3 ObservableBean (org.jvnet.hk2.config.ObservableBean)3 ActionReport (org.glassfish.api.ActionReport)2 CommandTarget (org.glassfish.config.support.CommandTarget)2 VirtualServer (org.glassfish.embeddable.web.VirtualServer)2 ThreadPool (org.glassfish.grizzly.config.dom.ThreadPool)2 Transport (org.glassfish.grizzly.config.dom.Transport)2 Target (org.glassfish.internal.api.Target)2 org.jvnet.hk2.config (org.jvnet.hk2.config)2 ConfigBean (org.jvnet.hk2.config.ConfigBean)2 ConfigCode (org.jvnet.hk2.config.ConfigCode)2