Commit 07b73477 authored by Dave Cridland's avatar Dave Cridland

Merge pull request #172 from tevans/OF-877

OF-877: Cleanup BOSH start/stop/restart
parents 6d0283c6 7b2d581a
...@@ -167,7 +167,6 @@ public final class HttpBindManager { ...@@ -167,7 +167,6 @@ public final class HttpBindManager {
PropertyEventDispatcher.addListener(new HttpServerPropertyListener()); PropertyEventDispatcher.addListener(new HttpServerPropertyListener());
this.httpSessionManager = new HttpSessionManager(); this.httpSessionManager = new HttpSessionManager();
contexts = new ContextHandlerCollection();
// setup the cache for the allowed origins // setup the cache for the allowed origins
this.setupAllowedOriginsMap(); this.setupAllowedOriginsMap();
...@@ -186,6 +185,7 @@ public final class HttpBindManager { ...@@ -186,6 +185,7 @@ public final class HttpBindManager {
try { try {
httpBindServer.start(); httpBindServer.start();
Log.info("HTTP bind service started");
} }
catch (Exception e) { catch (Exception e) {
Log.error("Error starting HTTP bind service", e); Log.error("Error starting HTTP bind service", e);
...@@ -198,10 +198,12 @@ public final class HttpBindManager { ...@@ -198,10 +198,12 @@ public final class HttpBindManager {
if (httpBindServer != null) { if (httpBindServer != null) {
try { try {
httpBindServer.stop(); httpBindServer.stop();
Log.info("HTTP bind service stopped");
} }
catch (Exception e) { catch (Exception e) {
Log.error("Error stoping HTTP bind service", e); Log.error("Error stopping HTTP bind service", e);
} }
httpBindServer = null;
} }
} }
...@@ -486,9 +488,6 @@ public final class HttpBindManager { ...@@ -486,9 +488,6 @@ public final class HttpBindManager {
* @throws Exception when there is an error configuring the HTTP binding ports. * @throws Exception when there is an error configuring the HTTP binding ports.
*/ */
public void setHttpBindPorts(int unsecurePort, int securePort) throws Exception { public void setHttpBindPorts(int unsecurePort, int securePort) throws Exception {
changeHttpBindPorts(unsecurePort, securePort);
bindPort = unsecurePort;
bindSecurePort = securePort;
if (unsecurePort != HTTP_BIND_PORT_DEFAULT) { if (unsecurePort != HTTP_BIND_PORT_DEFAULT) {
JiveGlobals.setProperty(HTTP_BIND_PORT, String.valueOf(unsecurePort)); JiveGlobals.setProperty(HTTP_BIND_PORT, String.valueOf(unsecurePort));
} }
...@@ -503,28 +502,6 @@ public final class HttpBindManager { ...@@ -503,28 +502,6 @@ public final class HttpBindManager {
} }
} }
private synchronized void changeHttpBindPorts(int unsecurePort, int securePort)
throws Exception {
if (unsecurePort < 0 && securePort < 0) {
throw new IllegalArgumentException("At least one port must be greater than zero.");
}
if (unsecurePort == securePort) {
throw new IllegalArgumentException("Ports must be distinct.");
}
if (httpBindServer != null) {
try {
httpBindServer.stop();
}
catch (Exception e) {
Log.error("Error stopping http bind server", e);
}
}
configureHttpBindServer(unsecurePort, securePort);
httpBindServer.start();
}
/** /**
* Starts an HTTP Bind server on the specified port and secure port. * Starts an HTTP Bind server on the specified port and secure port.
* *
...@@ -557,6 +534,7 @@ public final class HttpBindManager { ...@@ -557,6 +534,7 @@ public final class HttpBindManager {
httpBindServer.addConnector(httpsConnector); httpBindServer.addConnector(httpsConnector);
} }
contexts = new ContextHandlerCollection();
createBoshHandler(contexts, "/http-bind"); createBoshHandler(contexts, "/http-bind");
createCrossDomainHandler(contexts, "/crossdomain.xml"); createCrossDomainHandler(contexts, "/crossdomain.xml");
loadStaticDirectory(contexts); loadStaticDirectory(contexts);
...@@ -616,23 +594,10 @@ public final class HttpBindManager { ...@@ -616,23 +594,10 @@ public final class HttpBindManager {
private void doEnableHttpBind(boolean shouldEnable) { private void doEnableHttpBind(boolean shouldEnable) {
if (shouldEnable && httpBindServer == null) { if (shouldEnable && httpBindServer == null) {
try { start();
changeHttpBindPorts(JiveGlobals.getIntProperty(HTTP_BIND_PORT,
HTTP_BIND_PORT_DEFAULT), JiveGlobals.getIntProperty(HTTP_BIND_SECURE_PORT,
HTTP_BIND_SECURE_PORT_DEFAULT));
}
catch (Exception e) {
Log.error("Error configuring HTTP binding ports", e);
}
} }
else if (!shouldEnable && httpBindServer != null) { else if (!shouldEnable && httpBindServer != null) {
try { stop();
httpBindServer.stop();
}
catch (Exception e) {
Log.error("Error stopping HTTP bind service", e);
}
httpBindServer = null;
} }
} }
...@@ -689,41 +654,19 @@ public final class HttpBindManager { ...@@ -689,41 +654,19 @@ public final class HttpBindManager {
if (value == bindPort) { if (value == bindPort) {
return; return;
} }
try { restartServer();
changeHttpBindPorts(value, JiveGlobals.getIntProperty(HTTP_BIND_SECURE_PORT,
HTTP_BIND_SECURE_PORT_DEFAULT));
bindPort = value;
}
catch (Exception ex) {
Log.error("Error setting HTTP bind ports", ex);
}
} }
private void setSecureHttpBindPort(int value) { private void setSecureHttpBindPort(int value) {
if (value == bindSecurePort) { if (value == bindSecurePort) {
return; return;
} }
try { restartServer();
changeHttpBindPorts(JiveGlobals.getIntProperty(HTTP_BIND_PORT,
HTTP_BIND_PORT_DEFAULT), value);
bindSecurePort = value;
}
catch (Exception ex) {
Log.error("Error setting HTTP bind ports", ex);
}
} }
private synchronized void restartServer() { private synchronized void restartServer() {
if (httpBindServer != null) { stop();
try { start();
httpBindServer.stop();
}
catch (Exception e) {
Log.error("Error stopping http bind server", e);
}
configureHttpBindServer(getHttpBindUnsecurePort(), getHttpBindSecurePort());
}
} }
/** Listens for changes to Jive properties that affect the HTTP server manager. */ /** Listens for changes to Jive properties that affect the HTTP server manager. */
......
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