Commit 7719a088 authored by Alex Wenckus's avatar Alex Wenckus Committed by alex

We are up and running.

git-svn-id: http://svn.igniterealtime.org/svn/repos/wildfire/branches@5744 b35dd754-fafc-0310-a699-88a17e54d16e
parent dc0a6461
......@@ -19,6 +19,7 @@ junit.jar | 3.8.1
jdic.jar | 0.9.1 (for windows only)
jstl.jar | Jakarta standard taglib 1.1.2
jmdns.jar | 1.0 RC1
jsp-api.jar | Jetty 6.1.0 (2.0)
jtds.jar | 1.2
jzlib.jar | 1.0.7
mysql.jar | 3.1.13
......
......@@ -12,6 +12,7 @@
package org.jivesoftware.wildfire;
import org.jivesoftware.wildfire.net.SocketReader;
import org.mortbay.jetty.Server;
import java.io.IOException;
import java.net.Socket;
......@@ -208,4 +209,13 @@ public interface ConnectionManager {
* @return the port to use for connection managers.
*/
public int getConnectionManagerListenerPort();
/**
* Returns the jetty server.
*
* @return the jetty server.
*/
Server getHttpServer();
void setHttpServer(Server server);
}
......@@ -14,15 +14,15 @@ import org.jivesoftware.util.JiveGlobals;
import org.jivesoftware.util.LocaleUtils;
import org.jivesoftware.util.Log;
import org.jivesoftware.wildfire.XMPPServer;
import org.mortbay.http.HttpContext;
import org.mortbay.http.HttpListener;
import org.mortbay.http.SunJsseListener;
import org.jivesoftware.wildfire.ConnectionManager;
import org.jivesoftware.wildfire.net.SSLConfig;
import org.mortbay.jetty.Connector;
import org.mortbay.jetty.Server;
import org.mortbay.log.Factory;
import org.mortbay.log.LogImpl;
import org.mortbay.log.OutputStreamLogSink;
import org.mortbay.util.InetAddrPort;
import org.mortbay.jetty.nio.SelectChannelConnector;
import org.mortbay.jetty.security.SslSocketConnector;
import org.mortbay.jetty.webapp.WebAppContext;
import javax.net.ssl.SSLServerSocketFactory;
import java.io.File;
/**
......@@ -33,19 +33,29 @@ import java.io.File;
*/
public class AdminConsolePlugin implements Plugin {
private static Server jetty = null;
private static Server server = null;
private int port;
private int securePort;
private File pluginDir;
private HttpContext context = null;
private HttpListener plainListener = null;
private HttpListener secureListener = null;
private WebAppContext context = null;
private Connector plainListener = null;
private Connector secureListener = null;
/**
* Create a jetty module.
*/
public AdminConsolePlugin() {
ConnectionManager manager = XMPPServer.getInstance().getConnectionManager();
if(manager != null) {
server = manager.getHttpServer();
}
if(server == null) {
server = new Server();
if(manager != null) {
manager.setHttpServer(server);
}
}
}
public void restartListeners() {
......@@ -54,33 +64,21 @@ public class AdminConsolePlugin implements Plugin {
System.out.println(restarting);
Log.info(restarting);
jetty.stop();
server.stop();
if (plainListener != null) {
jetty.removeListener(plainListener);
server.removeConnector(plainListener);
plainListener = null;
}
if (secureListener != null) {
jetty.removeListener(secureListener);
server.removeConnector(secureListener);
secureListener = null;
}
jetty.removeContext(context);
server.removeHandler(context);
loadListeners();
// Add web-app. Check to see if we're in development mode. If so, we don't
// add the normal web-app location, but the web-app in the project directory.
if (Boolean.getBoolean("developmentMode")) {
System.out.println(LocaleUtils.getLocalizedString("admin.console.devmode"));
context = jetty.addWebApplication("/",
pluginDir.getParentFile().getParentFile().getParent() + File.separator + "src" +
File.separator + "web");
}
else {
context = jetty.addWebApplication("/",
pluginDir.getAbsoluteFile() + File.separator + "webapp");
}
context.setWelcomeFiles(new String[]{"index.jsp"});
jetty.start();
context = createWebAppContext();
server.addHandler(context);
server.start();
printListenerMessages();
}
......@@ -93,35 +91,33 @@ public class AdminConsolePlugin implements Plugin {
// Configure HTTP socket listener. Setting the interface property to a
// non null value will imply that the Jetty server will only
// accept connect requests to that IP address.
String interfaceName = JiveGlobals.getXMLProperty("network.interface");
// String interfaceName = JiveGlobals.getXMLProperty("network.interface");
port = JiveGlobals.getXMLProperty("adminConsole.port", 9090);
InetAddrPort address = new InetAddrPort(interfaceName, port);
SelectChannelConnector connector = new SelectChannelConnector();
connector.setPort(port);
// InetAddrPort address = new InetAddrPort(interfaceName, port);
if (port > 0) {
plainListener = jetty.addListener(address);
plainListener = connector;
server.addConnector(connector);
}
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");
// The location is relative to the home directory of the application.
keyStoreLocation = JiveGlobals.getHomeDirectory() + File.separator + keyStoreLocation;
SslSocketConnector secureConnector = new JiveSslConnector();
secureConnector.setPort(securePort);
// Get the keystore password. The default password is "changeit".
String keypass = JiveGlobals.getProperty("xmpp.socket.ssl.keypass", "changeit");
keypass = keypass.trim();
secureConnector.setTrustPassword(SSLConfig.getTrustPassword());
secureConnector.setTruststoreType(SSLConfig.getStoreType());
secureConnector.setTruststore(SSLConfig.getTruststoreLocation());
secureConnector.setNeedClientAuth(false);
secureConnector.setWantClientAuth(false);
listener.setKeystore(keyStoreLocation);
listener.setKeyPassword(keypass);
listener.setPassword(keypass);
listener.setHost(interfaceName);
listener.setPort(securePort);
secureListener = jetty.addListener(listener);
secureConnector.setKeyPassword(SSLConfig.getKeyPassword());
secureConnector.setKeystoreType(SSLConfig.getStoreType());
secureConnector.setKeystore(SSLConfig.getKeystoreLocation());
secureListener = secureConnector;
server.addConnector(secureListener);
}
}
catch (Exception e) {
......@@ -132,9 +128,7 @@ public class AdminConsolePlugin implements Plugin {
public void initializePlugin(PluginManager manager, File pluginDir) {
this.pluginDir = pluginDir;
try {
// Configure logging to a file, creating log dir if needed
System.setProperty("org.apache.commons.logging.LogFactory", "org.mortbay.log.Factory");
File logDir = null;
File logDir;
String logDirectory = JiveGlobals.getXMLProperty("log.directory");
// Check if the "log.directory" was defined
if (logDirectory != null) {
......@@ -151,45 +145,28 @@ public class AdminConsolePlugin implements Plugin {
if (!logDir.exists()) {
logDir.mkdirs();
}
File logFile = new File(logDir, "admin-console.log");
OutputStreamLogSink logSink = new OutputStreamLogSink(logFile.toString());
logSink.start();
// In some cases, commons-logging settings can be stomped by other
// libraries in the classpath. Make sure that hasn't happened before
// setting configuration.
Object logImpl = Factory.getFactory().getInstance("");
if (logImpl instanceof LogImpl) {
LogImpl log = (LogImpl)logImpl;
// Ignore INFO logs unless debugging turned on.
if (Log.isDebugEnabled() &&
JiveGlobals.getBooleanProperty("jetty.debug.enabled", true)) {
log.setVerbose(1);
}
else {
log.setVerbose(-1);
}
log.add(logSink);
}
jetty = new Server();
// File logFile = new File(logDir, "admin-console.log");
// OutputStreamLogSink logSink = new OutputStreamLogSink(logFile.toString());
// logSink.start();
// // In some cases, commons-logging settings can be stomped by other
// // libraries in the classpath. Make sure that hasn't happened before
// // setting configuration.
// Logger log = (Logger) LogFactory.getFactory().getInstance("");
// // Ignore INFO logs unless debugging turned on.
// if (Log.isDebugEnabled() &&
// JiveGlobals.getBooleanProperty("jetty.debug.enabled", true)) {
// log.setVerbose(1);
// }
// else {
// log.setVerbose(-1);
// }
// log.add(logSink);
loadListeners();
// Add web-app. Check to see if we're in development mode. If so, we don't
// add the normal web-app location, but the web-app in the project directory.
if (Boolean.getBoolean("developmentMode")) {
System.out.println(LocaleUtils.getLocalizedString("admin.console.devmode"));
context = jetty.addWebApplication("/",
pluginDir.getParentFile().getParentFile().getParent() + File.separator + "src" +
File.separator + "web");
}
else {
context = jetty.addWebApplication("/",
pluginDir.getAbsoluteFile() + File.separator + "webapp");
}
context.setWelcomeFiles(new String[]{"index.jsp"});
jetty.start();
context = createWebAppContext();
server.addHandler(context);
server.start();
printListenerMessages();
}
......@@ -199,16 +176,34 @@ public class AdminConsolePlugin implements Plugin {
}
}
private WebAppContext createWebAppContext() {
WebAppContext context;
// Add web-app. Check to see if we're in development mode. If so, we don't
// add the normal web-app location, but the web-app in the project directory.
if (Boolean.getBoolean("developmentMode")) {
System.out.println(LocaleUtils.getLocalizedString("admin.console.devmode"));
context = new WebAppContext(
pluginDir.getParentFile().getParentFile().getParent() + File.separator +
"src" + File.separator + "web", "/");
}
else {
context = new WebAppContext(pluginDir.getAbsoluteFile() + File.separator + "webapp",
"/");
}
context.setWelcomeFiles(new String[]{"index.jsp"});
return context;
}
public void destroyPlugin() {
plainListener = null;
secureListener = null;
try {
if (jetty != null) {
jetty.stop();
jetty = null;
if (server != null) {
server.stop();
server = null;
}
}
catch (InterruptedException e) {
catch (Exception e) {
Log.error(LocaleUtils.getLocalizedString("admin.error"), e);
}
}
......@@ -219,7 +214,7 @@ public class AdminConsolePlugin implements Plugin {
* @return the Jetty server instance.
*/
public static Server getJettyServer() {
return jetty;
return server;
}
/**
......@@ -255,4 +250,11 @@ public class AdminConsolePlugin implements Plugin {
System.out.println(msg);
}
}
public class JiveSslConnector extends SslSocketConnector {
@Override
protected SSLServerSocketFactory createFactory() throws Exception {
return SSLConfig.getServerSocketFactory();
}
}
}
\ No newline at end of file
/**
* $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.Server;
import org.mortbay.jetty.Connector;
import org.mortbay.jetty.Handler;
import org.mortbay.jetty.security.SslSocketConnector;
import org.mortbay.jetty.servlet.ServletHolder;
import org.mortbay.jetty.servlet.ServletHandler;
import org.mortbay.jetty.nio.SelectChannelConnector;
import org.jivesoftware.util.Log;
import org.jivesoftware.wildfire.net.SSLConfig;
import javax.net.ssl.SSLServerSocketFactory;
/**
* Manages connections to the server which use the HTTP Bind protocol specified in <a
* href="http://www.xmpp.org/extensions/xep-0124.html">XEP-0124</a>. The manager maps a servlet to
* an embedded servlet container using the ports provided in the constructor.
*
* @author Alexander Wenckus
*/
public class HttpBindManager {
private int plainPort;
private int sslPort;
private Server server;
private String serverName;
public HttpBindManager(String serverName, int plainPort, int sslPort) {
this.plainPort = plainPort;
this.sslPort = sslPort;
this.server = new Server();
this.serverName = serverName;
}
/**
* Starts the HTTP Bind service.
*
* @throws Exception if there is an error starting up the server.
*/
public void startup() throws Exception {
for(Connector connector : createConnectors()) {
server.addConnector(connector);
}
server.addHandler(createServletHandler());
server.start();
}
private Handler createServletHandler() {
ServletHolder servletHolder = new ServletHolder(
new HttpBindServlet(new HttpSessionManager(serverName)));
ServletHandler servletHandler = new ServletHandler();
servletHandler.addServletWithMapping(servletHolder, "/");
return servletHandler;
}
private Connector[] createConnectors() {
SelectChannelConnector connector = new SelectChannelConnector();
connector.setPort(plainPort);
if (sslPort > 0) {
try {
SslSocketConnector secureConnector = new JiveSslConnector();
secureConnector.setPort(sslPort);
secureConnector.setTrustPassword(SSLConfig.getTrustPassword());
secureConnector.setTruststoreType(SSLConfig.getStoreType());
secureConnector.setTruststore(SSLConfig.getTruststoreLocation());
secureConnector.setNeedClientAuth(false);
secureConnector.setWantClientAuth(false);
secureConnector.setKeyPassword(SSLConfig.getKeyPassword());
secureConnector.setKeystoreType(SSLConfig.getStoreType());
secureConnector.setKeystore(SSLConfig.getKeystoreLocation());
return new Connector[]{connector, secureConnector};
}
catch (Exception ex) {
Log.error("Error establishing SSL connector for HTTP Bind", ex);
}
}
return new Connector[]{connector};
}
/**
* Shutdown the HTTP Bind service, freeing any related resources.
*
* @throws Exception if there is an error shutting down the service.
*/
public void shutdown() throws Exception {
server.stop();
}
private class JiveSslConnector extends SslSocketConnector {
@Override
protected SSLServerSocketFactory createFactory() throws Exception {
return SSLConfig.getServerSocketFactory();
}
}
}
......@@ -46,7 +46,7 @@ public class HttpBindServlet extends HttpServlet {
}
}
HttpBindServlet(HttpSessionManager sessionManager) {
public HttpBindServlet(HttpSessionManager sessionManager) {
this.sessionManager = sessionManager;
}
......
......@@ -134,11 +134,11 @@ public class HttpSession extends ClientSession {
return null;
}
public void close() {
public synchronized void close() {
conn.close();
}
private synchronized void close(boolean isServerShuttingDown) {
private synchronized void closeConnection() {
if(isClosed) {
return;
}
......@@ -175,7 +175,7 @@ public class HttpSession extends ClientSession {
deliver(new Deliverable(text));
}
public synchronized void deliver(Packet stanza) {
private synchronized void deliver(Packet stanza) {
deliver(new Deliverable(stanza));
}
......@@ -332,7 +332,7 @@ public class HttpSession extends ClientSession {
public static class HttpVirtualConnection extends VirtualConnection {
public void closeVirtualConnection() {
((HttpSession)session).close(false);
((HttpSession)session).closeConnection();
}
public InetAddress getInetAddress() {
......@@ -340,7 +340,7 @@ public class HttpSession extends ClientSession {
}
public void systemShutdown() {
((HttpSession)session).close(true);
((HttpSession)session).closeConnection();
}
public void deliver(Packet packet) throws UnauthorizedException {
......@@ -353,7 +353,6 @@ public class HttpSession extends ClientSession {
}
private class Deliverable {
private final String text;
private final Packet packet;
......
......@@ -55,7 +55,6 @@ public class HttpSessionManager {
*/
private static int pollingInterval;
private String serverName;
private InactivityTimer timer = new InactivityTimer();
private SessionManager sessionManager;
private Map<String, HttpSession> sessionMap = new HashMap<String, HttpSession>();
......@@ -67,8 +66,7 @@ public class HttpSessionManager {
pollingInterval = JiveGlobals.getIntProperty("xmpp.httpbind.client.requests.polling", 5);
}
public HttpSessionManager(String serverName) {
this.serverName = serverName;
public HttpSessionManager() {
this.sessionManager = SessionManager.getInstance();
}
......@@ -90,7 +88,7 @@ public class HttpSessionManager {
int wait = getIntAttribute(rootNode.attributeValue("wait"), 60);
int hold = getIntAttribute(rootNode.attributeValue("hold"), 1);
HttpSession session = createSession(serverName);
HttpSession session = createSession();
session.setWait(wait);
session.setHold(hold);
session.setSecure(connection.isSecure());
......@@ -109,12 +107,11 @@ public class HttpSessionManager {
return session;
}
private HttpSession createSession(String serverName) throws UnauthorizedException {
private HttpSession createSession() throws UnauthorizedException {
// Create a ClientSession for this user.
StreamID streamID = SessionManager.getInstance().nextStreamID();
HttpSession session = new HttpSession(serverName, streamID);
// Send to the server that a new client session has been created
sessionManager.createClientHttpSession(streamID);
HttpSession session = sessionManager.createClientHttpSession(streamID);
// Register that the new session is associated with the specified stream ID
sessionMap.put(streamID.getID(), session);
session.addSessionCloseListener(new SessionListener() {
......
......@@ -15,12 +15,16 @@ import org.jivesoftware.util.JiveGlobals;
import org.jivesoftware.util.LocaleUtils;
import org.jivesoftware.util.Log;
import org.jivesoftware.wildfire.*;
import org.jivesoftware.wildfire.http.HttpSessionManager;
import org.jivesoftware.wildfire.http.HttpBindServlet;
import org.jivesoftware.wildfire.container.BasicModule;
import org.jivesoftware.wildfire.container.AdminConsolePlugin;
import org.jivesoftware.wildfire.multiplex.MultiplexerPacketDeliverer;
import org.jivesoftware.wildfire.net.*;
import org.mortbay.jetty.Server;
import org.mortbay.jetty.Handler;
import org.mortbay.jetty.servlet.ServletHolder;
import org.mortbay.jetty.servlet.ServletHandler;
import java.io.IOException;
import java.net.InetAddress;
import java.net.Socket;
......@@ -50,10 +54,12 @@ public class ConnectionManagerImpl extends BasicModule implements ConnectionMana
private boolean isStarted = false;
// Used to know if the sockets have been started
private boolean isSocketStarted = false;
private Server jettyServer;
public ConnectionManagerImpl() {
super("Connection Manager");
ports = new ArrayList<ServerPort>(4);
jettyServer = new Server();
}
private void createSocket() {
......@@ -287,10 +293,22 @@ public class ConnectionManagerImpl extends BasicModule implements ConnectionMana
}
private void startHTTPBindListeners() {
Server jetty = AdminConsolePlugin.getJettyServer();
if(jetty == null) {
return;
if(jettyServer == null) {
jettyServer = AdminConsolePlugin.getJettyServer();
if(jettyServer == null) {
return;
}
}
jettyServer.addHandler(createServletHandler());
}
private Handler createServletHandler() {
ServletHolder servletHolder = new ServletHolder(
new HttpBindServlet(new HttpSessionManager()));
ServletHandler servletHandler = new ServletHandler();
servletHandler.addServletWithMapping(servletHolder, "/http-bind/");
return servletHandler;
}
public void initialize(XMPPServer server) {
......@@ -502,6 +520,14 @@ public class ConnectionManagerImpl extends BasicModule implements ConnectionMana
SocketAcceptThread.DEFAULT_MULTIPLEX_PORT);
}
public Server getHttpServer() {
return jettyServer;
}
public void setHttpServer(Server server) {
this.jettyServer = server;
}
// #####################################################################
// Module management
// #####################################################################
......
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