Search in sources :

Example 96 with Context

use of org.apache.catalina.Context in project tomcat by apache.

the class MapperListener method registerWrapper.

/**
     * Register wrapper.
     */
private void registerWrapper(Wrapper wrapper) {
    Context context = (Context) wrapper.getParent();
    String contextPath = context.getPath();
    if ("/".equals(contextPath)) {
        contextPath = "";
    }
    String version = context.getWebappVersion();
    String hostName = context.getParent().getName();
    List<WrapperMappingInfo> wrappers = new ArrayList<>();
    prepareWrapperMappingInfo(context, wrapper, wrappers);
    mapper.addWrappers(hostName, contextPath, version, wrappers);
    if (log.isDebugEnabled()) {
        log.debug(sm.getString("mapperListener.registerWrapper", wrapper.getName(), contextPath, service));
    }
}
Also used : Context(org.apache.catalina.Context) ArrayList(java.util.ArrayList)

Example 97 with Context

use of org.apache.catalina.Context in project tomcat by apache.

the class ContextMBean method findFilterDef.

/**
     * Return the filter definition for the specified filter name, if any;
     * otherwise return <code>null</code>.
     *
     * @param name Filter name to look up
     * @return a string representation of the filter definition
     * @throws MBeanException propagated from the managed resource access
     */
public String findFilterDef(String name) throws MBeanException {
    Context context = doGetManagedResource();
    FilterDef filterDef = context.findFilterDef(name);
    return filterDef.toString();
}
Also used : Context(org.apache.catalina.Context) FilterDef(org.apache.tomcat.util.descriptor.web.FilterDef)

Example 98 with Context

use of org.apache.catalina.Context in project tomcat by apache.

the class ContextMBean method findFilterDefs.

/**
     * Return the set of defined filters for this Context.
     * @return a string array with a representation of all
     *  the filter definitions
     * @throws MBeanException propagated from the managed resource access
     */
public String[] findFilterDefs() throws MBeanException {
    Context context = doGetManagedResource();
    FilterDef[] filterDefs = context.findFilterDefs();
    String[] stringFilters = new String[filterDefs.length];
    for (int counter = 0; counter < filterDefs.length; counter++) {
        stringFilters[counter] = filterDefs[counter].toString();
    }
    return stringFilters;
}
Also used : Context(org.apache.catalina.Context) FilterDef(org.apache.tomcat.util.descriptor.web.FilterDef) SecurityConstraint(org.apache.tomcat.util.descriptor.web.SecurityConstraint)

Example 99 with Context

use of org.apache.catalina.Context in project tomcat by apache.

the class ManagerServlet method deploy.

/**
     * Install an application for the specified path from the specified
     * web application archive.
     *
     * @param writer    Writer to render results to
     * @param config    URL of the context configuration file to be installed
     * @param cn        Name of the application to be installed
     * @param war       URL of the web application archive to be installed
     * @param update    true to override any existing webapp on the path
     * @param smClient  i18n messages using the locale of the client
     */
protected void deploy(PrintWriter writer, String config, ContextName cn, String war, boolean update, StringManager smClient) {
    if (config != null && config.length() == 0) {
        config = null;
    }
    if (war != null && war.length() == 0) {
        war = null;
    }
    if (debug >= 1) {
        if (config != null && config.length() > 0) {
            if (war != null) {
                log("install: Installing context configuration at '" + config + "' from '" + war + "'");
            } else {
                log("install: Installing context configuration at '" + config + "'");
            }
        } else {
            if (cn != null) {
                log("install: Installing web application '" + cn + "' from '" + war + "'");
            } else {
                log("install: Installing web application from '" + war + "'");
            }
        }
    }
    if (!validateContextName(cn, writer, smClient)) {
        return;
    }
    // checked in call above
    @SuppressWarnings("null") String name = cn.getName();
    String baseName = cn.getBaseName();
    String displayPath = cn.getDisplayName();
    // If app exists deployment can only proceed if update is true
    // Note existing files will be deleted and then replaced
    Context context = (Context) host.findChild(name);
    if (context != null && !update) {
        writer.println(smClient.getString("managerServlet.alreadyContext", displayPath));
        return;
    }
    if (config != null && (config.startsWith("file:"))) {
        config = config.substring("file:".length());
    }
    if (war != null && (war.startsWith("file:"))) {
        war = war.substring("file:".length());
    }
    try {
        if (isServiced(name)) {
            writer.println(smClient.getString("managerServlet.inService", displayPath));
        } else {
            addServiced(name);
            try {
                if (config != null) {
                    if (!configBase.mkdirs() && !configBase.isDirectory()) {
                        writer.println(smClient.getString("managerServlet.mkdirFail", configBase));
                        return;
                    }
                    File localConfig = new File(configBase, baseName + ".xml");
                    if (localConfig.isFile() && !localConfig.delete()) {
                        writer.println(smClient.getString("managerServlet.deleteFail", localConfig));
                        return;
                    }
                    copy(new File(config), localConfig);
                }
                if (war != null) {
                    File localWar;
                    if (war.endsWith(".war")) {
                        localWar = new File(host.getAppBaseFile(), baseName + ".war");
                    } else {
                        localWar = new File(host.getAppBaseFile(), baseName);
                    }
                    if (localWar.exists() && !ExpandWar.delete(localWar)) {
                        writer.println(smClient.getString("managerServlet.deleteFail", localWar));
                        return;
                    }
                    copy(new File(war), localWar);
                }
                // Perform new deployment
                check(name);
            } finally {
                removeServiced(name);
            }
        }
        writeDeployResult(writer, smClient, name, displayPath);
    } catch (Throwable t) {
        ExceptionUtils.handleThrowable(t);
        log("ManagerServlet.install[" + displayPath + "]", t);
        writer.println(smClient.getString("managerServlet.exception", t.toString()));
    }
}
Also used : Context(org.apache.catalina.Context) ServletContext(javax.servlet.ServletContext) File(java.io.File)

Example 100 with Context

use of org.apache.catalina.Context in project tomcat by apache.

the class ManagerServlet method list.

/**
     * Render a list of the currently active Contexts in our virtual host.
     *
     * @param writer Writer to render to
     * @param smClient i18n support for current client's locale
     */
protected void list(PrintWriter writer, StringManager smClient) {
    if (debug >= 1)
        log("list: Listing contexts for virtual host '" + host.getName() + "'");
    writer.println(smClient.getString("managerServlet.listed", host.getName()));
    Container[] contexts = host.findChildren();
    for (int i = 0; i < contexts.length; i++) {
        Context context = (Context) contexts[i];
        if (context != null) {
            String displayPath = context.getPath();
            if (displayPath.equals(""))
                displayPath = "/";
            if (context.getState().isAvailable()) {
                writer.println(smClient.getString("managerServlet.listitem", displayPath, "running", "" + context.getManager().findSessions().length, context.getDocBase()));
            } else {
                writer.println(smClient.getString("managerServlet.listitem", displayPath, "stopped", "0", context.getDocBase()));
            }
        }
    }
}
Also used : Context(org.apache.catalina.Context) ServletContext(javax.servlet.ServletContext) Container(org.apache.catalina.Container)

Aggregations

Context (org.apache.catalina.Context)376 Tomcat (org.apache.catalina.startup.Tomcat)212 Test (org.junit.Test)180 TomcatBaseTest (org.apache.catalina.startup.TomcatBaseTest)127 ByteChunk (org.apache.tomcat.util.buf.ByteChunk)96 File (java.io.File)77 ServletContext (javax.servlet.ServletContext)74 AsyncContext (javax.servlet.AsyncContext)73 StandardContext (org.apache.catalina.core.StandardContext)65 Wrapper (org.apache.catalina.Wrapper)53 IOException (java.io.IOException)40 TesterContext (org.apache.tomcat.unittest.TesterContext)39 DefaultServlet (org.apache.catalina.servlets.DefaultServlet)37 URI (java.net.URI)33 WebSocketContainer (javax.websocket.WebSocketContainer)32 Session (javax.websocket.Session)31 Host (org.apache.catalina.Host)30 Container (org.apache.catalina.Container)26 ArrayList (java.util.ArrayList)25 ServletRequestWrapper (javax.servlet.ServletRequestWrapper)24