Search in sources :

Example 1 with WARDirContext

use of org.apache.naming.resources.WARDirContext in project Payara by payara.

the class StandardContext method start.

/**
 * Start this Context component.
 *
 * @exception LifecycleException if a startup error occurs
 */
@Override
public synchronized void start() throws LifecycleException {
    if (started) {
        if (log.isLoggable(Level.INFO)) {
            log.log(Level.INFO, LogFacade.CONTAINER_ALREADY_STARTED_EXCEPTION, logName());
        }
        return;
    }
    long startupTimeStart = System.currentTimeMillis();
    if (!initialized) {
        try {
            init();
        } catch (Exception ex) {
            throw new LifecycleException("Error initializaing ", ex);
        }
    }
    if (log.isLoggable(Level.FINE)) {
        log.log(Level.FINE, "Starting " + ("".equals(getName()) ? "ROOT" : getName()));
    }
    // Set JMX object name for proper pipeline registration
    preRegisterJMX();
    // Notify our interested LifecycleListeners
    lifecycle.fireLifecycleEvent(BEFORE_START_EVENT, null);
    setAvailable(false);
    setConfigured(false);
    // Add missing components as necessary
    if (webappResources == null) {
        // (1) Required by Loader
        if (log.isLoggable(Level.FINE)) {
            log.log(Level.FINE, "Configuring default Resources");
        }
        try {
            if ((docBase != null) && (docBase.endsWith(".war")) && (!(new File(docBase).isDirectory())))
                setResources(new WARDirContext());
            else
                setResources(new WebDirContext());
        } catch (IllegalArgumentException e) {
            throw new LifecycleException(rb.getString(LogFacade.INIT_RESOURCES_EXCEPTION), e);
        }
    }
    resourcesStart();
    // Add alternate resources
    if (alternateDocBases != null && !alternateDocBases.isEmpty()) {
        for (AlternateDocBase alternateDocBase : alternateDocBases) {
            String docBase = alternateDocBase.getDocBase();
            if (log.isLoggable(Level.FINE)) {
                log.log(Level.FINE, "Configuring alternate resources");
            }
            try {
                if (docBase != null && docBase.endsWith(".war") && (!(new File(docBase).isDirectory()))) {
                    setAlternateResources(alternateDocBase, new WARDirContext());
                } else {
                    setAlternateResources(alternateDocBase, new FileDirContext());
                }
            } catch (IllegalArgumentException e) {
                throw new LifecycleException(rb.getString(LogFacade.INIT_RESOURCES_EXCEPTION), e);
            }
        }
        alternateResourcesStart();
    }
    if (getLoader() == null) {
        createLoader();
    }
    // Initialize character set mapper
    getCharsetMapper();
    // Post work directory
    postWorkDirectory();
    // Validate required extensions
    try {
        ExtensionValidator.validateApplication(getResources(), this);
    } catch (IOException ioe) {
        String msg = MessageFormat.format(rb.getString(LogFacade.DEPENDENCY_CHECK_EXCEPTION), this);
        throw new LifecycleException(msg, ioe);
    }
    // Reading the "catalina.useNaming" environment variable
    String useNamingProperty = System.getProperty("catalina.useNaming");
    if ((useNamingProperty != null) && ("false".equals(useNamingProperty))) {
        useNaming = false;
    }
    if (isUseNaming()) {
        if (namingContextListener == null) {
            namingContextListener = new NamingContextListener();
            namingContextListener.setDebug(getDebug());
            namingContextListener.setName(getNamingContextName());
            addLifecycleListener(namingContextListener);
        }
    }
    // Binding thread
    // START OF SJSAS 8.1 6174179
    // ClassLoader oldCCL = bindThread();
    ClassLoader oldCCL = null;
    try {
        started = true;
        // Start our subordinate components, if any
        if ((loader != null) && (loader instanceof Lifecycle))
            ((Lifecycle) loader).start();
        if ((logger != null) && (logger instanceof Lifecycle))
            ((Lifecycle) logger).start();
        // Unbinding thread
        // START OF SJSAS 8.1 6174179
        // unbindThread(oldCCL);
        // END OF SJSAS 8.1 6174179
        // Binding thread
        oldCCL = bindThread();
        if ((realm != null) && (realm instanceof Lifecycle))
            ((Lifecycle) realm).start();
        if ((resources != null) && (resources instanceof Lifecycle))
            ((Lifecycle) resources).start();
        // Start our child containers, if any
        for (Container child : findChildren()) {
            if (child instanceof Lifecycle) {
                ((Lifecycle) child).start();
            }
        }
        // if any
        if (pipeline instanceof Lifecycle)
            ((Lifecycle) pipeline).start();
        // START SJSAS 8.1 5049111
        // Notify our interested LifecycleListeners
        lifecycle.fireLifecycleEvent(START_EVENT, null);
    // END SJSAS 8.1 5049111
    } catch (Throwable t) {
        throw new LifecycleException(t);
    } finally {
        // Unbinding thread
        unbindThread(oldCCL);
    }
    if (!getConfigured()) {
        String msg = MessageFormat.format(rb.getString(LogFacade.STARTUP_CONTEXT_FAILED_EXCEPTION), getName());
        throw new LifecycleException(msg);
    }
    // Store some required info as ServletContext attributes
    postResources();
    if (orderedLibs != null && !orderedLibs.isEmpty()) {
        getServletContext().setAttribute(ServletContext.ORDERED_LIBS, orderedLibs);
        context.setAttributeReadOnly(ServletContext.ORDERED_LIBS);
    }
    // Initialize associated mapper
    mapper.setContext(getPath(), welcomeFiles, ContextsAdapterUtility.wrap(resources));
    // Binding thread
    oldCCL = bindThread();
    try {
        // Set up the context init params
        mergeParameters();
        // Notify our interested LifecycleListeners
        lifecycle.fireLifecycleEvent(AFTER_START_EVENT, null);
        // Support for pluggability : this has to be done before
        // listener events are fired
        callServletContainerInitializers();
        // Configure and call application event listeners
        contextListenerStart();
        // Start manager
        if ((manager != null) && (manager instanceof Lifecycle)) {
            ((Lifecycle) getManager()).start();
        }
        // Start ContainerBackgroundProcessor thread
        super.threadStart();
        // Configure and call application filters
        filterStart();
        // Load and initialize all "load on startup" servlets
        loadOnStartup(findChildren());
    } catch (Throwable t) {
        log.log(Level.SEVERE, LogFacade.STARTUP_CONTEXT_FAILED_EXCEPTION, getName());
        try {
            stop();
        } catch (Throwable tt) {
            log.log(Level.SEVERE, LogFacade.CLEANUP_FAILED_EXCEPTION, tt);
        }
        throw new LifecycleException(t);
    } finally {
        // Unbinding thread
        unbindThread(oldCCL);
    }
    // Set available status depending upon startup success
    if (log.isLoggable(Level.FINEST)) {
        log.log(Level.FINEST, "Startup successfully completed");
    }
    setAvailable(true);
    // JMX registration
    registerJMX();
    startTimeMillis = System.currentTimeMillis();
    startupTime = startTimeMillis - startupTimeStart;
    // Send j2ee.state.running notification
    if (getObjectName() != null) {
        Notification notification = new Notification("j2ee.state.running", this, sequenceNumber++);
        sendNotification(notification);
    }
    // of files on startup
    if (getLoader() instanceof WebappLoader) {
        ((WebappLoader) getLoader()).closeJARs(true);
    }
}
Also used : LifecycleException(org.apache.catalina.LifecycleException) WebDirContext(org.apache.naming.resources.WebDirContext) WARDirContext(org.apache.naming.resources.WARDirContext) FileDirContext(org.apache.naming.resources.FileDirContext) Lifecycle(org.apache.catalina.Lifecycle) IOException(java.io.IOException) LifecycleException(org.apache.catalina.LifecycleException) MalformedObjectNameException(javax.management.MalformedObjectNameException) IOException(java.io.IOException) ServletException(javax.servlet.ServletException) NamingException(javax.naming.NamingException) MBeanRegistrationException(javax.management.MBeanRegistrationException) MalformedURLException(java.net.MalformedURLException) Notification(javax.management.Notification) Container(org.apache.catalina.Container) AlternateDocBase(org.glassfish.grizzly.http.server.util.AlternateDocBase) WebappClassLoader(org.glassfish.web.loader.WebappClassLoader) WebappLoader(org.apache.catalina.loader.WebappLoader) File(java.io.File)

Aggregations

File (java.io.File)1 IOException (java.io.IOException)1 MalformedURLException (java.net.MalformedURLException)1 MBeanRegistrationException (javax.management.MBeanRegistrationException)1 MalformedObjectNameException (javax.management.MalformedObjectNameException)1 Notification (javax.management.Notification)1 NamingException (javax.naming.NamingException)1 ServletException (javax.servlet.ServletException)1 Container (org.apache.catalina.Container)1 Lifecycle (org.apache.catalina.Lifecycle)1 LifecycleException (org.apache.catalina.LifecycleException)1 WebappLoader (org.apache.catalina.loader.WebappLoader)1 FileDirContext (org.apache.naming.resources.FileDirContext)1 WARDirContext (org.apache.naming.resources.WARDirContext)1 WebDirContext (org.apache.naming.resources.WebDirContext)1 AlternateDocBase (org.glassfish.grizzly.http.server.util.AlternateDocBase)1 WebappClassLoader (org.glassfish.web.loader.WebappClassLoader)1