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; ...@@ -25,6 +25,7 @@ import org.jivesoftware.util.JiveGlobals;
import org.jivesoftware.util.LocaleUtils; import org.jivesoftware.util.LocaleUtils;
import org.jivesoftware.util.Log; import org.jivesoftware.util.Log;
import org.mortbay.http.SunJsseListener; import org.mortbay.http.SunJsseListener;
import org.mortbay.http.HttpListener;
import org.mortbay.jetty.Server; import org.mortbay.jetty.Server;
import org.mortbay.jetty.servlet.WebApplicationContext; import org.mortbay.jetty.servlet.WebApplicationContext;
import org.mortbay.log.Factory; import org.mortbay.log.Factory;
...@@ -47,43 +48,43 @@ public class AdminConsolePlugin implements Plugin { ...@@ -47,43 +48,43 @@ public class AdminConsolePlugin implements Plugin {
private int port; private int port;
private int securePort; private int securePort;
private HttpListener plainListener = null;
private HttpListener secureListener = null;
/** /**
* Create a jetty module. * Create a jetty module.
*/ */
public AdminConsolePlugin() { public AdminConsolePlugin() {
} }
public void initializePlugin(PluginManager manager, File pluginDir) { public void restartListeners() {
try { try {
// Configure logging to a file, creating log dir if needed jetty.stop();
System.setProperty("org.apache.commons.logging.LogFactory", "org.mortbay.log.Factory"); if (plainListener != null) {
File logDir = new File(JiveGlobals.getHomeDirectory(), "logs"); jetty.removeListener(plainListener);
if (!logDir.exists()) { }
logDir.mkdirs(); 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 // Configure HTTP socket listener
boolean plainStarted = false;
// Setting this property to a not null value will imply that the Jetty server will only // Setting this property to a not null value will imply that the Jetty server will only
// accept connect requests to that IP address // accept connect requests to that IP address
interfaceName = JiveGlobals.getXMLProperty("adminConsole.interface"); interfaceName = JiveGlobals.getXMLProperty("adminConsole.interface");
port = JiveGlobals.getXMLProperty("adminConsole.port", 9090); port = JiveGlobals.getXMLProperty("adminConsole.port", 9090);
InetAddrPort address = new InetAddrPort(interfaceName, port); InetAddrPort address = new InetAddrPort(interfaceName, port);
if (port > 0) { if (port > 0) {
jetty.addListener(address); plainListener = jetty.addListener(address);
plainStarted = true;
} }
boolean secureStarted = false;
try { try {
securePort = JiveGlobals.getXMLProperty("adminConsole.securePort", 9091); securePort = JiveGlobals.getXMLProperty("adminConsole.securePort", 9091);
if (securePort > 0) { if (securePort > 0) {
...@@ -114,13 +115,33 @@ public class AdminConsolePlugin implements Plugin { ...@@ -114,13 +115,33 @@ public class AdminConsolePlugin implements Plugin {
listener.setHost(interfaceName); listener.setHost(interfaceName);
listener.setPort(securePort); listener.setPort(securePort);
jetty.addListener(listener); secureListener = jetty.addListener(listener);
secureStarted = true;
} }
} }
catch (Exception e) { catch (Exception e) {
Log.error(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 // Add web-app
WebApplicationContext webAppContext = jetty.addWebApplication("/", WebApplicationContext webAppContext = jetty.addWebApplication("/",
...@@ -132,17 +153,17 @@ public class AdminConsolePlugin implements Plugin { ...@@ -132,17 +153,17 @@ public class AdminConsolePlugin implements Plugin {
String warning = LocaleUtils.getLocalizedString("admin.console.warning"); String warning = LocaleUtils.getLocalizedString("admin.console.warning");
String listening = LocaleUtils.getLocalizedString("admin.console.listening"); String listening = LocaleUtils.getLocalizedString("admin.console.listening");
if (!plainStarted && !secureStarted) { if (plainListener == null && secureListener == null) {
Log.info(warning); Log.info(warning);
System.out.println(warning); System.out.println(warning);
} }
else if (!plainStarted && secureStarted) { else if (plainListener == null && secureListener != null) {
Log.info(listening + " https://" + Log.info(listening + " https://" +
XMPPServer.getInstance().getServerInfo().getName() + ":" + securePort); XMPPServer.getInstance().getServerInfo().getName() + ":" + securePort);
System.out.println(listening + " https://" + System.out.println(listening + " https://" +
XMPPServer.getInstance().getServerInfo().getName() + ":" + securePort); XMPPServer.getInstance().getServerInfo().getName() + ":" + securePort);
} }
else if (!secureStarted && plainStarted) { else if (secureListener == null && plainListener != null) {
Log.info(listening + " http://" + Log.info(listening + " http://" +
XMPPServer.getInstance().getServerInfo().getName() + ":" + port); XMPPServer.getInstance().getServerInfo().getName() + ":" + port);
System.out.println(listening + " http://" + System.out.println(listening + " http://" +
...@@ -165,6 +186,8 @@ public class AdminConsolePlugin implements Plugin { ...@@ -165,6 +186,8 @@ public class AdminConsolePlugin implements Plugin {
} }
public void destroyPlugin() { public void destroyPlugin() {
plainListener = null;
secureListener = null;
try { try {
if (jetty != null) { if (jetty != null) {
jetty.stop(); 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