Java Code Examples for org.apache.catalina.Context#getLogger()

The following examples show how to use org.apache.catalina.Context#getLogger() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FileStore.java    From Tomcat8-Source-Read with MIT License 5 votes vote down vote up
/**
 * Load and return the Session associated with the specified session
 * identifier from this Store, without removing it.  If there is no
 * such stored Session, return <code>null</code>.
 *
 * @param id Session identifier of the session to load
 *
 * @exception ClassNotFoundException if a deserialization error occurs
 * @exception IOException if an input/output error occurs
 */
@Override
public Session load(String id) throws ClassNotFoundException, IOException {
    // Open an input stream to the specified pathname, if any
    File file = file(id);
    if (file == null) {
        return null;
    }

    if (!file.exists()) {
        return null;
    }

    Context context = getManager().getContext();
    Log contextLog = context.getLogger();

    if (contextLog.isDebugEnabled()) {
        contextLog.debug(sm.getString(getStoreName()+".loading", id, file.getAbsolutePath()));
    }

    ClassLoader oldThreadContextCL = context.bind(Globals.IS_SECURITY_ENABLED, null);

    try (FileInputStream fis = new FileInputStream(file.getAbsolutePath());
            ObjectInputStream ois = getObjectInputStream(fis)) {

        StandardSession session = (StandardSession) manager.createEmptySession();
        session.readObjectData(ois);
        session.setManager(manager);
        return session;
    } catch (FileNotFoundException e) {
        if (contextLog.isDebugEnabled()) {
            contextLog.debug("No persisted data file found");
        }
        return null;
    } finally {
        context.unbind(Globals.IS_SECURITY_ENABLED, oldThreadContextCL);
    }
}
 
Example 2
Source File: Introspection.java    From Tomcat8-Source-Read with MIT License 5 votes vote down vote up
/**
 * Attempt to load a class using the given Container's class loader. If the
 * class cannot be loaded, a debug level log message will be written to the
 * Container's log and null will be returned.
 * @param context The class loader of this context will be used to attempt
 *  to load the class
 * @param className The class name
 * @return the loaded class or <code>null</code> if loading failed
 */
public static Class<?> loadClass(Context context, String className) {
    ClassLoader cl = context.getLoader().getClassLoader();
    Log log = context.getLogger();
    Class<?> clazz = null;
    try {
        clazz = cl.loadClass(className);
    } catch (ClassNotFoundException | NoClassDefFoundError | ClassFormatError e) {
        log.debug(sm.getString("introspection.classLoadFailed", className), e);
    } catch (Throwable t) {
        ExceptionUtils.handleThrowable(t);
        log.debug(sm.getString("introspection.classLoadFailed", className), t);
    }
    return clazz;
}
 
Example 3
Source File: StandardManager.java    From Tomcat8-Source-Read with MIT License 4 votes vote down vote up
/**
 * Load any currently active sessions that were previously unloaded
 * to the appropriate persistence mechanism, if any.  If persistence is not
 * supported, this method returns without doing anything.
 *
 * @exception ClassNotFoundException if a serialized class cannot be
 *  found during the reload
 * @exception IOException if an input/output error occurs
 */
protected void doLoad() throws ClassNotFoundException, IOException {
    if (log.isDebugEnabled()) {
        log.debug("Start: Loading persisted sessions");
    }

    // Initialize our internal data structures
    sessions.clear();

    // Open an input stream to the specified pathname, if any
    File file = file();
    if (file == null) {
        return;
    }
    if (log.isDebugEnabled()) {
        log.debug(sm.getString("standardManager.loading", pathname));
    }
    Loader loader = null;
    ClassLoader classLoader = null;
    Log logger = null;
    try (FileInputStream fis = new FileInputStream(file.getAbsolutePath());
            BufferedInputStream bis = new BufferedInputStream(fis)) {
        Context c = getContext();
        loader = c.getLoader();
        logger = c.getLogger();
        if (loader != null) {
            classLoader = loader.getClassLoader();
        }
        if (classLoader == null) {
            classLoader = getClass().getClassLoader();
        }

        // Load the previously unloaded active sessions
        synchronized (sessions) {
            try (ObjectInputStream ois = new CustomObjectInputStream(bis, classLoader, logger,
                    getSessionAttributeValueClassNamePattern(),
                    getWarnOnSessionAttributeFilterFailure())) {
                Integer count = (Integer) ois.readObject();
                int n = count.intValue();
                if (log.isDebugEnabled())
                    log.debug("Loading " + n + " persisted sessions");
                for (int i = 0; i < n; i++) {
                    StandardSession session = getNewSession();
                    session.readObjectData(ois);
                    session.setManager(this);
                    sessions.put(session.getIdInternal(), session);
                    session.activate();
                    if (!session.isValidInternal()) {
                        // If session is already invalid,
                        // expire session to prevent memory leak.
                        session.setValid(true);
                        session.expire();
                    }
                    sessionCounter++;
                }
            } finally {
                // Delete the persistent storage file
                if (file.exists()) {
                    if (!file.delete()) {
                        log.warn(sm.getString("standardManager.deletePersistedFileFail", file));
                    }
                }
            }
        }
    } catch (FileNotFoundException e) {
        if (log.isDebugEnabled()) {
            log.debug("No persisted data file found");
        }
        return;
    }

    if (log.isDebugEnabled()) {
        log.debug("Finish: Loading persisted sessions");
    }
}