Search in sources :

Example 16 with Container

use of org.apache.catalina.Container 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 17 with Container

use of org.apache.catalina.Container 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 18 with Container

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

the class Tomcat method initWebappDefaults.

/**
     * Provide default configuration for a context. This is the programmatic
     * equivalent of the default web.xml.
     *
     *  TODO: in normal Tomcat, if default-web.xml is not found, use this
     *  method
     *
     * @param contextPath   The context to set the defaults for
     */
public void initWebappDefaults(String contextPath) {
    Container ctx = getHost().findChild(contextPath);
    initWebappDefaults((Context) ctx);
}
Also used : Container(org.apache.catalina.Container)

Example 19 with Container

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

the class WebAnnotationSet method loadApplicationServletAnnotations.

/**
     * Process the annotations for the servlets.
     * @param context The context which will have its annotations processed
     */
protected static void loadApplicationServletAnnotations(Context context) {
    Container[] children = context.findChildren();
    for (Container child : children) {
        if (child instanceof Wrapper) {
            Wrapper wrapper = (Wrapper) child;
            if (wrapper.getServletClass() == null) {
                continue;
            }
            Class<?> classClass = Introspection.loadClass(context, wrapper.getServletClass());
            if (classClass == null) {
                continue;
            }
            loadClassAnnotation(context, classClass);
            loadFieldsAnnotation(context, classClass);
            loadMethodsAnnotation(context, classClass);
            /* Process RunAs annotation which can be only on servlets.
                 * Ref JSR 250, equivalent to the run-as element in
                 * the deployment descriptor
                 */
            RunAs annotation = classClass.getAnnotation(RunAs.class);
            if (annotation != null) {
                wrapper.setRunAs(annotation.value());
            }
        }
    }
}
Also used : Wrapper(org.apache.catalina.Wrapper) Container(org.apache.catalina.Container) RunAs(javax.annotation.security.RunAs)

Example 20 with Container

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

the class StandardHostSF method storeChildren.

/**
     * Store the specified Host properties and children
     * (Listener,Alias,Realm,Valve,Cluster, Context)
     *
     * @param aWriter
     *            PrintWriter to which we are storing
     * @param indent
     *            Number of spaces to indent this element
     * @param aHost
     *            Host whose properties are being stored
     *
     * @exception Exception
     *                if an exception occurs while storing
     */
@Override
public void storeChildren(PrintWriter aWriter, int indent, Object aHost, StoreDescription parentDesc) throws Exception {
    if (aHost instanceof StandardHost) {
        StandardHost host = (StandardHost) aHost;
        // Store nested <Listener> elements
        LifecycleListener[] listeners = ((Lifecycle) host).findLifecycleListeners();
        storeElementArray(aWriter, indent, listeners);
        // Store nested <Alias> elements
        String[] aliases = host.findAliases();
        getStoreAppender().printTagArray(aWriter, "Alias", indent + 2, aliases);
        // Store nested <Realm> element
        Realm realm = host.getRealm();
        if (realm != null) {
            Realm parentRealm = null;
            if (host.getParent() != null) {
                parentRealm = host.getParent().getRealm();
            }
            if (realm != parentRealm) {
                storeElement(aWriter, indent, realm);
            }
        }
        // Store nested <Valve> elements
        Valve[] valves = host.getPipeline().getValves();
        if (valves != null && valves.length > 0) {
            List<Valve> hostValves = new ArrayList<>();
            for (int i = 0; i < valves.length; i++) {
                if (!(valves[i] instanceof ClusterValve))
                    hostValves.add(valves[i]);
            }
            storeElementArray(aWriter, indent, hostValves.toArray());
        }
        // store all <Cluster> elements
        Cluster cluster = host.getCluster();
        if (cluster != null) {
            Cluster parentCluster = null;
            if (host.getParent() != null) {
                parentCluster = host.getParent().getCluster();
            }
            if (cluster != parentCluster) {
                storeElement(aWriter, indent, cluster);
            }
        }
        // store all <Context> elements
        Container[] children = host.findChildren();
        storeElementArray(aWriter, indent, children);
    }
}
Also used : Lifecycle(org.apache.catalina.Lifecycle) ArrayList(java.util.ArrayList) Cluster(org.apache.catalina.Cluster) LifecycleListener(org.apache.catalina.LifecycleListener) ClusterValve(org.apache.catalina.ha.ClusterValve) Container(org.apache.catalina.Container) StandardHost(org.apache.catalina.core.StandardHost) ClusterValve(org.apache.catalina.ha.ClusterValve) Valve(org.apache.catalina.Valve) Realm(org.apache.catalina.Realm)

Aggregations

Container (org.apache.catalina.Container)125 Context (org.apache.catalina.Context)26 Host (org.apache.catalina.Host)20 Engine (org.apache.catalina.Engine)18 IOException (java.io.IOException)17 StandardContext (org.apache.catalina.core.StandardContext)17 ObjectName (javax.management.ObjectName)15 StandardHost (org.apache.catalina.core.StandardHost)13 Wrapper (org.apache.catalina.Wrapper)11 ArrayList (java.util.ArrayList)10 Valve (org.apache.catalina.Valve)10 SecurityConstraint (org.apache.tomcat.util.descriptor.web.SecurityConstraint)10 Realm (org.apache.catalina.Realm)9 File (java.io.File)8 LifecycleException (org.apache.catalina.LifecycleException)8 StandardWrapper (org.apache.catalina.core.StandardWrapper)8 ServletContext (javax.servlet.ServletContext)7 ServletException (javax.servlet.ServletException)7 Lifecycle (org.apache.catalina.Lifecycle)7 Service (org.apache.catalina.Service)7