@Override public void stop() throws Exception { this.tomcatServer.stop(); this.port = 0; }
private void configureTomcat(Tomcat tomcat, Connector connector) { tomcat.setBaseDir(noSuchBaseDir.toAbsolutePath().toString()); tomcat.setConnector(connector); }
@Override protected void initServer() throws Exception { this.tomcatServer = new Tomcat(); this.tomcatServer.setBaseDir(baseDir); this.tomcatServer.setHostname(getHost()); this.tomcatServer.setPort(getPort()); ServletHttpHandlerAdapter servlet = initServletAdapter(); File base = new File(System.getProperty("java.io.tmpdir")); Context rootContext = tomcatServer.addContext(this.contextPath, base.getAbsolutePath()); Tomcat.addServlet(rootContext, "httpHandlerServlet", servlet).setAsyncSupported(true); rootContext.addServletMappingDecoded(this.servletMapping, "httpHandlerServlet"); if (wsListener != null) { rootContext.addApplicationListener(wsListener.getName()); } }
@Override public void setup() { Connector connector = new Connector(Http11NioProtocol.class.getName()); connector.setPort(0); File baseDir = createTempDir("tomcat"); String baseDirPath = baseDir.getAbsolutePath(); this.tomcatServer = new Tomcat(); this.tomcatServer.setBaseDir(baseDirPath); this.tomcatServer.setPort(0); this.tomcatServer.getService().addConnector(connector); this.tomcatServer.setConnector(connector); }
@Override protected void startInternal() throws LifecycleException { this.tomcatServer.start(); setPort(this.tomcatServer.getConnector().getLocalPort()); }
void awaitTermination() { tomcat.getServer().await(); } }
@Override public int getPort() { Connector connector = this.tomcat.getConnector(); if (connector != null) { return connector.getLocalPort(); } return 0; }
@Override public void undeployConfig() { if (this.context != null) { this.context.removeServletMapping("/"); this.tomcatServer.getHost().removeChild(this.context); } }
static void configure(Tomcat tomcat, Props props) { Connector httpConnector = newHttpConnector(props); tomcat.getService().addConnector(httpConnector); }
/** * Starts the embedded Tomcat server. */ public void startContainer() throws LifecycleException { // start server container.start(); // add shutdown hook to stop server Runtime.getRuntime().addShutdownHook(new Thread() { @Override public void run() { stopContainer(); } }); }
@Override public void start() throws Exception { this.tomcatServer.start(); this.port = this.tomcatServer.getConnector().getLocalPort(); this.context.addLifecycleListener(event -> { if (logger.isDebugEnabled()) { logger.debug("Event: " + event.getType()); } }); }
@AfterClass(alwaysRun = true) public void tearDownGlobal() throws Exception { tomcat.stop(); }
/** * Blocks and waits until the server shuts down. */ public void await() { Server server; synchronized (this) { server = tomcat.getServer(); } server.await(); // Can't do this with lock held }
@AfterClass(alwaysRun = true) public void tearDownGlobal() throws Exception { tomcat.stop(); executor.shutdown(); }
@Override public void run() { TomcatWebServer.this.tomcat.getServer().await(); }
@Override public void close() { super.close(); ServletManager.getInstance().removeServletContext(url.getPort()); try { tomcat.stop(); } catch (Exception e) { logger.warn(e.getMessage(), e); } } }
@Override public void close() { super.close(); ServletManager.getInstance().removeServletContext(url.getPort()); try { tomcat.stop(); } catch (Exception e) { logger.warn(e.getMessage(), e); } } }