Categories: MSDN / DotNet / Java / Scripts / Linux / PHP Ask - La ask - La Answer

How to shutdown embedded Jetty via host application

What is the cleanest way to have a servlet invoked via Jetty, communicate something to the host application? Is there was a simple way for the host application to tell Jetty to provide some sort of object reference to the servlet-- a reference to an object they can both see, so when the servlet methods get invoked, the servlet can communicate back to the host (embedding) application. I want to be able to stop the server via a call to Server.stop or system.exit in the servlet's doGet Method. Below is the host application that starts the Jetty server. Thanks!

public class MyJettyLauncher
{
public static void main(String[] args)
throws Exception
{
org.mortbay.jetty.Server server = new Server();
org.mortbay.jetty.nio.SelectChannelConnector connector = new SelectChannelConnector();
connector.setPort(8080);
server.setConnectors(new Connector[]{connector});
WebAppContext wah = new WebAppContext();
wah.setContextPath("/");
wah.setWar("c:/projects/DataRep/DataRep.war");
server.addHandler(wah);
server.start();

BrowserLauncher launcher = new BrowserLauncher(null);
BrowserLauncherRunner runner = new BrowserLauncherRunner(launcher, "http://localhost:8080", null);
Thread launcherThread = new Thread(runner);
launcherThread.start();
}
}
[1377 byte] By [sirix42] at [2007-11-11 9:53:11]