Commit a4f1e438 authored by Alex Wenckus's avatar Alex Wenckus Committed by alex

Javadocs + code reformat.

git-svn-id: http://svn.igniterealtime.org/svn/repos/wildfire/trunk@5933 b35dd754-fafc-0310-a699-88a17e54d16e
parent 14af0930
...@@ -32,7 +32,7 @@ import java.util.ArrayList; ...@@ -32,7 +32,7 @@ import java.util.ArrayList;
import java.util.Map; import java.util.Map;
/** /**
* Manages the instances of Jetty which provide the admin console funtionality and the http binding * Manages the instances of Jetty which provide the admin console funtionality and the HTTP binding
* functionality. * functionality.
* *
* @author Alexander Wenckus * @author Alexander Wenckus
...@@ -77,16 +77,29 @@ public class HttpServerManager { ...@@ -77,16 +77,29 @@ public class HttpServerManager {
PropertyEventDispatcher.addListener(new HttpServerPropertyListener()); PropertyEventDispatcher.addListener(new HttpServerPropertyListener());
// Configure Jetty logging to a more reasonable default. // Configure Jetty logging to a more reasonable default.
System.setProperty("org.mortbay.log.class", "org.jivesoftware.wildfire.HttpServerManager$JettyLog"); System.setProperty("org.mortbay.log.class",
"org.jivesoftware.wildfire.HttpServerManager$JettyLog");
// JSP 2.0 uses commons-logging, so also override that implementation. // JSP 2.0 uses commons-logging, so also override that implementation.
System.setProperty("org.apache.commons.logging.LogFactory", System.setProperty("org.apache.commons.logging.LogFactory",
"org.jivesoftware.wildfire.HttpServerManager$CommonsLogFactory"); "org.jivesoftware.wildfire.HttpServerManager$CommonsLogFactory");
} }
/**
* Sets the Jetty context which provides the functionality for the admin console.
*
* @param context the web-app context which provides functionality for the admin console.
*/
public void setAdminConsoleContext(Context context) { public void setAdminConsoleContext(Context context) {
this.adminConsoleContext = context; this.adminConsoleContext = context;
} }
/**
* Sets up the parameters for the HTTP binding servlet.
*
* @param context the servlet holder context which holds the servlet serving up the HTTP binding
* service.
* @param httpBindPath the path to which the HTTP binding servlet will be bound.
*/
public void setHttpBindContext(ServletHolder context, String httpBindPath) { public void setHttpBindContext(ServletHolder context, String httpBindPath) {
this.httpBindContext = context; this.httpBindContext = context;
this.httpBindPath = httpBindPath; this.httpBindPath = httpBindPath;
...@@ -102,7 +115,7 @@ public class HttpServerManager { ...@@ -102,7 +115,7 @@ public class HttpServerManager {
private void createHttpBindServer(int port, int securePort) { private void createHttpBindServer(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) {
httpBindServer = null; httpBindServer = null;
return; return;
} }
...@@ -121,8 +134,8 @@ public class HttpServerManager { ...@@ -121,8 +134,8 @@ public class HttpServerManager {
adminServer = httpBindServer; adminServer = httpBindServer;
loadConnectors = false; loadConnectors = false;
} }
else if (checkPorts(new int[] { this.port, this.securePort }, else if (checkPorts(new int[]{this.port, this.securePort},
new int [] {port, securePort})) new int[]{port, securePort}))
{ {
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.");
...@@ -143,7 +156,7 @@ public class HttpServerManager { ...@@ -143,7 +156,7 @@ public class HttpServerManager {
if (connectors.size() == 0) { if (connectors.size() == 0) {
adminServer = null; adminServer = null;
// Log warning. // Log warning.
String warning = LocaleUtils.getLocalizedString("admin.console.warning"); String warning = LocaleUtils.getLocalizedString("admin.console.warning");
Log.info(warning); Log.info(warning);
System.out.println(warning); System.out.println(warning);
...@@ -155,6 +168,11 @@ public class HttpServerManager { ...@@ -155,6 +168,11 @@ public class HttpServerManager {
adminServer.addConnector(connector); adminServer.addConnector(connector);
} }
} }
logAdminConsolePorts();
}
private void logAdminConsolePorts() {
// Log what ports the admin console is running on. // Log what ports the admin console is running on.
String listening = LocaleUtils.getLocalizedString("admin.console.listening"); String listening = LocaleUtils.getLocalizedString("admin.console.listening");
boolean isPlainStarted = false; boolean isPlainStarted = false;
...@@ -191,12 +209,17 @@ public class HttpServerManager { ...@@ -191,12 +209,17 @@ public class HttpServerManager {
} }
} }
private boolean checkPorts(int [] httpBindPorts, int [] adminConsolePorts) { private boolean checkPorts(int[] httpBindPorts, int[] adminConsolePorts) {
return httpBindPorts[0] == adminConsolePorts[0] || httpBindPorts[0] == adminConsolePorts[0] return httpBindPorts[0] == adminConsolePorts[0] || httpBindPorts[0] == adminConsolePorts[0]
|| httpBindPorts[1] == adminConsolePorts[0] || httpBindPorts[1] == adminConsolePorts[0]
|| 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() { public void startup() {
if (httpBindContext != null && isHttpBindServiceEnabled()) { if (httpBindContext != null && isHttpBindServiceEnabled()) {
createHttpBindServer(); createHttpBindServer();
...@@ -207,7 +230,7 @@ public class HttpServerManager { ...@@ -207,7 +230,7 @@ public class HttpServerManager {
addContexts(); addContexts();
if(httpBindServer != null) { if (httpBindServer != null) {
try { try {
httpBindServer.start(); httpBindServer.start();
} }
...@@ -215,7 +238,7 @@ public class HttpServerManager { ...@@ -215,7 +238,7 @@ public class HttpServerManager {
Log.error("Could not start HTTP bind server", e); Log.error("Could not start HTTP bind server", e);
} }
} }
if(adminServer != null && adminServer != httpBindServer) { if (adminServer != null && adminServer != httpBindServer) {
try { try {
adminServer.start(); adminServer.start();
} }
...@@ -238,7 +261,7 @@ public class HttpServerManager { ...@@ -238,7 +261,7 @@ public class HttpServerManager {
return; return;
} }
if (adminServer != null) { if (adminServer != null) {
if(adminServer.getHandler() != null) { if (adminServer.getHandler() != null) {
removeHttpBindServlet(adminConsoleContext); removeHttpBindServlet(adminConsoleContext);
} }
else { else {
...@@ -256,17 +279,17 @@ public class HttpServerManager { ...@@ -256,17 +279,17 @@ public class HttpServerManager {
ServletHandler handler = adminConsoleContext.getServletHandler(); ServletHandler handler = adminConsoleContext.getServletHandler();
ServletMapping[] servletMappings = handler.getServletMappings(); ServletMapping[] servletMappings = handler.getServletMappings();
List<ServletMapping> toAdd = new ArrayList<ServletMapping>(); List<ServletMapping> toAdd = new ArrayList<ServletMapping>();
for(ServletMapping mapping : servletMappings) { for (ServletMapping mapping : servletMappings) {
if(mapping.getServletName().equals(httpBindContext.getName())) { if (mapping.getServletName().equals(httpBindContext.getName())) {
continue; continue;
} }
toAdd.add(mapping); toAdd.add(mapping);
} }
ServletHolder [] servletHolder = handler.getServlets(); ServletHolder[] servletHolder = handler.getServlets();
List<ServletHolder> toAddServlets = new ArrayList<ServletHolder>(); List<ServletHolder> toAddServlets = new ArrayList<ServletHolder>();
for(ServletHolder holder : servletHolder) { for (ServletHolder holder : servletHolder) {
if(holder.equals(httpBindContext)) { if (holder.equals(httpBindContext)) {
continue; continue;
} }
toAddServlets.add(holder); toAddServlets.add(holder);
...@@ -276,6 +299,9 @@ public class HttpServerManager { ...@@ -276,6 +299,9 @@ 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() { public void shutdown() {
if (httpBindServer != null) { if (httpBindServer != null) {
try { try {
...@@ -331,9 +357,9 @@ public class HttpServerManager { ...@@ -331,9 +357,9 @@ public class HttpServerManager {
} }
/** /**
* Returns true if the HTTP bind server is currently enabled. * Returns true if the HTTP binding server is currently enabled.
* *
* @return true if the HTTP bind server is currently enabled. * @return true if the HTTP binding server is currently enabled.
*/ */
public boolean isHttpBindEnabled() { public boolean isHttpBindEnabled() {
return httpBindServer != null && httpBindServer.isRunning(); return httpBindServer != null && httpBindServer.isRunning();
...@@ -362,11 +388,11 @@ public class HttpServerManager { ...@@ -362,11 +388,11 @@ public class HttpServerManager {
* console. * console.
* *
* @return true if the HTTP binding service is running on a seperate server than the admin * @return true if the HTTP binding service is running on a seperate server than the admin
* console. * console.
*/ */
public boolean isSeperateHttpBindServerConfigured() { public boolean isSeperateHttpBindServerConfigured() {
return (httpBindServer != null && httpBindServer != adminServer) || (httpBindServer == null return (httpBindServer != null && httpBindServer != adminServer) || (httpBindServer == null
&& (getAdminUnsecurePort() != JiveGlobals.getIntProperty(HTTP_BIND_PORT, 9090) && (getAdminUnsecurePort() != JiveGlobals.getIntProperty(HTTP_BIND_PORT, 9090)
|| getAdminSecurePort() || getAdminSecurePort()
!= JiveGlobals.getIntProperty(HTTP_BIND_SECURE_PORT, 9091))); != JiveGlobals.getIntProperty(HTTP_BIND_SECURE_PORT, 9091)));
} }
...@@ -376,7 +402,7 @@ public class HttpServerManager { ...@@ -376,7 +402,7 @@ public class HttpServerManager {
} }
/** /**
* Set the ports on which the HTTP bind service will be running. * Set the ports on which the HTTP binding service will be running.
* *
* @param unsecurePort the unsecured connection port which clients can connect to. * @param unsecurePort the unsecured connection port which clients can connect to.
* @param securePort the secured connection port which clients can connect to. * @param securePort the secured connection port which clients can connect to.
...@@ -412,7 +438,7 @@ public class HttpServerManager { ...@@ -412,7 +438,7 @@ public class HttpServerManager {
if (checkPorts(new int[]{unsecurePort, securePort}, if (checkPorts(new int[]{unsecurePort, securePort},
new int[]{adminPort, adminSecurePort})) new int[]{adminPort, adminSecurePort}))
{ {
if(unsecurePort != adminPort || securePort != adminSecurePort) { if (unsecurePort != adminPort || securePort != adminSecurePort) {
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, http binding will run on the admin console ports."); " ports, http binding will run on the admin console ports.");
} }
...@@ -451,22 +477,32 @@ public class HttpServerManager { ...@@ -451,22 +477,32 @@ 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() { public int getAdminUnsecurePort() {
return JiveGlobals.getXMLProperty(ADMIN_CONSOLE_PORT, ADMIN_CONSOLE_PORT_DEFAULT); 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() { public int getAdminSecurePort() {
return JiveGlobals.getXMLProperty(ADMIN_CONOSLE_SECURE_PORT, return JiveGlobals.getXMLProperty(ADMIN_CONOSLE_SECURE_PORT,
ADMIN_CONSOLE_SECURE_PORT_DEFAULT); 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,
ADMIN_CONSOLE_PORT_DEFAULT),JiveGlobals.getIntProperty(HTTP_BIND_SECURE_PORT, ADMIN_CONSOLE_PORT_DEFAULT), JiveGlobals.getIntProperty(HTTP_BIND_SECURE_PORT,
ADMIN_CONSOLE_SECURE_PORT_DEFAULT)); ADMIN_CONSOLE_SECURE_PORT_DEFAULT));
} }
else if(!shouldEnable && httpBindServer != null) { else if (!shouldEnable && httpBindServer != null) {
if (httpBindServer != adminServer) { if (httpBindServer != adminServer) {
try { try {
httpBindServer.stop(); httpBindServer.stop();
...@@ -543,7 +579,7 @@ public class HttpServerManager { ...@@ -543,7 +579,7 @@ public class HttpServerManager {
} }
public void propertyDeleted(String property, Map params) { public void propertyDeleted(String property, Map params) {
if(property.equalsIgnoreCase(HTTP_BIND_ENABLED)) { if (property.equalsIgnoreCase(HTTP_BIND_ENABLED)) {
doEnableHttpBind(HTTP_BIND_ENABLED_DEFAULT); doEnableHttpBind(HTTP_BIND_ENABLED_DEFAULT);
} }
else if (property.equalsIgnoreCase(HTTP_BIND_PORT)) { else if (property.equalsIgnoreCase(HTTP_BIND_PORT)) {
...@@ -570,8 +606,8 @@ public class HttpServerManager { ...@@ -570,8 +606,8 @@ public class HttpServerManager {
} }
/** /**
* A Logger implementation to override the default Jetty logging behavior. All log statements are * A Logger implementation to override the default Jetty logging behavior. All log statements
* written to the Wildfire logs. Info level logging is sent to debug. * are written to the Wildfire logs. Info level logging is sent to debug.
*/ */
public static class JettyLog implements Logger { public static class JettyLog implements Logger {
...@@ -610,8 +646,8 @@ public class HttpServerManager { ...@@ -610,8 +646,8 @@ public class HttpServerManager {
} }
/** /**
* A LogFactory implementation to override the default commons-logging behavior. All log statements are * A LogFactory implementation to override the default commons-logging behavior. All log
* written to the Wildfire logs. Info level logging is sent to debug. * statements are written to the Wildfire logs. Info level logging is sent to debug.
*/ */
public static class CommonsLogFactory extends LogFactory { public static class CommonsLogFactory extends LogFactory {
...@@ -704,11 +740,15 @@ public class HttpServerManager { ...@@ -704,11 +740,15 @@ public class HttpServerManager {
return new String[0]; return new String[0];
} }
public org.apache.commons.logging.Log getInstance(Class aClass) throws LogConfigurationException { public org.apache.commons.logging.Log getInstance(Class aClass)
throws LogConfigurationException
{
return log; return log;
} }
public org.apache.commons.logging.Log getInstance(String string) throws LogConfigurationException { public org.apache.commons.logging.Log getInstance(String string)
throws LogConfigurationException
{
return log; return log;
} }
...@@ -721,7 +761,7 @@ public class HttpServerManager { ...@@ -721,7 +761,7 @@ public class HttpServerManager {
} }
public void setAttribute(String string, Object object) { public void setAttribute(String string, Object object) {
} }
} }
} }
\ No newline at end of file
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