@Override public String hostName() { if (hostName != null) { return hostName; } // If connector w/o hostName return tomcat.map(t -> t.getEngine().getDefaultHost()) .orElse(null); } }
private void addInstanceIdToEngineName() { int instanceId = containerCounter.incrementAndGet(); if (instanceId > 0) { Engine engine = this.tomcat.getEngine(); engine.setName(engine.getName() + "-" + instanceId); } }
public synchronized void start() throws IOException { if (id != null) { log.info("Starting Serving Layer {}", id); } Preconditions.checkState(tomcat == null); // Has to happen very early before Tomcat init: System.setProperty("org.apache.tomcat.util.buf.UDecoder.ALLOW_ENCODED_SLASH", "true"); noSuchBaseDir = Files.createTempDirectory("Oryx"); noSuchBaseDir.toFile().deleteOnExit(); Tomcat tomcat = new Tomcat(); Connector connector = makeConnector(); configureTomcat(tomcat, connector); configureEngine(tomcat.getEngine()); configureServer(tomcat.getServer()); configureHost(tomcat.getHost()); makeContext(tomcat, noSuchBaseDir); try { tomcat.start(); } catch (LifecycleException le) { throw new IOException(le); } this.tomcat = tomcat; }
@Test public void verifySingleConnector() { // Relevant to Tomcat 9.0 assertThat(applicationContext).isInstanceOf(WebServerApplicationContext.class); WebServer webServer = ((WebServerApplicationContext) applicationContext).getWebServer(); assertThat(webServer).isInstanceOf(TomcatWebServer.class); assertThat(((TomcatWebServer) webServer).getTomcat() .getEngine() .getService() .findConnectors()).hasSize(1); }
@Override public WebServer getWebServer(HttpHandler httpHandler) { Tomcat tomcat = new Tomcat(); File baseDir = (this.baseDirectory != null) ? this.baseDirectory : createTempDir("tomcat"); tomcat.setBaseDir(baseDir.getAbsolutePath()); Connector connector = new Connector(this.protocol); tomcat.getService().addConnector(connector); customizeConnector(connector); tomcat.setConnector(connector); tomcat.getHost().setAutoDeploy(false); configureEngine(tomcat.getEngine()); TomcatHttpHandlerAdapter servlet = new TomcatHttpHandlerAdapter(httpHandler); prepareContext(tomcat.getHost(), servlet); return new TomcatWebServer(tomcat, getPort() >= 0); }
@Override public WebServer getWebServer(ServletContextInitializer... initializers) { Tomcat tomcat = new Tomcat(); File baseDir = (this.baseDirectory != null) ? this.baseDirectory : createTempDir("tomcat"); tomcat.setBaseDir(baseDir.getAbsolutePath()); Connector connector = new Connector(this.protocol); tomcat.getService().addConnector(connector); customizeConnector(connector); tomcat.setConnector(connector); tomcat.getHost().setAutoDeploy(false); configureEngine(tomcat.getEngine()); for (Connector additionalConnector : this.additionalTomcatConnectors) { tomcat.getService().addConnector(additionalConnector); } prepareContext(tomcat.getHost(), initializers); return getTomcatWebServer(tomcat); }
public void setDefaultHost(String defaultHostName) { tomcat.setHostname(defaultHostName); tomcat.getEngine().setDefaultHost(defaultHostName); }
/** * Sets the current host - all future webapps will * be added to this host. When tomcat starts, the * host will be the default host. * * @param host The current host */ public void setHost(Host host) { Engine engine = getEngine(); boolean found = false; for (Container engineHost : engine.findChildren()) { if (engineHost == host) { found = true; } } if (!found) { engine.addChild(host); } }
public Host getHost() { if (host == null) { host = new StandardHost(); host.setName(hostname); getEngine().addChild( host ); } return host; }
public Host getHost() { if (host == null) { host = new StandardHost(); host.setName(hostname); getEngine().addChild( host ); } return host; }
private Engine prepareTomcatEngine(Tomcat tomcat, Property engineConfig) { Engine engine = tomcat.getEngine(); engine.setName(engineConfig.name); // set the JVM Route property (JK/JK2) String jvmRoute = ContainerConfig.getPropertyValue(engineConfig, "jvm-route", null); if (jvmRoute != null) { engine.setJvmRoute(jvmRoute); } return engine; }
private Host prepareVirtualHost(Tomcat tomcat, List<String> virtualHosts) { // assume that the first virtual-host will be the default; additional virtual-hosts will be aliases String hostName = virtualHosts.get(0); Host host; Engine engine = tomcat.getEngine(); org.apache.catalina.Container childContainer = engine.findChild(hostName); if (childContainer instanceof Host) { host = (Host) childContainer; } else { host = new StandardHost(); host.setName(hostName); engine.addChild(host); } virtualHosts.stream() .filter(virtualHost -> virtualHost != hostName) .forEach(virtualHost -> host.addAlias(virtualHost)); return host; }
public Host getHost() { if (host == null) { host = new StandardHost(); host.setName(hostname); getEngine().addChild( host ); } return host; }
public Host getHost() { if (host == null) { host = new StandardHost(); host.setName(hostname); getEngine().addChild( host ); } return host; }
public Host getHost() { if (host == null) { host = new StandardHost(); host.setName(hostname); getEngine().addChild( host ); } return host; }
public Host getHost() { if (host == null) { host = new StandardHost(); host.setName(hostname); getEngine().addChild( host ); } return host; }
public void run(CompletableFuture start, JaxRsServletConfigurer jaxRsConfigurer, CompletableFuture end) { Tomcat tomcat = new Tomcat(); tomcat.setPort(serverData.getPort()); tomcat.getHost().setAutoDeploy(false); tomcat.getEngine().setBackgroundProcessorDelay(-1); File docBase = new File("."); StandardContext context =(StandardContext)tomcat.addContext("", docBase.getAbsolutePath()); context.addServletContainerInitializer(new TomcatListener(jaxRsConfigurer, serverData, filterData, servletData, servletContextListenerData, servletRequestListenerData), new HashSet<>()); addAccessLog(tomcat,context); serverData.getModule().getServerConfigManager().accept(new WebServerProvider(tomcat)); addSSL(tomcat.getConnector()); startServer(tomcat, start, end); }
public static Host addHostToEngine(String hostName) { String hostBaseDir = CarbonUtils.getCarbonRepository() + "/webapps/"; CarbonTomcatService carbonTomcatService = DataHolder.getInstance().getCarbonTomcatService(); // adding virtual host to tomcat engine Engine engine = carbonTomcatService.getTomcat().getEngine(); StandardHost host = new StandardHost(); host.setAppBase(hostBaseDir); host.setName(hostName); host.setUnpackWARs(false); host.addValve(new CarbonContextCreatorValve()); host.addValve(new CompositeValve()); engine.addChild(host); log.info("host added to the tomcat: " + host); return host; }