Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I dont know if this fits your needs but it actually worked for my app. The listener is called at application start, if it is declared in your web.xml:</p> <pre><code>&lt;listener&gt; &lt;listener-class&gt;your.package.TestServletListener&lt;/listener-class&gt; &lt;/listener&gt; </code></pre> <p>There you can do testing and call the ShutdownThread if one fails. It will connect to Tomcats shutdown port and send the shutdown command as a String:</p> <pre><code>public class TestServletListener implements ServletContextListener { @Override public void contextInitialized(ServletContextEvent arg0) { System.out.println("Starting app, running 5 tests ..."); // do tests ... for (int i = 0; i &lt; 5; i++) { System.out.println("testing ... " + i); waitFor(1000); } // If a test failed call: System.out.println("test failed!"); new ShutdownTask().start(); } @Override public void contextDestroyed(ServletContextEvent arg0) { System.out.print("Stopping app, cleaning up (takes 3 sec) ... "); waitFor(3000); System.out.println("done"); } private void waitFor(int i) { try { Thread.sleep(i); } catch (InterruptedException e) { e.printStackTrace(); } } class ShutdownTask extends Thread { @Override public void run() { try { Socket s = new Socket("127.0.0.1", 8015); PrintStream os = new PrintStream(s.getOutputStream()); os.println("shutdown"); s.close(); System.out.println("Shutting down server ..."); } catch (IOException e) { e.printStackTrace(); } } } } </code></pre> <p>You need to make sure that the shutdown port and shutdown command are in sync with your Tomcats server.xml:</p> <pre><code>... &lt;Server port="8015" shutdown="shutdown"&gt; ... </code></pre> <p>For example, you could pass them as context parameters in your web.xml. Like System.exit(...) this is not going to work (without further config) if Tomcat is running with a SecurityManager.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload