Search in sources :

Example 6 with Context

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

the class DefaultServlet method validateGlobalXsltFile.

private File validateGlobalXsltFile() {
    Context context = resources.getContext();
    File baseConf = new File(context.getCatalinaBase(), "conf");
    File result = validateGlobalXsltFile(baseConf);
    if (result == null) {
        File homeConf = new File(context.getCatalinaHome(), "conf");
        if (!baseConf.equals(homeConf)) {
            result = validateGlobalXsltFile(homeConf);
        }
    }
    return result;
}
Also used : Context(org.apache.catalina.Context) ServletContext(javax.servlet.ServletContext) RandomAccessFile(java.io.RandomAccessFile) File(java.io.File)

Example 7 with Context

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

the class MBeanFactory method removeLoader.

/**
     * Remove an existing Loader.
     *
     * @param name MBean Name of the component to remove
     *
     * @exception Exception if a component cannot be removed
     */
public void removeLoader(String name) throws Exception {
    ObjectName oname = new ObjectName(name);
    // Acquire a reference to the component to be removed
    Container container = getParentContainerFromChild(oname);
    if (container instanceof Context) {
        ((Context) container).setLoader(null);
    }
}
Also used : Context(org.apache.catalina.Context) StandardContext(org.apache.catalina.core.StandardContext) Container(org.apache.catalina.Container) ObjectName(javax.management.ObjectName)

Example 8 with Context

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

the class MBeanUtils method createObjectName.

/**
     * Create an <code>ObjectName</code> for this
     * <code>ContextResourceLink</code> object.
     *
     * @param domain Domain in which this name is to be created
     * @param resourceLink The ContextResourceLink to be named
     * @return a new object name
     * @exception MalformedObjectNameException if a name cannot be created
     */
public static ObjectName createObjectName(String domain, ContextResourceLink resourceLink) throws MalformedObjectNameException {
    ObjectName name = null;
    String quotedResourceLinkName = ObjectName.quote(resourceLink.getName());
    Object container = resourceLink.getNamingResources().getContainer();
    if (container instanceof Server) {
        name = new ObjectName(domain + ":type=ResourceLink" + ",resourcetype=Global" + ",name=" + quotedResourceLinkName);
    } else if (container instanceof Context) {
        Context context = ((Context) container);
        ContextName cn = new ContextName(context.getName(), false);
        Container host = context.getParent();
        name = new ObjectName(domain + ":type=ResourceLink" + ",resourcetype=Context,host=" + host.getName() + ",context=" + cn.getDisplayName() + ",name=" + quotedResourceLinkName);
    }
    return (name);
}
Also used : Context(org.apache.catalina.Context) Container(org.apache.catalina.Container) MBeanServer(javax.management.MBeanServer) Server(org.apache.catalina.Server) ObjectName(javax.management.ObjectName) ContextName(org.apache.catalina.util.ContextName)

Example 9 with Context

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

the class MBeanUtils method createObjectName.

/**
     * Create an <code>ObjectName</code> for this
     * <code>ContextResource</code> object.
     *
     * @param domain Domain in which this name is to be created
     * @param resource The ContextResource to be named
     * @return a new object name
     * @exception MalformedObjectNameException if a name cannot be created
     */
public static ObjectName createObjectName(String domain, ContextResource resource) throws MalformedObjectNameException {
    ObjectName name = null;
    String quotedResourceName = ObjectName.quote(resource.getName());
    Object container = resource.getNamingResources().getContainer();
    if (container instanceof Server) {
        name = new ObjectName(domain + ":type=Resource" + ",resourcetype=Global,class=" + resource.getType() + ",name=" + quotedResourceName);
    } else if (container instanceof Context) {
        Context context = ((Context) container);
        ContextName cn = new ContextName(context.getName(), false);
        Container host = context.getParent();
        name = new ObjectName(domain + ":type=Resource" + ",resourcetype=Context,host=" + host.getName() + ",context=" + cn.getDisplayName() + ",class=" + resource.getType() + ",name=" + quotedResourceName);
    }
    return (name);
}
Also used : Context(org.apache.catalina.Context) Container(org.apache.catalina.Container) MBeanServer(javax.management.MBeanServer) Server(org.apache.catalina.Server) ObjectName(javax.management.ObjectName) ContextName(org.apache.catalina.util.ContextName)

Example 10 with Context

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

the class UserConfig method deploy.

/**
     * Deploy a web application for the specified user if they have such an
     * application in the defined directory within their home directory.
     *
     * @param user Username owning the application to be deployed
     * @param home Home directory of this user
     */
private void deploy(String user, String home) {
    // Does this user have a web application to be deployed?
    String contextPath = "/~" + user;
    if (host.findChild(contextPath) != null)
        return;
    File app = new File(home, directoryName);
    if (!app.exists() || !app.isDirectory())
        return;
    host.getLogger().info(sm.getString("userConfig.deploy", user));
    // Deploy the web application for this user
    try {
        Class<?> clazz = Class.forName(contextClass);
        Context context = (Context) clazz.newInstance();
        context.setPath(contextPath);
        context.setDocBase(app.toString());
        clazz = Class.forName(configClass);
        LifecycleListener listener = (LifecycleListener) clazz.newInstance();
        context.addLifecycleListener(listener);
        host.addChild(context);
    } catch (Exception e) {
        host.getLogger().error(sm.getString("userConfig.error", user), e);
    }
}
Also used : Context(org.apache.catalina.Context) LifecycleListener(org.apache.catalina.LifecycleListener) File(java.io.File)

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