@Override public Connector apply(String hostname) { // Create the connector with our protocol handler. Tomcat will call ProtocolHandler.setAdapter() // on its startup with the Coyote Adapter which gives an access to Tomcat's HTTP service pipeline. final Class<?> protocolType = TomcatService.PROTOCOL_HANDLER_CLASS; final Connector connector = new Connector(protocolType.getName()); // We do not really open a port - just trying to stop the Connector from complaining. connector.setPort(0); final StandardServer server = newServer(hostname, connector, config); // Retrieve the components configured by newServer(), so we can use it in checkConfiguration(). final Service service = server.findServices()[0]; final Engine engine = TomcatUtil.engine(service, hostname); final StandardHost host = (StandardHost) engine.findChildren()[0]; final Context context = (Context) host.findChildren()[0]; // Apply custom configurators set via TomcatServiceBuilder.configurator() try { config.configurators().forEach(c -> c.accept(server)); } catch (Throwable t) { throw new TomcatServiceException("failed to configure an embedded Tomcat", t); } // Make sure the configurators did not ruin what we have configured in this method. checkConfiguration(server, service, connector, engine, host, context); assert connector.getService().getServer() != null; return connector; }
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.");
private boolean isContextExists(Context context) { // Is this Context actually among those that are defined? for (int i = 0; i < engines.length; i++) { Container hosts[] = engines[i].findChildren(); for (int j = 0; j < hosts.length; j++) { Container contexts[] = hosts[j].findChildren(); for (int k = 0; k < contexts.length; k++) { if (context == (Context) contexts[k]) { return true; } } } } return false; }
private void registerListenersForEngine(Engine engine) { for (Container hostContainer : engine.findChildren()) { Host host = (Host) hostContainer; host.addContainerListener(this); registerListenersForHost(host); } }
private void registerListenersForEngine(Engine engine) { for (Container hostContainer : engine.findChildren()) { Host host = (Host) hostContainer; host.addContainerListener(this); registerListenersForHost(host); } }
private void registerListenersForEngine(Engine engine) { for (Container hostContainer : engine.findChildren()) { Host host = (Host) hostContainer; host.addContainerListener(this); registerListenersForHost(host); } }
private void registerListenersForEngine(Engine engine) { for (Container hostContainer : engine.findChildren()) { Host host = (Host) hostContainer; host.addContainerListener(this); registerListenersForHost(host); } }
private void registerListenersForEngine(Engine engine) { for (Container hostContainer : engine.findChildren()) { Host host = (Host) hostContainer; host.addContainerListener(this); registerListenersForHost(host); } }
/** * Reconfigures the access log valve of each virtual server with the * updated attributes of the <access-log> element from domain.xml. */ public void updateAccessLog(HttpService httpService) { Container[] virtualServers = getEngine().findChildren(); for (Container virtualServer : virtualServers) { ((VirtualServer) virtualServer).reconfigureAccessLog( httpService, webContainerFeatureFactory); } }
private void registerListenersForEngine(Engine engine) { for (Container hostContainer : engine.findChildren()) { Host host = (Host) hostContainer; host.addContainerListener(this); registerListenersForHost(host); } }
private void registerListenersForEngine(Engine engine) { for (Container hostContainer : engine.findChildren()) { Host host = (Host) hostContainer; host.addContainerListener(this); registerListenersForHost(host); } }
private void registerListenersForEngine(Engine engine) { for (Container hostContainer : engine.findChildren()) { Host host = (Host) hostContainer; host.addContainerListener(this); registerListenersForHost(host); } }
public Host getHost() { Engine engine = getEngine(); if (engine.findChildren().length > 0) { return (Host) engine.findChildren()[0]; } Host host = new StandardHost(); host.setName(hostname); getEngine().addChild(host); return host; }
public Host getHost() { Engine engine = getEngine(); if (engine.findChildren().length > 0) { return (Host) engine.findChildren()[0]; } Host host = new StandardHost(); host.setName(hostname); getEngine().addChild(host); return host; }
void start() { ServletContainerFactory.registerContext(this); // Container[] childrenContainers = engine.findChildren(); for (Container childContainer : childrenContainers) { if (childContainer instanceof Host) { Host host = (Host)childContainer; registerHost(host); } } // engine.addContainerListener(this); }
private void check() { final StandardServer server = TomcatHelper.getServer(); for (final Service service : server.findServices()) { if (service.getContainer() instanceof Engine) { final Engine engine = (Engine) service.getContainer(); for (final Container engineChild : engine.findChildren()) { if (engineChild instanceof StandardHost) { final StandardHost host = (StandardHost) engineChild; webappBuilder.checkHost(host); } } } } }
private void check() { final StandardServer server = TomcatHelper.getServer(); for (final Service service : server.findServices()) { if (service.getContainer() instanceof Engine) { final Engine engine = (Engine) service.getContainer(); for (final Container engineChild : engine.findChildren()) { if (engineChild instanceof StandardHost) { final StandardHost host = (StandardHost) engineChild; webappBuilder.checkHost(host); } } } } }
@Test public void getHosts() { org.apache.catalina.Host host = mock(org.apache.catalina.Host.class); HostFactory hostFactory = mock(HostFactory.class); Host expected = mock(Host.class); when(this.engine.findChildren()).thenReturn(new Container[] { host }); when(this.registry.getHostFactory()).thenReturn(hostFactory); when(hostFactory.createHost(same(this.registry), same(host), same(this.catalinaEngine))).thenReturn(expected); Iterable<Host> result = this.catalinaEngine.getHosts(); Iterator<Host> hosts = result.iterator(); assertTrue(hosts.hasNext()); assertSame(expected, hosts.next()); assertFalse(hosts.hasNext()); }
@Override public void startInternal() throws LifecycleException { setState(LifecycleState.STARTING); // Find any components that have already been initialized since the // MBean listener won't be notified as those components will have // already registered their MBeans findDefaultHost(); Engine engine = (Engine) service.getContainer(); addListeners(engine); Container[] conHosts = engine.findChildren(); for (Container conHost : conHosts) { Host host = (Host) conHost; if (!LifecycleState.NEW.equals(host.getState())) { // Registering the host will register the context and wrappers registerHost(host); } } }
@Override public void startInternal() { setState(LifecycleState.STARTING); // Find any components that have already been initialized since the // MBean listener won't be notified as those components will have // already registered their MBeans findDefaultHost(); Engine engine = (Engine) connector.getService().getContainer(); addListeners(engine); Container[] conHosts = engine.findChildren(); for (Container conHost : conHosts) { Host host = (Host) conHost; if (!LifecycleState.NEW.equals(host.getState())) { // Registering the host will register the context and wrappers registerHost(host); } } }