Search in sources :

Example 51 with Container

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

the class TomcatWebAppBuilder method ensureMyFacesDontLooseFacesContext.

private void ensureMyFacesDontLooseFacesContext(final StandardContext standardContext) {
    for (final Container w : standardContext.findChildren()) {
        if (!Wrapper.class.isInstance(w)) {
            continue;
        }
        final Wrapper wrapper = Wrapper.class.cast(w);
        if ("FacesServlet".equals(wrapper.getName()) && "javax.faces.webapp.FacesServlet".equals(wrapper.getServletClass())) {
            final ClassLoader loader = standardContext.getLoader().getClassLoader();
            try {
                if (Files.toFile(loader.getResource("javax/faces/webapp/FacesServlet.class")).getName().startsWith("myfaces")) {
                    loader.loadClass("org.apache.tomee.myfaces.TomEEWorkaroundFacesServlet");
                    wrapper.setServletClass("org.apache.tomee.myfaces.TomEEWorkaroundFacesServlet");
                    break;
                }
            } catch (final Throwable t) {
            // not there, not a big deal in most of cases
            }
        }
    }
}
Also used : StandardWrapper(org.apache.catalina.core.StandardWrapper) Wrapper(org.apache.catalina.Wrapper) Container(org.apache.catalina.Container)

Example 52 with Container

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

the class TomcatWebAppBuilder method manageCluster.

private void manageCluster(final Cluster cluster) {
    if (cluster == null || cluster instanceof SimpleTomEETcpCluster) {
        return;
    }
    Cluster current = cluster;
    if (cluster instanceof SimpleTcpCluster) {
        final Container container = cluster.getContainer();
        current = new SimpleTomEETcpCluster((SimpleTcpCluster) cluster);
        container.setCluster(current);
    }
    if (current instanceof CatalinaCluster) {
        final CatalinaCluster haCluster = (CatalinaCluster) current;
        TomEEClusterListener listener = SystemInstance.get().getComponent(TomEEClusterListener.class);
        if (listener == null) {
            listener = new TomEEClusterListener();
            SystemInstance.get().setComponent(TomEEClusterListener.class, listener);
        }
        // better to be a singleton
        haCluster.addClusterListener(listener);
        clusters.add(haCluster);
    }
}
Also used : Container(org.apache.catalina.Container) CatalinaCluster(org.apache.catalina.ha.CatalinaCluster) SimpleTcpCluster(org.apache.catalina.ha.tcp.SimpleTcpCluster) TomEEClusterListener(org.apache.tomee.catalina.cluster.TomEEClusterListener) Cluster(org.apache.catalina.Cluster) CatalinaCluster(org.apache.catalina.ha.CatalinaCluster) SimpleTcpCluster(org.apache.catalina.ha.tcp.SimpleTcpCluster)

Example 53 with Container

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

the class Contexts method getHostname.

public static String getHostname(final StandardContext ctx) {
    String hostName = null;
    final Container parentHost = ctx.getParent();
    if (parentHost != null) {
        hostName = parentHost.getName();
    }
    if ((hostName == null) || (hostName.length() < 1)) {
        hostName = "_";
    }
    return hostName;
}
Also used : Container(org.apache.catalina.Container)

Example 54 with Container

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

the class Contexts method realWarPath.

public static File realWarPath(final Context standardContext) {
    if (standardContext == null) {
        return null;
    }
    final File docBase;
    Container container = standardContext;
    while (container != null) {
        if (container instanceof Host) {
            break;
        }
        container = container.getParent();
    }
    String baseName = null;
    if (standardContext.getDocBase() != null) {
        File file = new File(standardContext.getDocBase());
        if (!file.isAbsolute()) {
            if (container == null) {
                docBase = new File(engineBase(standardContext), standardContext.getDocBase());
            } else {
                final String appBase = ((Host) container).getAppBase();
                file = new File(appBase);
                if (!file.isAbsolute()) {
                    file = new File(engineBase(standardContext), appBase);
                }
                docBase = new File(file, standardContext.getDocBase());
            }
        } else {
            docBase = file;
        }
    } else {
        final String path = standardContext.getPath();
        if (path == null) {
            throw new IllegalStateException("Can't find docBase");
        } else {
            baseName = new ContextName(path, standardContext.getWebappVersion()).getBaseName();
            docBase = new File(baseName);
        }
    }
    if (!docBase.exists() && baseName != null) {
        // for old compatibility, will be removed soon
        if (Host.class.isInstance(container)) {
            final File file = new File(Host.class.cast(container).getAppBaseFile(), baseName);
            if (file.exists()) {
                return file;
            }
        }
        return oldRealWarPath(standardContext);
    }
    final String name = docBase.getName();
    if (name.endsWith(".war")) {
        final File extracted = new File(docBase.getParentFile(), name.substring(0, name.length() - ".war".length()));
        if (extracted.exists()) {
            return extracted;
        }
    }
    return docBase;
}
Also used : Container(org.apache.catalina.Container) Host(org.apache.catalina.Host) StandardHost(org.apache.catalina.core.StandardHost) File(java.io.File) ContextName(org.apache.catalina.util.ContextName)

Example 55 with Container

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

the class TomEEMyFacesContainerInitializer method isFacesServletPresent.

private boolean isFacesServletPresent(final ServletContext ctx) {
    if (ctx instanceof ApplicationContextFacade) {
        try {
            final ApplicationContext appCtx = (ApplicationContext) get(ApplicationContextFacade.class, ctx);
            final Context tomcatCtx = (Context) get(ApplicationContext.class, appCtx);
            if (tomcatCtx instanceof StandardContext) {
                final Container[] servlets = tomcatCtx.findChildren();
                if (servlets != null) {
                    for (final Container s : servlets) {
                        if (s instanceof Wrapper) {
                            if ("javax.faces.webapp.FacesServlet".equals(((Wrapper) s).getServletClass()) || "Faces Servlet".equals(s.getName())) {
                                return true;
                            }
                        }
                    }
                }
            }
        } catch (final Exception e) {
        // no-op
        }
    }
    return false;
}
Also used : ApplicationContext(org.apache.catalina.core.ApplicationContext) Context(org.apache.catalina.Context) ServletContext(javax.servlet.ServletContext) StandardContext(org.apache.catalina.core.StandardContext) Wrapper(org.apache.catalina.Wrapper) ApplicationContext(org.apache.catalina.core.ApplicationContext) Container(org.apache.catalina.Container) ApplicationContextFacade(org.apache.catalina.core.ApplicationContextFacade) StandardContext(org.apache.catalina.core.StandardContext) ServletException(javax.servlet.ServletException)

Aggregations

Container (org.apache.catalina.Container)163 Context (org.apache.catalina.Context)28 IOException (java.io.IOException)24 Host (org.apache.catalina.Host)22 StandardContext (org.apache.catalina.core.StandardContext)21 Engine (org.apache.catalina.Engine)18 LifecycleException (org.apache.catalina.LifecycleException)17 File (java.io.File)15 ObjectName (javax.management.ObjectName)15 Wrapper (org.apache.catalina.Wrapper)13 StandardHost (org.apache.catalina.core.StandardHost)13 ArrayList (java.util.ArrayList)12 ServletException (javax.servlet.ServletException)11 MalformedURLException (java.net.MalformedURLException)10 Valve (org.apache.catalina.Valve)10 StandardWrapper (org.apache.catalina.core.StandardWrapper)10 SecurityConstraint (org.apache.tomcat.util.descriptor.web.SecurityConstraint)10 NamingException (javax.naming.NamingException)9 Lifecycle (org.apache.catalina.Lifecycle)9 Realm (org.apache.catalina.Realm)9