diff --git a/src/java/org/jivesoftware/multiplexer/net/http/HttpBindServlet.java b/src/java/org/jivesoftware/multiplexer/net/http/HttpBindServlet.java index 758e3b1..25c101f 100644 --- a/src/java/org/jivesoftware/multiplexer/net/http/HttpBindServlet.java +++ b/src/java/org/jivesoftware/multiplexer/net/http/HttpBindServlet.java @@ -69,15 +69,38 @@ String sid = node.attributeValue("sid"); // We have a new session if(sid == null) { - createNewSession(request, response, node); + createNewSession(response, node); } else { - + handleSessionRequest(sid, request, response, node); } } - private void createNewSession(HttpServletRequest request, HttpServletResponse response, - Element rootNode) throws IOException { + private void handleSessionRequest(String sid, HttpServletRequest request, + HttpServletResponse response, Element rootNode) + throws IOException + { + long rid = getLongAttribue(rootNode.attributeValue("rid"), -1); + if(rid <= 0) { + response.sendError(HttpServletResponse.SC_BAD_REQUEST, "Body missing RID (Request ID)"); + return; + } + + HttpSession session = sessionManager.getSession(sid); + if(session == null) { + Log.warn("Client provided invalid session: " + sid + ". [" + + request.getRemoteAddr() + "]"); + response.sendError(HttpServletResponse.SC_NOT_FOUND, "Invalid SID."); + return; + } + synchronized(session) { + sessionManager.forwardRequest(rid, session, rootNode); + } + } + + private void createNewSession(HttpServletResponse response, Element rootNode) + throws IOException + { long rid = getLongAttribue(rootNode.attributeValue("rid"), -1); if(rid <= 0) { response.sendError(HttpServletResponse.SC_BAD_REQUEST, "Body missing RID (Request ID)"); diff --git a/src/java/org/jivesoftware/multiplexer/net/http/HttpSession.java b/src/java/org/jivesoftware/multiplexer/net/http/HttpSession.java index a0413d3..67b278c 100644 --- a/src/java/org/jivesoftware/multiplexer/net/http/HttpSession.java +++ b/src/java/org/jivesoftware/multiplexer/net/http/HttpSession.java @@ -22,6 +22,7 @@ private int hold; private String language; private final Queue connectionQueue = new LinkedList(); + private String stanza; public HttpSession(String serverName, String streamID) { @@ -29,6 +30,7 @@ } void addConnection(HttpConnection connection) { + connection.setSession(this); connectionQueue.offer(connection); } @@ -42,7 +44,8 @@ public void close(boolean isServerShuttingDown) { } - public void deliver(Element stanza) { + public synchronized void deliver(Element stanza) { + this.stanza = stanza.asXML(); } /** diff --git a/src/java/org/jivesoftware/multiplexer/net/http/HttpSessionManager.java b/src/java/org/jivesoftware/multiplexer/net/http/HttpSessionManager.java index 7ad69c6..1180f74 100644 --- a/src/java/org/jivesoftware/multiplexer/net/http/HttpSessionManager.java +++ b/src/java/org/jivesoftware/multiplexer/net/http/HttpSessionManager.java @@ -14,6 +14,8 @@ import org.jivesoftware.multiplexer.Session; import org.dom4j.Element; +import java.util.List; + /** * */ @@ -49,6 +51,7 @@ private static int pollingInterval; private String serverName; + private ServerSurrogate serverSurrogate; static { // Set the default read idle timeout. If none was set then assume 30 minutes @@ -59,6 +62,7 @@ public HttpSessionManager(String serverName) { this.serverName = serverName; + this.serverSurrogate = ConnectionManager.getInstance().getServerSurrogate(); } public HttpSession getSession(String streamID) { @@ -81,7 +85,6 @@ int wait = getIntAttribute(rootNode.attributeValue("wait"), 60); int hold = getIntAttribute(rootNode.attributeValue("hold"), 1); - ServerSurrogate serverSurrogate = ConnectionManager.getInstance().getServerSurrogate(); // Indicate the compression policy to use for this connection connection.setCompressionPolicy(serverSurrogate.getCompressionPolicy()); @@ -90,7 +93,7 @@ session.setHold(hold); // Store language and version information in the connection. session.setLanaguage(language); - connection.deliverBody(createSessionCreationResponse(session, serverSurrogate)); + connection.deliverBody(createSessionCreationResponse(session)); return session; } @@ -119,9 +122,7 @@ } } - private static String createSessionCreationResponse(HttpSession session, - ServerSurrogate serverSurrogate) - { + private String createSessionCreationResponse(HttpSession session) { StringBuilder builder = new StringBuilder(); builder.append("