Search in sources :

Example 71 with LifecycleException

use of org.apache.catalina.LifecycleException in project Payara by payara.

the class WebContainer method loadDefaultWebModulesAfterAllAppsProcessed.

/**
 * Configures a default web module for each virtual server
 * if default-web-module is defined.
 */
public void loadDefaultWebModulesAfterAllAppsProcessed() {
    String defaultPath = null;
    Container[] vsArray = getEngine().findChildren();
    for (Container aVsArray : vsArray) {
        if (aVsArray instanceof VirtualServer) {
            VirtualServer vs = (VirtualServer) aVsArray;
            /*
                * Let AdminConsoleAdapter handle any requests for
                * the root context of the '__asadmin' virtual-server, see
                * https://glassfish.dev.java.net/issues/show_bug.cgi?id=5664
                */
            if (org.glassfish.api.web.Constants.ADMIN_VS.equals(vs.getName())) {
                continue;
            }
            WebModuleConfig wmInfo = vs.getDefaultWebModule(domain, habitat.<WebArchivist>getService(WebArchivist.class), appRegistry);
            if (wmInfo != null) {
                defaultPath = wmInfo.getContextPath();
                // Virtual server declares default-web-module
                try {
                    updateDefaultWebModule(vs, vs.getNetworkListenerNames(), wmInfo);
                } catch (LifecycleException le) {
                    String msg = rb.getString(LogFacade.DEFAULT_WEB_MODULE_ERROR);
                    msg = MessageFormat.format(msg, defaultPath, vs.getName());
                    logger.log(Level.SEVERE, msg, le);
                }
                if (logger.isLoggable(Level.INFO)) {
                    logger.log(Level.INFO, LogFacade.VIRTUAL_SERVER_LOADED_DEFAULT_WEB_MODULE, new Object[] { vs.getName(), defaultPath });
                }
            } else {
            // No need to create default web module off of virtual
            // server's docroot since system web modules are already
            // created in WebContainer.postConstruct
            }
        }
    }
}
Also used : Container(org.apache.catalina.Container) LifecycleException(org.apache.catalina.LifecycleException) WebArchivist(org.glassfish.web.deployment.archivist.WebArchivist)

Example 72 with LifecycleException

use of org.apache.catalina.LifecycleException in project Payara by payara.

the class WebContainer method updateDefaultWebModule.

/*
     * Updates the given virtual server with the given default path.
     *
     * The given default path corresponds to the context path of one of the
     * web contexts deployed on the virtual server that has been designated
     * as the virtual server's new default-web-module.
     *
     * @param virtualServer The virtual server to update
     * @param ports The port numbers of the HTTP listeners with which the
     * given virtual server is associated
     * @param defaultContextPath The context path of the web module that has
     * been designated as the virtual server's new default web module, or null
     * if the virtual server no longer has any default-web-module
     */
protected void updateDefaultWebModule(VirtualServer virtualServer, String[] listenerNames, WebModuleConfig wmInfo) throws LifecycleException {
    String defaultContextPath = null;
    if (wmInfo != null) {
        defaultContextPath = wmInfo.getContextPath();
    }
    if (defaultContextPath != null && !defaultContextPath.startsWith("/")) {
        defaultContextPath = "/" + defaultContextPath;
        wmInfo.getDescriptor().setContextRoot(defaultContextPath);
    }
    Connector[] connectors = _embedded.findConnectors();
    for (Connector connector : connectors) {
        PECoyoteConnector conn = (PECoyoteConnector) connector;
        String name = conn.getName();
        for (String listenerName : listenerNames) {
            if (name.equals(listenerName)) {
                Mapper mapper = conn.getMapper();
                try {
                    mapper.setDefaultContextPath(virtualServer.getName(), defaultContextPath);
                    for (String alias : virtualServer.findAliases()) {
                        mapper.setDefaultContextPath(alias, defaultContextPath);
                    }
                    virtualServer.setDefaultContextPath(defaultContextPath);
                } catch (Exception e) {
                    throw new LifecycleException(e);
                }
            }
        }
    }
}
Also used : PECoyoteConnector(com.sun.enterprise.web.connector.coyote.PECoyoteConnector) Connector(org.apache.catalina.Connector) Mapper(org.glassfish.grizzly.http.server.util.Mapper) ContextMapper(org.glassfish.internal.grizzly.ContextMapper) ContainerMapper(com.sun.enterprise.v3.services.impl.ContainerMapper) LifecycleException(org.apache.catalina.LifecycleException) PECoyoteConnector(com.sun.enterprise.web.connector.coyote.PECoyoteConnector) LifecycleException(org.apache.catalina.LifecycleException) NamingException(javax.naming.NamingException) BindException(java.net.BindException) MalformedURLException(java.net.MalformedURLException)

Example 73 with LifecycleException

use of org.apache.catalina.LifecycleException 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 74 with LifecycleException

use of org.apache.catalina.LifecycleException in project Payara by payara.

the class LoggerBase method write.

protected void write(String msg, Throwable throwable, int verbosity) {
    CharArrayWriter buf = new CharArrayWriter();
    PrintWriter writer = new PrintWriter(buf);
    writer.println(msg);
    throwable.printStackTrace(writer);
    Throwable rootCause = null;
    if (throwable instanceof LifecycleException)
        rootCause = ((LifecycleException) throwable).getCause();
    else if (throwable instanceof ServletException)
        rootCause = ((ServletException) throwable).getRootCause();
    if (rootCause != null) {
        writer.println("----- Root Cause -----");
        rootCause.printStackTrace(writer);
    }
    write(buf.toString(), verbosity);
}
Also used : ServletException(javax.servlet.ServletException) LifecycleException(org.apache.catalina.LifecycleException) CharArrayWriter(java.io.CharArrayWriter) PrintWriter(java.io.PrintWriter)

Example 75 with LifecycleException

use of org.apache.catalina.LifecycleException in project Payara by payara.

the class FileLogger method stop.

/**
 * Gracefully terminate the active use of the public methods of this
 * component.  This method should be the last one called on a given
 * instance of this component.
 *
 * @exception LifecycleException if this component detects a fatal error
 *  that needs to be reported
 */
public void stop() throws LifecycleException {
    // Validate and update our current component state
    if (!started)
        throw new LifecycleException(rb.getString(LogFacade.FILE_LOGGER_NOT_STARTED));
    lifecycle.fireLifecycleEvent(STOP_EVENT, null);
    started = false;
    close();
    super.stop();
}
Also used : LifecycleException(org.apache.catalina.LifecycleException)

Aggregations

LifecycleException (org.apache.catalina.LifecycleException)78 Lifecycle (org.apache.catalina.Lifecycle)23 IOException (java.io.IOException)18 NamingException (javax.naming.NamingException)12 MalformedURLException (java.net.MalformedURLException)11 Container (org.apache.catalina.Container)11 File (java.io.File)10 Realm (org.apache.catalina.Realm)10 ServletException (javax.servlet.ServletException)9 ArrayList (java.util.ArrayList)7 ReentrantReadWriteLock (java.util.concurrent.locks.ReentrantReadWriteLock)5 MalformedObjectNameException (javax.management.MalformedObjectNameException)5 Context (org.apache.catalina.Context)5 Loader (org.apache.catalina.Loader)5 StandardManager (org.apache.catalina.session.StandardManager)5 BindException (java.net.BindException)4 Properties (java.util.Properties)4 Lock (java.util.concurrent.locks.Lock)4 ReadWriteLock (java.util.concurrent.locks.ReadWriteLock)4 Notification (javax.management.Notification)4