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

Multiple servlets can be now added to the http-binding service.

git-svn-id: http://svn.igniterealtime.org/svn/repos/wildfire/trunk@6203 b35dd754-fafc-0310-a699-88a17e54d16e
parent 72532e72
...@@ -31,6 +31,7 @@ import java.security.cert.X509Certificate; ...@@ -31,6 +31,7 @@ import java.security.cert.X509Certificate;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Arrays;
/** /**
* 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
...@@ -62,6 +63,7 @@ public class HttpServerManager { ...@@ -62,6 +63,7 @@ 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). * Returns an HTTP server manager instance (singleton).
* *
...@@ -78,8 +80,7 @@ public class HttpServerManager { ...@@ -78,8 +80,7 @@ public class HttpServerManager {
private Server adminServer; private Server adminServer;
private Server httpBindServer; private Server httpBindServer;
private Context adminConsoleContext; private Context adminConsoleContext;
private ServletHolder httpBindContext; private Map<ServletHolder, String> httpBindContexts;
private String httpBindPath;
private CertificateEventListener certificateListener; private CertificateEventListener certificateListener;
private boolean restartNeeded = false; private boolean restartNeeded = false;
...@@ -107,15 +108,12 @@ public class HttpServerManager { ...@@ -107,15 +108,12 @@ public class HttpServerManager {
} }
/** /**
* Sets up the parameters for the HTTP binding servlet. * Sets up the parameters for the HTTP binding service.
* *
* @param context the servlet holder context which holds the servlet serving up the HTTP binding * @param contexts a collection of servlets utilized by the HTTP binding service.
* service.
* @param httpBindPath the path to which the HTTP binding servlet will be bound.
*/ */
public void setHttpBindContext(ServletHolder context, String httpBindPath) { public void setHttpBindContext(Map<ServletHolder,String> contexts) {
this.httpBindContext = context; this.httpBindContexts = contexts;
this.httpBindPath = httpBindPath;
} }
/** /**
...@@ -129,7 +127,7 @@ public class HttpServerManager { ...@@ -129,7 +127,7 @@ public class HttpServerManager {
certificateListener = new CertificateListener(); certificateListener = new CertificateListener();
CertificateManager.addListener(certificateListener); CertificateManager.addListener(certificateListener);
if (httpBindContext != null && isHttpBindServiceEnabled()) { if (httpBindContexts != null && isHttpBindServiceEnabled()) {
bindPort = JiveGlobals.getIntProperty(HTTP_BIND_PORT, ADMIN_CONSOLE_PORT_DEFAULT); bindPort = JiveGlobals.getIntProperty(HTTP_BIND_PORT, ADMIN_CONSOLE_PORT_DEFAULT);
bindSecurePort = JiveGlobals.getIntProperty(HTTP_BIND_SECURE_PORT, bindSecurePort = JiveGlobals.getIntProperty(HTTP_BIND_SECURE_PORT,
ADMIN_CONSOLE_SECURE_PORT_DEFAULT); ADMIN_CONSOLE_SECURE_PORT_DEFAULT);
...@@ -172,8 +170,10 @@ public class HttpServerManager { ...@@ -172,8 +170,10 @@ public class HttpServerManager {
if (httpBindServer != null && httpBindServer.isRunning()) { if (httpBindServer != null && httpBindServer.isRunning()) {
httpBindServer.stop(); httpBindServer.stop();
} }
if (httpBindContext != null && httpBindContext.isRunning()) { if (httpBindContexts != null) {
httpBindContext.stop(); for(ServletHolder httpBindContext : httpBindContexts.keySet()) {
httpBindContext.stop();
}
} }
} }
catch (Exception e) { catch (Exception e) {
...@@ -416,7 +416,10 @@ public class HttpServerManager { ...@@ -416,7 +416,10 @@ public class HttpServerManager {
private void addContexts() { private void addContexts() {
if (httpBindServer == adminServer && httpBindServer != null) { if (httpBindServer == adminServer && httpBindServer != null) {
adminConsoleContext.addServlet(httpBindContext, httpBindPath); for (Map.Entry<ServletHolder, String> httpBindContext : httpBindContexts.entrySet()) {
adminConsoleContext.addServlet(httpBindContext.getKey(),
httpBindContext.getValue());
}
if (adminServer.getHandler() == null) { if (adminServer.getHandler() == null) {
adminServer.addHandler(adminConsoleContext); adminServer.addHandler(adminConsoleContext);
} }
...@@ -432,7 +435,10 @@ public class HttpServerManager { ...@@ -432,7 +435,10 @@ public class HttpServerManager {
} }
if (httpBindServer != null) { if (httpBindServer != null) {
ServletHandler servletHandler = new ServletHandler(); ServletHandler servletHandler = new ServletHandler();
servletHandler.addServletWithMapping(httpBindContext, httpBindPath); for (Map.Entry<ServletHolder, String> httpBindContext : httpBindContexts.entrySet()) {
servletHandler.addServletWithMapping(httpBindContext.getKey(),
httpBindContext.getValue());
}
httpBindServer.addHandler(servletHandler); httpBindServer.addHandler(servletHandler);
} }
} }
...@@ -446,21 +452,19 @@ public class HttpServerManager { ...@@ -446,21 +452,19 @@ 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>();
List<String> servletNames = new ArrayList<String>();
for(ServletHolder holder : httpBindContexts.keySet()) {
servletNames.add(holder.getName());
}
for (ServletMapping mapping : servletMappings) { for (ServletMapping mapping : servletMappings) {
if (mapping.getServletName().equals(httpBindContext.getName())) { if (servletNames.contains(mapping.getServletName())) {
continue; continue;
} }
toAdd.add(mapping); toAdd.add(mapping);
} }
ServletHolder[] servletHolder = handler.getServlets(); List<ServletHolder> toAddServlets = Arrays.asList(handler.getServlets());
List<ServletHolder> toAddServlets = new ArrayList<ServletHolder>(); toAddServlets.removeAll(httpBindContexts.keySet());
for (ServletHolder holder : servletHolder) {
if (holder.equals(httpBindContext)) {
continue;
}
toAddServlets.add(holder);
}
handler.setServletMappings(toAdd.toArray(new ServletMapping[toAdd.size()])); handler.setServletMappings(toAdd.toArray(new ServletMapping[toAdd.size()]));
handler.setServlets(toAddServlets.toArray(new ServletHolder[toAddServlets.size()])); handler.setServlets(toAddServlets.toArray(new ServletHolder[toAddServlets.size()]));
......
/**
* $RCSfile$
* $Revision: $
* $Date: $
*
* Copyright (C) 2006 Jive Software. All rights reserved.
*
* This software is published under the terms of the GNU Public License (GPL),
* a copy of which is included in this distribution.
*/
package org.jivesoftware.wildfire.http;
import org.mortbay.jetty.servlet.ServletHolder;
import java.util.Map;
import java.util.HashMap;
/**
*
*/
public class HttpBindManager {
private static HttpBindManager instance = new HttpBindManager();
public static HttpBindManager getInstance() {
return instance;
}
/**
* Returns all the servlets that are part of the http-bind service.
*
* @return all the servlets that are part of the http-bind service.
*/
public Map<ServletHolder, String> getServlets() {
Map<ServletHolder, String> servlets = new HashMap<ServletHolder, String>();
servlets.put(new ServletHolder(new HttpBindServlet(new HttpSessionManager())),
"/http-bind/");
return servlets;
}
}
...@@ -14,11 +14,9 @@ package org.jivesoftware.wildfire.spi; ...@@ -14,11 +14,9 @@ package org.jivesoftware.wildfire.spi;
import org.jivesoftware.util.*; import org.jivesoftware.util.*;
import org.jivesoftware.wildfire.*; import org.jivesoftware.wildfire.*;
import org.jivesoftware.wildfire.container.BasicModule; import org.jivesoftware.wildfire.container.BasicModule;
import org.jivesoftware.wildfire.http.HttpBindServlet; import org.jivesoftware.wildfire.http.HttpBindManager;
import org.jivesoftware.wildfire.http.HttpSessionManager;
import org.jivesoftware.wildfire.multiplex.MultiplexerPacketDeliverer; import org.jivesoftware.wildfire.multiplex.MultiplexerPacketDeliverer;
import org.jivesoftware.wildfire.net.*; import org.jivesoftware.wildfire.net.*;
import org.mortbay.jetty.servlet.ServletHolder;
import java.io.IOException; import java.io.IOException;
import java.net.InetAddress; import java.net.InetAddress;
...@@ -308,11 +306,7 @@ public class ConnectionManagerImpl extends BasicModule implements ConnectionMana ...@@ -308,11 +306,7 @@ public class ConnectionManagerImpl extends BasicModule implements ConnectionMana
} }
private void startHTTPBindListeners() { private void startHTTPBindListeners() {
serverManager.setHttpBindContext(createServletHandler(), "/http-bind/"); serverManager.setHttpBindContext(HttpBindManager.getInstance().getServlets());
}
private ServletHolder createServletHandler() {
return new ServletHolder(new HttpBindServlet(new HttpSessionManager()));
} }
public void initialize(XMPPServer server) { public void initialize(XMPPServer server) {
......
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