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

The following examples show how to use org.apache.catalina.Context#reload() . 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: HostConfig.java    From Tomcat8-Source-Read with MIT License 6 votes vote down vote up
private void reload(DeployedApplication app, File fileToRemove, String newDocBase) {
    if(log.isInfoEnabled())
        log.info(sm.getString("hostConfig.reload", app.name));
    Context context = (Context) host.findChild(app.name);
    if (context.getState().isAvailable()) {
        if (fileToRemove != null && newDocBase != null) {
            context.addLifecycleListener(
                    new ExpandedDirectoryRemovalListener(fileToRemove, newDocBase));
        }
        // Reload catches and logs exceptions
        context.reload();
    } else {
        // If the context was not started (for example an error
        // in web.xml) we'll still get to try to start
        if (fileToRemove != null && newDocBase != null) {
            ExpandWar.delete(fileToRemove);
            context.setDocBase(newDocBase);
        }
        try {
            context.start();
        } catch (Exception e) {
            log.error(sm.getString("hostConfig.context.restart", app.name), e);
        }
    }
}
 
Example 2
Source File: HostConfig.java    From Tomcat7.0.67 with Apache License 2.0 6 votes vote down vote up
private void reload(DeployedApplication app, File fileToRemove, String newDocBase) {
    if(log.isInfoEnabled())
        log.info(sm.getString("hostConfig.reload", app.name));
    Context context = (Context) host.findChild(app.name);
    if (context.getState().isAvailable()) {
        if (fileToRemove != null && newDocBase != null) {
            context.addLifecycleListener(
                    new ExpandedDirectoryRemovalListener(fileToRemove, newDocBase));
        }
        // Reload catches and logs exceptions
        context.reload();
    } else {
        // If the context was not started (for example an error
        // in web.xml) we'll still get to try to start
        if (fileToRemove != null && newDocBase != null) {
            ExpandWar.delete(fileToRemove);
            context.setDocBase(newDocBase);
        }
        try {
            context.start();
        } catch (Exception e) {
            log.warn(sm.getString
                     ("hostConfig.context.restart", app.name), e);
        }
    }
}
 
Example 3
Source File: MeecrowaveRunMojo.java    From openwebbeans-meecrowave with Apache License 2.0 6 votes vote down vote up
private void reload(final Meecrowave meecrowave, final String context,
                    final Supplier<ClassLoader> loaderSupplier, final ClassLoader mojoLoader) {
    if (reloadGoals != null && !reloadGoals.isEmpty()) {
        final List<String> goals = session.getGoals();
        session.getRequest().setGoals(reloadGoals);
        try {
            lifecycleStarter.execute(session);
        } finally {
            session.getRequest().setGoals(goals);
        }
    }
    final Context ctx = Context.class.cast(meecrowave.getTomcat().getHost().findChild(context));
    if (useClasspathDeployment) {
        final Thread thread = Thread.currentThread();
        destroyTcclIfNeeded(thread, mojoLoader);
        thread.setContextClassLoader(loaderSupplier.get());
        ctx.setLoader(new ProvidedLoader(thread.getContextClassLoader(), meecrowave.getConfiguration().isTomcatWrapLoader()));
    }
    ctx.reload();
}
 
Example 4
Source File: ManagerServlet.java    From Tomcat8-Source-Read with MIT License 5 votes vote down vote up
/**
 * Reload the web application at the specified context path.
 *
 * @param writer Writer to render to
 * @param cn Name of the application to be restarted
 * @param smClient i18n support for current client's locale
 */
protected void reload(PrintWriter writer, ContextName cn,
        StringManager smClient) {

    if (debug >= 1)
        log("restart: Reloading web application '" + cn + "'");

    if (!validateContextName(cn, writer, smClient)) {
        return;
    }

    try {
        Context context = (Context) host.findChild(cn.getName());
        if (context == null) {
            writer.println(smClient.getString("managerServlet.noContext",
                    Escape.htmlElementContent(cn.getDisplayName())));
            return;
        }
        // It isn't possible for the manager to reload itself
        if (context.getName().equals(this.context.getName())) {
            writer.println(smClient.getString("managerServlet.noSelf"));
            return;
        }
        context.reload();
        writer.println(smClient.getString("managerServlet.reloaded",
                cn.getDisplayName()));
    } catch (Throwable t) {
        ExceptionUtils.handleThrowable(t);
        log("ManagerServlet.reload[" + cn.getDisplayName() + "]", t);
        writer.println(smClient.getString("managerServlet.exception",
                t.toString()));
    }

}
 
Example 5
Source File: ManagerServlet.java    From Tomcat7.0.67 with Apache License 2.0 5 votes vote down vote up
/**
 * Reload the web application at the specified context path.
 *
 * @param writer Writer to render to
 * @param cn Name of the application to be restarted
 */
protected void reload(PrintWriter writer, ContextName cn,
        StringManager smClient) {

    if (debug >= 1)
        log("restart: Reloading web application '" + cn + "'");

    if (!validateContextName(cn, writer, smClient)) {
        return;
    }

    try {
        Context context = (Context) host.findChild(cn.getName());
        if (context == null) {
            writer.println(smClient.getString("managerServlet.noContext",
                    RequestUtil.filter(cn.getDisplayName())));
            return;
        }
        // It isn't possible for the manager to reload itself
        if (context.getName().equals(this.context.getName())) {
            writer.println(smClient.getString("managerServlet.noSelf"));
            return;
        }
        context.reload();
        writer.println(smClient.getString("managerServlet.reloaded",
                cn.getDisplayName()));
    } catch (Throwable t) {
        ExceptionUtils.handleThrowable(t);
        log("ManagerServlet.reload[" + cn.getDisplayName() + "]", t);
        writer.println(smClient.getString("managerServlet.exception",
                t.toString()));
    }

}
 
Example 6
Source File: ManagerServlet.java    From tomcatsrc with Apache License 2.0 5 votes vote down vote up
/**
 * Reload the web application at the specified context path.
 *
 * @param writer Writer to render to
 * @param cn Name of the application to be restarted
 */
protected void reload(PrintWriter writer, ContextName cn,
        StringManager smClient) {

    if (debug >= 1)
        log("restart: Reloading web application '" + cn + "'");

    if (!validateContextName(cn, writer, smClient)) {
        return;
    }

    try {
        Context context = (Context) host.findChild(cn.getName());
        if (context == null) {
            writer.println(smClient.getString("managerServlet.noContext",
                    RequestUtil.filter(cn.getDisplayName())));
            return;
        }
        // It isn't possible for the manager to reload itself
        if (context.getName().equals(this.context.getName())) {
            writer.println(smClient.getString("managerServlet.noSelf"));
            return;
        }
        context.reload();
        writer.println(smClient.getString("managerServlet.reloaded",
                cn.getDisplayName()));
    } catch (Throwable t) {
        ExceptionUtils.handleThrowable(t);
        log("ManagerServlet.reload[" + cn.getDisplayName() + "]", t);
        writer.println(smClient.getString("managerServlet.exception",
                t.toString()));
    }

}