@AfterClass public static void cleanup() { try { if (idpServer.getServer() != null && idpServer.getServer().getState() != LifecycleState.DESTROYED) { if (idpServer.getServer().getState() != LifecycleState.STOPPED) { idpServer.stop(); } idpServer.destroy(); } } catch (Exception e) { e.printStackTrace(); } try { if (rpServer.getServer() != null && rpServer.getServer().getState() != LifecycleState.DESTROYED) { if (rpServer.getServer().getState() != LifecycleState.STOPPED) { rpServer.stop(); } rpServer.destroy(); } } catch (Exception e) { e.printStackTrace(); } }
private void doRequest() throws Exception { Tomcat tomcat = getTomcatInstance(); Context root = tomcat.addContext("", TEMP_DIR); Tomcat.addServlet(root, "Simple", new SimpleServlet()); root.addServletMapping("/test", "Simple"); tomcat.start(); // Open connection setPort(tomcat.getConnector().getLocalPort()); connect(); String[] request = new String[1]; request[0] = "GET /test HTTP/1.0" + CRLF + "Cookie: " + COOKIE_WITH_NAME_ONLY_1 + CRLF + "Cookie: " + COOKIE_WITH_NAME_ONLY_2 + CRLF + CRLF; setRequest(request); processRequest(true); // blocks until response has been read String response = getResponseBody(); // Close the connection disconnect(); reset(); tomcat.stop(); // Need the extra equals since cookie 1 is just the name assertEquals(COOKIE_WITH_NAME_ONLY_1 + "=" + COOKIE_WITH_NAME_ONLY_2, response); }
@Test public void testFlagFailCtxIfServletStartFails() throws Exception { Tomcat tomcat = getTomcatInstance(); File docBase = new File(System.getProperty("java.io.tmpdir")); StandardContext context = (StandardContext) tomcat.addContext("", docBase.getAbsolutePath()); // first we test the flag itself, which can be set on the Host and // Context assertFalse(context.getComputedFailCtxIfServletStartFails()); StandardHost host = (StandardHost) tomcat.getHost(); host.setFailCtxIfServletStartFails(true); assertTrue(context.getComputedFailCtxIfServletStartFails()); context.setFailCtxIfServletStartFails(Boolean.FALSE); assertFalse( "flag on Context should override Host config", context.getComputedFailCtxIfServletStartFails()); // second, we test the actual effect of the flag on the startup Wrapper servlet = Tomcat.addServlet(context, "myservlet", new FailingStartupServlet()); servlet.setLoadOnStartup(1); tomcat.start(); assertTrue("flag false should not fail deployment", context.getState().isAvailable()); tomcat.stop(); assertFalse(context.getState().isAvailable()); host.removeChild(context); context = (StandardContext) tomcat.addContext("", docBase.getAbsolutePath()); servlet = Tomcat.addServlet(context, "myservlet", new FailingStartupServlet()); servlet.setLoadOnStartup(1); tomcat.start(); assertFalse("flag true should fail deployment", context.getState().isAvailable()); }
public static void main(String[] args) throws Exception { Tomcat tomcat = new Tomcat(); tomcat.addWebapp("/", Paths.get("src/main/webapp").toAbsolutePath().toString()); tomcat.start(); System.out.println("http://localhost:8080/rest/hello"); System.in.read(); tomcat.stop(); }
@Override public void destruct() { try { tomcat.stop(); } catch (LifecycleException e) { L.e("Failed to stop RestApiModule.", e); } }
@Override public void stop() { if (embedded != null) { try { wrapper.deallocate(getServlet()); embedded.stop(); log.info("Stopped embedded Tomcat server"); } catch (Exception e) { throw new AssertionError(e); } } }
/** Stop this MockServer instance */ public AbstractRunner<T> stop() { if (!isRunning()) throw new IllegalStateException( this.getClass().getSimpleName().replace("Runner", "") + " is not running"); try { serverStopped(); shutdownThread.stopListening(); tomcat.stop(); tomcat.getServer().await(); } catch (Exception e) { throw new RuntimeException( "Failed to stop embedded jetty server gracefully, stopping JVM", e); } return this; }
@After @Override public void tearDown() throws Exception { try { // Some tests may call tomcat.destroy(), some tests may just call // tomcat.stop(), some not call either method. Make sure that stop() // & destroy() are called as necessary. if (tomcat.server != null && tomcat.server.getState() != LifecycleState.DESTROYED) { if (tomcat.server.getState() != LifecycleState.STOPPED) { tomcat.stop(); } tomcat.destroy(); } } finally { super.tearDown(); } }
@AfterClass public static void shutdownTomcat() throws Exception { tomcat.stop(); tomcat.destroy(); }
@Override public void tearDown() throws Exception { tomcat.stop(); }
public void stopServer() throws Exception { tomcat.stop(); tomcat.getServer().await(); serverStopped(); }
public void stop() throws Exception { tomcat.stop(); tomcat.destroy(); FileUtil.deleteDir(webRoot); }
public static void stopServer(Object object) throws Exception { Tomcat tomcat = (Tomcat) object; tomcat.stop(); }