Java Code Examples for org.apache.catalina.core.StandardEngine#findChildren()

The following examples show how to use org.apache.catalina.core.StandardEngine#findChildren() . 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: GlobalListenerSupport.java    From tomee with Apache License 2.0 5 votes vote down vote up
/**
 * Engine is added.
 *
 * @param engine tomcat engine
 */
private void engineAdded(final StandardEngine engine) {
    addContextListener(engine);
    for (final Container child : engine.findChildren()) {
        if (child instanceof StandardHost) {
            final StandardHost host = (StandardHost) child;
            hostAdded(host);
        }
    }
}
 
Example 2
Source File: GlobalListenerSupport.java    From tomee with Apache License 2.0 5 votes vote down vote up
/**
 * Engine is removed.
 *
 * @param engine tomcat engine
 */
private void engineRemoved(final StandardEngine engine) {
    for (final Container child : engine.findChildren()) {
        if (child instanceof StandardHost) {
            final StandardHost host = (StandardHost) child;
            hostRemoved(host);
        }
    }
}
 
Example 3
Source File: OpenEJBListener.java    From tomee with Apache License 2.0 5 votes vote down vote up
private static File tryToFindAndExtractWar(final StandardServer source) {
    if (System.getProperties().containsKey("openejb.war")) {
        return new File(System.getProperty("openejb.war"));
    }

    for (final Service service : source.findServices()) {
        final Container container = service.getContainer();
        if (container instanceof StandardEngine) {
            final StandardEngine engine = (StandardEngine) container;
            for (final Container child : engine.findChildren()) {
                if (child instanceof StandardHost) {
                    final StandardHost host = (StandardHost) child;
                    final File base = hostDir(System.getProperty("catalina.base"), host.getAppBase());

                    final File[] files = base.listFiles();
                    if (files != null) {
                        for (final File file : files) {
                            if (isTomEEWar(file)) {
                                return file;
                            }
                        }
                    }
                }
            }
        }
    }

    return null;
}
 
Example 4
Source File: OpenEJBListener.java    From tomee with Apache License 2.0 5 votes vote down vote up
private static File findOpenEjbWar() {
    // in Tomcat 5.5 the OpenEjb war is in the server/webapps director
    final String catalinaBase = System.getProperty("catalina.base");
    final File serverWebapps = new File(catalinaBase, "server/webapps");
    File openEjbWar = findOpenEjbWar(serverWebapps);
    if (openEjbWar != null) {
        return openEjbWar;
    }

    try {
        // in Tomcat 6 the OpenEjb war is normally in webapps, but we just
        // scan all hosts directories
        for (final Service service : TomcatHelper.getServer().findServices()) {
            final Container container = service.getContainer();
            if (container instanceof StandardEngine) {
                final StandardEngine engine = (StandardEngine) container;
                for (final Container child : engine.findChildren()) {
                    if (child instanceof StandardHost) {
                        final StandardHost host = (StandardHost) child;
                        final File hostDir = hostDir(catalinaBase, host.getAppBase());

                        openEjbWar = findOpenEjbWar(hostDir);
                        if (openEjbWar != null) {
                            return openEjbWar;
                        } else {
                            return findOpenEjbWar(host);
                        }
                    }
                }
            }
        }
    } catch (final Exception e) {
        LOGGER.log(Level.WARNING, "OpenEJBListener.findOpenEjbWar: {0}", e.getMessage());
    }

    return null;
}
 
Example 5
Source File: StandardEngineSF.java    From Tomcat8-Source-Read with MIT License 4 votes vote down vote up
/**
 * Store the specified Engine properties.
 *
 * @param aWriter
 *            PrintWriter to which we are storing
 * @param indent
 *            Number of spaces to indent this element
 * @param aEngine
 *            Object whose properties are being stored
 *
 * @exception Exception
 *                if an exception occurs while storing
 */
@Override
public void storeChildren(PrintWriter aWriter, int indent, Object aEngine,
        StoreDescription parentDesc) throws Exception {
    if (aEngine instanceof StandardEngine) {
        StandardEngine engine = (StandardEngine) aEngine;
        // Store nested <Listener> elements
        LifecycleListener listeners[] = ((Lifecycle) engine)
                .findLifecycleListeners();
        storeElementArray(aWriter, indent, listeners);

        // Store nested <Realm> element
        Realm realm = engine.getRealm();
        Realm parentRealm = null;
        // TODO is this case possible? (see it a old Server 5.0 impl)
        if (engine.getParent() != null) {
            parentRealm = engine.getParent().getRealm();
        }
        if (realm != parentRealm) {
            storeElement(aWriter, indent, realm);

        }

        // Store nested <Valve> elements
        Valve valves[] = engine.getPipeline().getValves();
        if(valves != null && valves.length > 0 ) {
            List<Valve> engineValves = new ArrayList<>() ;
            for(int i = 0 ; i < valves.length ; i++ ) {
                if(!( valves[i] instanceof ClusterValve))
                    engineValves.add(valves[i]);
            }
            storeElementArray(aWriter, indent, engineValves.toArray());
        }

        // store all <Cluster> elements
        Cluster cluster = engine.getCluster();
        if (cluster != null) {
            storeElement(aWriter, indent, cluster);
        }
        // store all <Host> elements
        Container children[] = engine.findChildren();
        storeElementArray(aWriter, indent, children);

   }
}