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);
}
/**
* $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