I have embedded Jetty into my Eclipse RCP application successfully. In my RCP application, when user click some button, a browser will be opened and some servlet page shown. The jsp files are in a separated directory, it is a angulajs web application.
I am trying to shutdown embedded Jetty server from Eclipse UI plugin when user closes the RCP.The server is started in a class named Workshop which is part of web project, so I dont have access to Server instance to call, server.stop() from Eclipse UI Plugin.I have tried below code, but in vein.
1>Configure ShutdownHook to Workshop class of web project
server = new Server();
server.setConnectors(new Connector[] { connector });
server.setHandler(handlers);
server.start();
handlers.addHandler(new ShutdownHandler(server, "abc"));
server.setStopAtShutdown(true);
server.setGracefulShutdown(7_000);
ShutdownThread.getInstance().run();
2> In my Eclipse UI Plugin, I have added
Runtime.getRuntime().addShutdownHook(new Thread() {
@Override
public void run() {
try {
URL url = new URL("http://localhost:" + resultPortNo + "/shutdown?token=" + shutdownCookie);
HttpURLConnection connection = (HttpURLConnection)url.openConnection();
connection.setRequestMethod("POST");
connection.getResponseCode();
logger.info("Shutting down " + url + ": " + connection.getResponseMessage());
} catch (SocketException e) {
// logger.debug("Not running");
// Okay - the server is not running
} catch (IOException e) {
throw new RuntimeException(e);
}
}
});
HtppUrlConnection throws 404-NotFound response code.So Jetty server is still running. How do we handle embedded Jetty shutdown from Eclipse UI Plugin.
I did read lot of articles, but cannot find answer to my question.
Any help will be appreciated.Thank you.