Java Code Examples for org.apache.catalina.core.StandardHost#findChildren()
The following examples show how to use
org.apache.catalina.core.StandardHost#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 |
private static boolean hasChild(final StandardHost host, final String name) { for (final Container child : host.findChildren()) { // the TomEERemoteWebapp path = "/" + name if (name.equals(child.getName()) || (StandardContext.class.isInstance(child) && ("/" + name).equals(StandardContext.class.cast(child).getPath()))) { return true; } } return false; }
Example 2
Source File: GlobalListenerSupport.java From tomee with Apache License 2.0 | 5 votes |
/** * Host is added. * * @param host tomcat host. */ private void hostAdded(final StandardHost host) { addContextListener(host); host.addLifecycleListener(this); for (final Container child : host.findChildren()) { if (child instanceof StandardContext) { final StandardContext context = (StandardContext) child; contextAdded(context); } } }
Example 3
Source File: GlobalListenerSupport.java From tomee with Apache License 2.0 | 5 votes |
/** * Host is removed. * * @param host tomcat host */ private void hostRemoved(final StandardHost host) { for (final Container child : host.findChildren()) { if (child instanceof StandardContext) { final StandardContext context = (StandardContext) child; contextRemoved(context); } } }
Example 4
Source File: StandardHostSF.java From Tomcat8-Source-Read with MIT License | 4 votes |
/** * 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); } }
Example 5
Source File: ManagedConnectorFactory.java From armeria with Apache License 2.0 | 4 votes |
private void checkConfiguration(StandardServer server, Service expectedService, Connector expectedConnector, Engine expectedEngine, StandardHost expectedHost, Context expectedContext) { // Check if Catalina base and home directories have not been changed. final File expectedBaseDir = config.baseDir().toFile(); if (!Objects.equals(server.getCatalinaBase(), expectedBaseDir) || !Objects.equals(server.getCatalinaHome(), expectedBaseDir)) { throw new TomcatServiceException("A configurator should never change the Catalina base and home."); } // Check if the server's port has not been changed. if (server.getPort() != EMBEDDED_TOMCAT_PORT) { throw new TomcatServiceException("A configurator should never change the port of the server."); } // Check if the default service has not been removed and a new service has not been added. final Service[] services = server.findServices(); if (services == null || services.length != 1 || services[0] != expectedService) { throw new TomcatServiceException( "A configurator should never remove the default service or add a new service."); } // Check if the name of the default service has not been changed. if (!config.serviceName().equals(expectedService.getName())) { throw new TomcatServiceException( "A configurator should never change the name of the default service."); } // Check if the default connector has not been removed final Connector[] connectors = expectedService.findConnectors(); if (connectors == null || Arrays.stream(connectors).noneMatch(c -> c == expectedConnector)) { throw new TomcatServiceException("A configurator should never remove the default connector."); } // Check if the engine has not been changed. final Container actualEngine = TomcatUtil.engine(expectedService, expectedHost.getName()); if (actualEngine != expectedEngine) { throw new TomcatServiceException( "A configurator should never change the engine of the default service."); } // Check if the engine's name has not been changed. if (!config.engineName().equals(expectedEngine.getName())) { throw new TomcatServiceException( "A configurator should never change the name of the default engine."); } // Check if the default realm has not been changed. if (expectedEngine.getRealm() != config.realm()) { throw new TomcatServiceException("A configurator should never change the default realm."); } // Check if the default host has not been removed. final Container[] engineChildren = expectedEngine.findChildren(); if (engineChildren == null || Arrays.stream(engineChildren).noneMatch(c -> c == expectedHost)) { throw new TomcatServiceException("A configurator should never remove the default host."); } // Check if the default context has not been removed. final Container[] contextChildren = expectedHost.findChildren(); if (contextChildren == null || Arrays.stream(contextChildren).noneMatch(c -> c == expectedContext)) { throw new TomcatServiceException("A configurator should never remove the default context."); } // Check if the docBase of the default context has not been changed. if (!config.docBase().toString().equals(expectedContext.getDocBase())) { throw new TomcatServiceException( "A configurator should never change the docBase of the default context."); } }