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,12 +48,81 @@ public class AdminConsolePlugin implements Plugin { ...@@ -47,12 +48,81 @@ 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 restartListeners() {
try {
jetty.stop();
if (plainListener != null) {
jetty.removeListener(plainListener);
}
if (secureListener != null) {
jetty.removeListener(secureListener);
}
loadListeners();
jetty.start();
}
catch (Exception e) {
Log.error(e);
}
}
private void loadListeners() throws Exception {
// Configure HTTP socket listener
// 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) {
plainListener = jetty.addListener(address);
}
try {
securePort = JiveGlobals.getXMLProperty("adminConsole.securePort", 9091);
if (securePort > 0) {
SunJsseListener listener = new SunJsseListener();
// Get the keystore location. The default location is security/keystore
String keyStoreLocation = JiveGlobals.getProperty("xmpp.socket.ssl.keystore",
"resources" + File.separator + "security" + File.separator + "keystore");
keyStoreLocation = JiveGlobals.getHomeDirectory() + File.separator + keyStoreLocation;
// Get the keystore password. The default password is "changeit".
String keypass = JiveGlobals.getProperty("xmpp.socket.ssl.keypass", "changeit");
keypass = keypass.trim();
// Get the truststore location; default at security/truststore
String trustStoreLocation = JiveGlobals.getProperty("xmpp.socket.ssl.truststore",
"resources" + File.separator + "security" + File.separator + "truststore");
trustStoreLocation = JiveGlobals.getHomeDirectory() + File.separator +
trustStoreLocation;
// Get the truststore passwprd; default is "changeit".
String trustpass = JiveGlobals.getProperty("xmpp.socket.ssl.trustpass", "changeit");
trustpass = trustpass.trim();
listener.setKeystore(keyStoreLocation);
listener.setKeyPassword(keypass);
listener.setPassword(keypass);
listener.setHost(interfaceName);
listener.setPort(securePort);
secureListener = jetty.addListener(listener);
}
}
catch (Exception e) {
Log.error(e);
}
}
public void initializePlugin(PluginManager manager, File pluginDir) { public void initializePlugin(PluginManager manager, File pluginDir) {
try { try {
// Configure logging to a file, creating log dir if needed // Configure logging to a file, creating log dir if needed
...@@ -71,56 +141,7 @@ public class AdminConsolePlugin implements Plugin { ...@@ -71,56 +141,7 @@ public class AdminConsolePlugin implements Plugin {
jetty = new Server(); jetty = new Server();
// Configure HTTP socket listener loadListeners();
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;
}
boolean secureStarted = false;
try {
securePort = JiveGlobals.getXMLProperty("adminConsole.securePort", 9091);
if (securePort > 0) {
SunJsseListener listener = new SunJsseListener();
// Get the keystore location. The default location is security/keystore
String keyStoreLocation = JiveGlobals.getProperty("xmpp.socket.ssl.keystore",
"resources" + File.separator + "security" + File.separator + "keystore");
keyStoreLocation = JiveGlobals.getHomeDirectory() + File.separator + keyStoreLocation;
// Get the keystore password. The default password is "changeit".
String keypass = JiveGlobals.getProperty("xmpp.socket.ssl.keypass", "changeit");
keypass = keypass.trim();
// Get the truststore location; default at security/truststore
String trustStoreLocation = JiveGlobals.getProperty("xmpp.socket.ssl.truststore",
"resources" + File.separator + "security" + File.separator + "truststore");
trustStoreLocation = JiveGlobals.getHomeDirectory() + File.separator +
trustStoreLocation;
// Get the truststore passwprd; default is "changeit".
String trustpass = JiveGlobals.getProperty("xmpp.socket.ssl.trustpass", "changeit");
trustpass = trustpass.trim();
listener.setKeystore(keyStoreLocation);
listener.setKeyPassword(keypass);
listener.setPassword(keypass);
listener.setHost(interfaceName);
listener.setPort(securePort);
jetty.addListener(listener);
secureStarted = true;
}
}
catch (Exception e) {
Log.error(e);
}
// 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