Commit 8fe8d389 authored by Matt Tucker's avatar Matt Tucker Committed by matt

Code cleanup.

git-svn-id: http://svn.igniterealtime.org/svn/repos/wildfire/trunk@6071 b35dd754-fafc-0310-a699-88a17e54d16e
parent aed17322
...@@ -61,18 +61,28 @@ public class HttpServerManager { ...@@ -61,18 +61,28 @@ public class HttpServerManager {
public static final int HTTP_BIND_SECURE_PORT_DEFAULT = 8483; public static final int HTTP_BIND_SECURE_PORT_DEFAULT = 8483;
/**
* Returns an HTTP server manager instance (singleton).
*
* @return an HTTP server manager instance.
*/
public static HttpServerManager getInstance() { public static HttpServerManager getInstance() {
return instance; return instance;
} }
private int port; private int bindPort;
private int securePort; private int adminPort;
private int bindSecurePort;
private int adminSecurePort;
private Server adminServer; private Server adminServer;
private Server httpBindServer; private Server httpBindServer;
private Context adminConsoleContext; private Context adminConsoleContext;
private ServletHolder httpBindContext; private ServletHolder httpBindContext;
private String httpBindPath; private String httpBindPath;
/**
* Constructs a new HTTP server manager.
*/
private HttpServerManager() { private HttpServerManager() {
PropertyEventDispatcher.addListener(new HttpServerPropertyListener()); PropertyEventDispatcher.addListener(new HttpServerPropertyListener());
...@@ -105,14 +115,163 @@ public class HttpServerManager { ...@@ -105,14 +115,163 @@ public class HttpServerManager {
this.httpBindPath = httpBindPath; this.httpBindPath = httpBindPath;
} }
private void createHttpBindServer() { /**
port = JiveGlobals.getIntProperty(HTTP_BIND_PORT, ADMIN_CONSOLE_PORT_DEFAULT); * Starts any neccesary Jetty instances. If the admin console and http-binding are running on
securePort = JiveGlobals.getIntProperty(HTTP_BIND_SECURE_PORT, * seperate ports then two jetty instances are started, if not then only one is started. The
* proper contexts are then added to the Jetty servers.
*/
public void startup() {
if (httpBindContext != null && isHttpBindServiceEnabled()) {
bindPort = JiveGlobals.getIntProperty(HTTP_BIND_PORT, ADMIN_CONSOLE_PORT_DEFAULT);
bindSecurePort = JiveGlobals.getIntProperty(HTTP_BIND_SECURE_PORT,
ADMIN_CONSOLE_SECURE_PORT_DEFAULT);
startHttpBindServer(bindPort, bindSecurePort);
}
if (adminConsoleContext != null) {
createAdminConsoleServer();
}
addContexts();
if (httpBindServer != null) {
try {
httpBindServer.start();
}
catch (Exception e) {
Log.error("Could not start HTTP bind server", e);
}
}
if (adminServer != null && adminServer != httpBindServer) {
try {
adminServer.start();
}
catch (Exception e) {
Log.error("Could not start admin conosle server", e);
}
}
}
/**
* Shuts down any Jetty servers that are running the admin console and HTTP binding service.
*/
public void shutdown() {
if (httpBindServer != null) {
try {
httpBindServer.stop();
}
catch (Exception e) {
Log.error("Error stopping HTTP bind server", e);
}
httpBindServer = null;
}
//noinspection ConstantConditions
if (adminServer != null && adminServer != httpBindServer) {
try {
adminServer.stop();
}
catch (Exception e) {
Log.error("Error stopping admin console server", e);
}
adminServer = null;
}
}
/**
* Returns true if the HTTP binding server is currently enabled.
*
* @return true if the HTTP binding server is currently enabled.
*/
public boolean isHttpBindEnabled() {
return httpBindServer != null && httpBindServer.isRunning();
}
/**
* Returns the HTTP binding port which does not use SSL.
*
* @return the HTTP binding port which does not use SSL.
*/
public int getHttpBindUnsecurePort() {
return JiveGlobals.getIntProperty(HTTP_BIND_PORT, HTTP_BIND_PORT_DEFAULT);
}
/**
* Returns the HTTP binding port which uses SSL.
*
* @return the HTTP binding port which uses SSL.
*/
public int getHttpBindSecurePort() {
return JiveGlobals.getIntProperty(HTTP_BIND_SECURE_PORT, HTTP_BIND_SECURE_PORT_DEFAULT);
}
/**
* Returns true if the HTTP binding service is running on a seperate server than the admin
* console.
*
* @return true if the HTTP binding service is running on a seperate server than the admin
* console.
*/
public boolean isSeperateHttpBindServerConfigured() {
return (httpBindServer != null && httpBindServer != adminServer) || (httpBindServer == null
&& (getAdminUnsecurePort() != JiveGlobals.getIntProperty(HTTP_BIND_PORT, 9090)
|| getAdminSecurePort()
!= JiveGlobals.getIntProperty(HTTP_BIND_SECURE_PORT, 9091)));
}
public void setHttpBindEnabled(boolean isEnabled) {
JiveGlobals.setProperty(HTTP_BIND_ENABLED, String.valueOf(isEnabled));
}
/**
* Set the ports on which the HTTP binding service will be running.
*
* @param unsecurePort the unsecured connection port which clients can connect to.
* @param securePort the secured connection port which clients can connect to.
*/
public void setHttpBindPorts(int unsecurePort, int securePort) {
changeHttpBindPorts(unsecurePort, securePort);
bindPort = unsecurePort;
bindSecurePort = securePort;
if (unsecurePort != getAdminUnsecurePort()) {
JiveGlobals.setProperty(HTTP_BIND_PORT, String.valueOf(unsecurePort));
}
else {
JiveGlobals.deleteProperty(HTTP_BIND_PORT);
}
if (securePort != getAdminSecurePort()) {
JiveGlobals.setProperty(HTTP_BIND_SECURE_PORT, String.valueOf(securePort));
}
else {
JiveGlobals.deleteProperty(HTTP_BIND_SECURE_PORT);
}
}
/**
* Returns the non-SSL port on which the admin console is currently operating.
*
* @return the non-SSL port on which the admin console is currently operating.
*/
public int getAdminUnsecurePort() {
return JiveGlobals.getXMLProperty(ADMIN_CONSOLE_PORT, ADMIN_CONSOLE_PORT_DEFAULT);
}
/**
* Returns the SSL port on which the admin console is current operating.
*
* @return the SSL port on which the admin console is current operating.
*/
public int getAdminSecurePort() {
return JiveGlobals.getXMLProperty(ADMIN_CONOSLE_SECURE_PORT,
ADMIN_CONSOLE_SECURE_PORT_DEFAULT); ADMIN_CONSOLE_SECURE_PORT_DEFAULT);
createHttpBindServer(port, securePort);
} }
private void createHttpBindServer(int port, int securePort) { /**
* Starts an HTTP Bind server on the specified port and secure port.
*
* @param port the port to start the normal (unsecured) HTTP Bind service on.
* @param securePort the port to start the TLS (secure) HTTP Bind service on.
*/
private void startHttpBindServer(int port, int securePort) {
httpBindServer = new Server(); httpBindServer = new Server();
Collection<Connector> connectors = createAdminConsoleConnectors(port, securePort); Collection<Connector> connectors = createAdminConsoleConnectors(port, securePort);
if (connectors.size() == 0) { if (connectors.size() == 0) {
...@@ -125,17 +284,17 @@ public class HttpServerManager { ...@@ -125,17 +284,17 @@ public class HttpServerManager {
} }
private void createAdminConsoleServer() { private void createAdminConsoleServer() {
int port = JiveGlobals.getXMLProperty(ADMIN_CONSOLE_PORT, ADMIN_CONSOLE_PORT_DEFAULT); adminPort = JiveGlobals.getXMLProperty(ADMIN_CONSOLE_PORT, ADMIN_CONSOLE_PORT_DEFAULT);
int securePort = JiveGlobals.getXMLProperty(ADMIN_CONOSLE_SECURE_PORT, adminSecurePort = JiveGlobals.getXMLProperty(ADMIN_CONOSLE_SECURE_PORT,
ADMIN_CONSOLE_SECURE_PORT_DEFAULT); ADMIN_CONSOLE_SECURE_PORT_DEFAULT);
boolean loadConnectors = true; boolean loadConnectors = true;
if (httpBindServer != null) { if (httpBindServer != null) {
if (port == this.port && securePort == this.securePort) { if (adminPort == bindPort && adminSecurePort == bindSecurePort) {
adminServer = httpBindServer; adminServer = httpBindServer;
loadConnectors = false; loadConnectors = false;
} }
else if (checkPorts(new int[]{this.port, this.securePort}, else if (checkPorts(new int[]{adminPort, adminSecurePort},
new int[]{port, securePort})) new int[]{bindPort, bindSecurePort}))
{ {
Log.warn("HTTP bind ports must be either the same or distinct from admin console" + Log.warn("HTTP bind ports must be either the same or distinct from admin console" +
" ports."); " ports.");
...@@ -152,7 +311,7 @@ public class HttpServerManager { ...@@ -152,7 +311,7 @@ public class HttpServerManager {
} }
if (loadConnectors) { if (loadConnectors) {
Collection<Connector> connectors = createAdminConsoleConnectors(port, securePort); Collection<Connector> connectors = createAdminConsoleConnectors(adminPort, adminSecurePort);
if (connectors.size() == 0) { if (connectors.size() == 0) {
adminServer = null; adminServer = null;
...@@ -178,10 +337,10 @@ public class HttpServerManager { ...@@ -178,10 +337,10 @@ public class HttpServerManager {
boolean isPlainStarted = false; boolean isPlainStarted = false;
boolean isSecureStarted = false; boolean isSecureStarted = false;
for (Connector connector : adminServer.getConnectors()) { for (Connector connector : adminServer.getConnectors()) {
if (connector.getPort() == port) { if (connector.getPort() == adminPort) {
isPlainStarted = true; isPlainStarted = true;
} }
else if (connector.getPort() == securePort) { else if (connector.getPort() == adminSecurePort) {
isSecureStarted = true; isSecureStarted = true;
} }
} }
...@@ -189,23 +348,23 @@ public class HttpServerManager { ...@@ -189,23 +348,23 @@ public class HttpServerManager {
if (isPlainStarted && isSecureStarted) { if (isPlainStarted && isSecureStarted) {
String msg = listening + ":" + System.getProperty("line.separator") + String msg = listening + ":" + System.getProperty("line.separator") +
" http://" + XMPPServer.getInstance().getServerInfo().getName() + ":" + " http://" + XMPPServer.getInstance().getServerInfo().getName() + ":" +
port + System.getProperty("line.separator") + adminPort + System.getProperty("line.separator") +
" https://" + XMPPServer.getInstance().getServerInfo().getName() + ":" + " https://" + XMPPServer.getInstance().getServerInfo().getName() + ":" +
securePort; adminSecurePort;
Log.info(msg); Log.info(msg);
System.out.println(msg); System.out.println(msg);
} }
else if (isSecureStarted) { else if (isSecureStarted) {
Log.info(listening + " https://" + Log.info(listening + " https://" +
XMPPServer.getInstance().getServerInfo().getName() + ":" + securePort); XMPPServer.getInstance().getServerInfo().getName() + ":" + adminSecurePort);
System.out.println(listening + " https://" + System.out.println(listening + " https://" +
XMPPServer.getInstance().getServerInfo().getName() + ":" + securePort); XMPPServer.getInstance().getServerInfo().getName() + ":" + adminSecurePort);
} }
else if (isPlainStarted) { else if (isPlainStarted) {
Log.info(listening + " http://" + Log.info(listening + " http://" +
XMPPServer.getInstance().getServerInfo().getName() + ":" + port); XMPPServer.getInstance().getServerInfo().getName() + ":" + adminPort);
System.out.println(listening + " http://" + System.out.println(listening + " http://" +
XMPPServer.getInstance().getServerInfo().getName() + ":" + port); XMPPServer.getInstance().getServerInfo().getName() + ":" + adminPort);
} }
} }
...@@ -215,39 +374,6 @@ public class HttpServerManager { ...@@ -215,39 +374,6 @@ public class HttpServerManager {
|| httpBindPorts[1] == adminConsolePorts[1]; || httpBindPorts[1] == adminConsolePorts[1];
} }
/**
* Starts any neccesary Jetty instances. If the admin console and http-binding are running on
* seperate ports then two jetty instances are started, if not then only one is started. The
* proper contexts are then added to the Jetty servers.
*/
public void startup() {
if (httpBindContext != null && isHttpBindServiceEnabled()) {
createHttpBindServer();
}
if (adminConsoleContext != null) {
createAdminConsoleServer();
}
addContexts();
if (httpBindServer != null) {
try {
httpBindServer.start();
}
catch (Exception e) {
Log.error("Could not start HTTP bind server", e);
}
}
if (adminServer != null && adminServer != httpBindServer) {
try {
adminServer.start();
}
catch (Exception e) {
Log.error("Could not start admin conosle server", e);
}
}
}
private boolean isHttpBindServiceEnabled() { private boolean isHttpBindServiceEnabled() {
return JiveGlobals.getBooleanProperty(HTTP_BIND_ENABLED, HTTP_BIND_ENABLED_DEFAULT); return JiveGlobals.getBooleanProperty(HTTP_BIND_ENABLED, HTTP_BIND_ENABLED_DEFAULT);
} }
...@@ -299,31 +425,6 @@ public class HttpServerManager { ...@@ -299,31 +425,6 @@ public class HttpServerManager {
handler.setServlets(toAddServlets.toArray(new ServletHolder[toAddServlets.size()])); handler.setServlets(toAddServlets.toArray(new ServletHolder[toAddServlets.size()]));
} }
/**
* Shuts down any Jetty servers that are running the admin console and HTTP binding service.
*/
public void shutdown() {
if (httpBindServer != null) {
try {
httpBindServer.stop();
}
catch (Exception e) {
Log.error("Error stopping HTTP bind server", e);
}
httpBindServer = null;
}
//noinspection ConstantConditions
if (adminServer != null && adminServer != httpBindServer) {
try {
adminServer.stop();
}
catch (Exception e) {
Log.error("Error stopping admin console server", e);
}
adminServer = null;
}
}
private Collection<Connector> createAdminConsoleConnectors(int port, int securePort) { private Collection<Connector> createAdminConsoleConnectors(int port, int securePort) {
List<Connector> connectorList = new ArrayList<Connector>(); List<Connector> connectorList = new ArrayList<Connector>();
...@@ -356,75 +457,6 @@ public class HttpServerManager { ...@@ -356,75 +457,6 @@ public class HttpServerManager {
return connectorList; return connectorList;
} }
/**
* Returns true if the HTTP binding server is currently enabled.
*
* @return true if the HTTP binding server is currently enabled.
*/
public boolean isHttpBindEnabled() {
return httpBindServer != null && httpBindServer.isRunning();
}
/**
* Returns the HTTP binding port which does not use SSL.
*
* @return the HTTP binding port which does not use SSL.
*/
public int getHttpBindUnsecurePort() {
return JiveGlobals.getIntProperty(HTTP_BIND_PORT, HTTP_BIND_PORT_DEFAULT);
}
/**
* Returns the HTTP binding port which uses SSL.
*
* @return the HTTP binding port which uses SSL.
*/
public int getHttpBindSecurePort() {
return JiveGlobals.getIntProperty(HTTP_BIND_SECURE_PORT, HTTP_BIND_SECURE_PORT_DEFAULT);
}
/**
* Returns true if the HTTP binding service is running on a seperate server than the admin
* console.
*
* @return true if the HTTP binding service is running on a seperate server than the admin
* console.
*/
public boolean isSeperateHttpBindServerConfigured() {
return (httpBindServer != null && httpBindServer != adminServer) || (httpBindServer == null
&& (getAdminUnsecurePort() != JiveGlobals.getIntProperty(HTTP_BIND_PORT, 9090)
|| getAdminSecurePort()
!= JiveGlobals.getIntProperty(HTTP_BIND_SECURE_PORT, 9091)));
}
public void setHttpBindEnabled(boolean isEnabled) {
JiveGlobals.setProperty(HTTP_BIND_ENABLED, String.valueOf(isEnabled));
}
/**
* Set the ports on which the HTTP binding service will be running.
*
* @param unsecurePort the unsecured connection port which clients can connect to.
* @param securePort the secured connection port which clients can connect to.
*/
public void setHttpBindPorts(int unsecurePort, int securePort) {
changeHttpBindPorts(unsecurePort, securePort);
port = unsecurePort;
this.securePort = securePort;
if (unsecurePort != getAdminUnsecurePort()) {
JiveGlobals.setProperty(HTTP_BIND_PORT, String.valueOf(unsecurePort));
}
else {
JiveGlobals.deleteProperty(HTTP_BIND_PORT);
}
if (securePort != getAdminSecurePort()) {
JiveGlobals.setProperty(HTTP_BIND_SECURE_PORT, String.valueOf(securePort));
}
else {
JiveGlobals.deleteProperty(HTTP_BIND_SECURE_PORT);
}
}
private void changeHttpBindPorts(int unsecurePort, int securePort) { private void changeHttpBindPorts(int unsecurePort, int securePort) {
if (unsecurePort < 0 && securePort < 0) { if (unsecurePort < 0 && securePort < 0) {
throw new IllegalArgumentException("At least one port must be greater than zero."); throw new IllegalArgumentException("At least one port must be greater than zero.");
...@@ -467,7 +499,7 @@ public class HttpServerManager { ...@@ -467,7 +499,7 @@ public class HttpServerManager {
Log.error("Error stopping HTTP bind service", e); Log.error("Error stopping HTTP bind service", e);
} }
} }
createHttpBindServer(unsecurePort, securePort); startHttpBindServer(unsecurePort, securePort);
addContexts(); addContexts();
try { try {
httpBindServer.start(); httpBindServer.start();
...@@ -477,25 +509,6 @@ public class HttpServerManager { ...@@ -477,25 +509,6 @@ public class HttpServerManager {
} }
} }
/**
* Returns the non-SSL port on which the admin console is currently operating.
*
* @return the non-SSL port on which the admin console is currently operating.
*/
public int getAdminUnsecurePort() {
return JiveGlobals.getXMLProperty(ADMIN_CONSOLE_PORT, ADMIN_CONSOLE_PORT_DEFAULT);
}
/**
* Returns the SSL port on which the admin console is current operating.
*
* @return the SSL port on which the admin console is current operating.
*/
public int getAdminSecurePort() {
return JiveGlobals.getXMLProperty(ADMIN_CONOSLE_SECURE_PORT,
ADMIN_CONSOLE_SECURE_PORT_DEFAULT);
}
private void doEnableHttpBind(boolean shouldEnable) { private void doEnableHttpBind(boolean shouldEnable) {
if (shouldEnable && httpBindServer == null) { if (shouldEnable && httpBindServer == null) {
changeHttpBindPorts(JiveGlobals.getIntProperty(HTTP_BIND_PORT, changeHttpBindPorts(JiveGlobals.getIntProperty(HTTP_BIND_PORT,
...@@ -520,13 +533,13 @@ public class HttpServerManager { ...@@ -520,13 +533,13 @@ public class HttpServerManager {
} }
private void setUnsecureHttpBindPort(int value) { private void setUnsecureHttpBindPort(int value) {
if (value == port) { if (value == bindPort) {
return; return;
} }
try { try {
changeHttpBindPorts(value, JiveGlobals.getIntProperty(HTTP_BIND_SECURE_PORT, changeHttpBindPorts(value, JiveGlobals.getIntProperty(HTTP_BIND_SECURE_PORT,
ADMIN_CONSOLE_SECURE_PORT_DEFAULT)); ADMIN_CONSOLE_SECURE_PORT_DEFAULT));
port = value; bindPort = value;
} }
catch (Exception ex) { catch (Exception ex) {
Log.error("Error setting HTTP bind ports", ex); Log.error("Error setting HTTP bind ports", ex);
...@@ -534,20 +547,22 @@ public class HttpServerManager { ...@@ -534,20 +547,22 @@ public class HttpServerManager {
} }
private void setSecureHttpBindPort(int value) { private void setSecureHttpBindPort(int value) {
if (value == securePort) { if (value == bindSecurePort) {
return; return;
} }
try { try {
changeHttpBindPorts(JiveGlobals.getIntProperty(HTTP_BIND_PORT, changeHttpBindPorts(JiveGlobals.getIntProperty(HTTP_BIND_PORT,
ADMIN_CONSOLE_PORT_DEFAULT), value); ADMIN_CONSOLE_PORT_DEFAULT), value);
securePort = value; bindSecurePort = value;
} }
catch (Exception ex) { catch (Exception ex) {
Log.error("Error setting HTTP bind ports", ex); Log.error("Error setting HTTP bind ports", ex);
} }
} }
/**
* Listens for changes to Jive properties that affect the HTTP server manager.
*/
private class HttpServerPropertyListener implements PropertyEventListener { private class HttpServerPropertyListener implements PropertyEventListener {
public void propertySet(String property, Map params) { public void propertySet(String property, Map params) {
......
...@@ -324,12 +324,12 @@ public class XMPPServer { ...@@ -324,12 +324,12 @@ public class XMPPServer {
// No certificates were found so create new self-signed certificates // No certificates were found so create new self-signed certificates
if (!dsaFound) { if (!dsaFound) {
CertificateManager.createDSACert(ksKeys, SSLConfig.getKeyPassword(), name + "_dsa", "cn=" + name, CertificateManager.createDSACert(ksKeys, SSLConfig.getKeyPassword(),
"cn=" + name, "*." + name); name + "_dsa", "cn=" + name, "cn=" + name, "*." + name);
} }
if (!rsaFound) { if (!rsaFound) {
CertificateManager.createRSACert(ksKeys, SSLConfig.getKeyPassword(), name + "_rsa", "cn=" + name, CertificateManager.createRSACert(ksKeys, SSLConfig.getKeyPassword(),
"cn=" + name, "*." + name); name + "_rsa", "cn=" + name, "cn=" + name, "*." + name);
} }
// Save new certificates into the key store // Save new certificates into the key store
if (!dsaFound || !rsaFound) { if (!dsaFound || !rsaFound) {
......
...@@ -82,10 +82,10 @@ public class PluginManager { ...@@ -82,10 +82,10 @@ public class PluginManager {
// See if we're in development mode. If so, check for new plugins once every 5 seconds. // See if we're in development mode. If so, check for new plugins once every 5 seconds.
// Otherwise, default to every 20 seconds. // Otherwise, default to every 20 seconds.
if (Boolean.getBoolean("developmentMode")) { if (Boolean.getBoolean("developmentMode")) {
executor.scheduleWithFixedDelay(pluginMonitor, 1, 5, TimeUnit.SECONDS); executor.scheduleWithFixedDelay(pluginMonitor, 0, 5, TimeUnit.SECONDS);
} }
else { else {
executor.scheduleWithFixedDelay(pluginMonitor, 1, 20, TimeUnit.SECONDS); executor.scheduleWithFixedDelay(pluginMonitor, 0, 20, TimeUnit.SECONDS);
} }
} }
......
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