Commit db046946 authored by Matt Tucker's avatar Matt Tucker Committed by matt

Updates to make it possible to finish setup with restart.


git-svn-id: http://svn.igniterealtime.org/svn/repos/messenger/trunk@1756 b35dd754-fafc-0310-a699-88a17e54d16e
parent 7362d516
......@@ -25,6 +25,7 @@ import org.jivesoftware.util.JiveGlobals;
import org.jivesoftware.util.LocaleUtils;
import org.jivesoftware.util.Log;
import org.mortbay.http.SunJsseListener;
import org.mortbay.http.HttpListener;
import org.mortbay.jetty.Server;
import org.mortbay.jetty.servlet.WebApplicationContext;
import org.mortbay.log.Factory;
......@@ -47,43 +48,43 @@ public class AdminConsolePlugin implements Plugin {
private int port;
private int securePort;
private HttpListener plainListener = null;
private HttpListener secureListener = null;
/**
* Create a jetty module.
*/
public AdminConsolePlugin() {
}
public void initializePlugin(PluginManager manager, File pluginDir) {
public void restartListeners() {
try {
// Configure logging to a file, creating log dir if needed
System.setProperty("org.apache.commons.logging.LogFactory", "org.mortbay.log.Factory");
File logDir = new File(JiveGlobals.getHomeDirectory(), "logs");
if (!logDir.exists()) {
logDir.mkdirs();
jetty.stop();
if (plainListener != null) {
jetty.removeListener(plainListener);
}
if (secureListener != null) {
jetty.removeListener(secureListener);
}
loadListeners();
jetty.start();
}
catch (Exception e) {
Log.error(e);
}
}
File logFile = new File(logDir, "admin-console.log");
OutputStreamLogSink logSink = new OutputStreamLogSink(logFile.toString());
logSink.start();
LogImpl log = (LogImpl) Factory.getFactory().getInstance("");
// Ignore INFO logs.
log.setVerbose(-1);
log.add(logSink);
jetty = new Server();
private void loadListeners() throws Exception {
// Configure HTTP socket listener
boolean plainStarted = false;
// Setting this property to a not null value will imply that the Jetty server will only
// accept connect requests to that IP address
interfaceName = JiveGlobals.getXMLProperty("adminConsole.interface");
port = JiveGlobals.getXMLProperty("adminConsole.port", 9090);
InetAddrPort address = new InetAddrPort(interfaceName, port);
if (port > 0) {
jetty.addListener(address);
plainStarted = true;
plainListener = jetty.addListener(address);
}
boolean secureStarted = false;
try {
securePort = JiveGlobals.getXMLProperty("adminConsole.securePort", 9091);
if (securePort > 0) {
......@@ -114,13 +115,33 @@ public class AdminConsolePlugin implements Plugin {
listener.setHost(interfaceName);
listener.setPort(securePort);
jetty.addListener(listener);
secureStarted = true;
secureListener = jetty.addListener(listener);
}
}
catch (Exception e) {
Log.error(e);
}
}
public void initializePlugin(PluginManager manager, File pluginDir) {
try {
// Configure logging to a file, creating log dir if needed
System.setProperty("org.apache.commons.logging.LogFactory", "org.mortbay.log.Factory");
File logDir = new File(JiveGlobals.getHomeDirectory(), "logs");
if (!logDir.exists()) {
logDir.mkdirs();
}
File logFile = new File(logDir, "admin-console.log");
OutputStreamLogSink logSink = new OutputStreamLogSink(logFile.toString());
logSink.start();
LogImpl log = (LogImpl) Factory.getFactory().getInstance("");
// Ignore INFO logs.
log.setVerbose(-1);
log.add(logSink);
jetty = new Server();
loadListeners();
// Add web-app
WebApplicationContext webAppContext = jetty.addWebApplication("/",
......@@ -132,17 +153,17 @@ public class AdminConsolePlugin implements Plugin {
String warning = LocaleUtils.getLocalizedString("admin.console.warning");
String listening = LocaleUtils.getLocalizedString("admin.console.listening");
if (!plainStarted && !secureStarted) {
if (plainListener == null && secureListener == null) {
Log.info(warning);
System.out.println(warning);
}
else if (!plainStarted && secureStarted) {
else if (plainListener == null && secureListener != null) {
Log.info(listening + " https://" +
XMPPServer.getInstance().getServerInfo().getName() + ":" + securePort);
System.out.println(listening + " https://" +
XMPPServer.getInstance().getServerInfo().getName() + ":" + securePort);
}
else if (!secureStarted && plainStarted) {
else if (secureListener == null && plainListener != null) {
Log.info(listening + " http://" +
XMPPServer.getInstance().getServerInfo().getName() + ":" + port);
System.out.println(listening + " http://" +
......@@ -165,6 +186,8 @@ public class AdminConsolePlugin implements Plugin {
}
public void destroyPlugin() {
plainListener = null;
secureListener = null;
try {
if (jetty != null) {
jetty.stop();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment