diff --git a/ConnectionManager.iml b/ConnectionManager.iml index e7c7005..90f2de7 100644 --- a/ConnectionManager.iml +++ b/ConnectionManager.iml @@ -1,7 +1,7 @@ - + diff --git a/ConnectionManager.ipr b/ConnectionManager.ipr index fe409b8..be3e73b 100644 --- a/ConnectionManager.ipr +++ b/ConnectionManager.ipr @@ -10,13 +10,19 @@ + + + + + + + + @@ -48,6 +68,48 @@ + + + @@ -79,108 +142,131 @@ + + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + + + + + + + + + + + + + + + + + + @@ -189,6 +275,7 @@ + + + + + + diff --git a/src/java/org/jivesoftware/multiplexer/net/http/HttpBindManager.java b/src/java/org/jivesoftware/multiplexer/net/http/HttpBindManager.java index 7515394..d4a78d7 100644 --- a/src/java/org/jivesoftware/multiplexer/net/http/HttpBindManager.java +++ b/src/java/org/jivesoftware/multiplexer/net/http/HttpBindManager.java @@ -1,10 +1,12 @@ /** - * $RCSfile: $ - * $Revision: $ - * $Date: $ + * $RCSfile$ + * $Revision: $ + * $Date: $ * * Copyright (C) 2006 Jive Software. All rights reserved. - * This software is the proprietary information of Jive Software. Use is subject to license terms. + * + * 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.multiplexer.net.http; @@ -16,7 +18,7 @@ /** * Manages connections to the server which use the HTTP Bind protocol specified in - * XEP-0124. The manager maps a servlet + * XEP-0124. The manager maps a servlet * to an embedded servlet container using the ports provided in the constructor. * * @author Alexander Wenckus @@ -34,6 +36,11 @@ this.serverName = serverName; } + /** + * Starts the HTTP Bind service. + * + * @throws Exception if there is an error starting up the server. + */ public void startup() throws Exception { SelectChannelConnector connector = new SelectChannelConnector(); connector.setPort(plainPort); @@ -48,6 +55,11 @@ server.start(); } + /** + * 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(); } diff --git a/src/java/org/jivesoftware/multiplexer/net/http/HttpBindServlet.java b/src/java/org/jivesoftware/multiplexer/net/http/HttpBindServlet.java index 92332fb..56ccc04 100644 --- a/src/java/org/jivesoftware/multiplexer/net/http/HttpBindServlet.java +++ b/src/java/org/jivesoftware/multiplexer/net/http/HttpBindServlet.java @@ -1,10 +1,12 @@ /** - * $RCSfile: $ - * $Revision: $ - * $Date: $ + * $RCSfile$ + * $Revision: $ + * $Date: $ * * Copyright (C) 2006 Jive Software. All rights reserved. - * This software is the proprietary information of Jive Software. Use is subject to license terms. + * + * 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.multiplexer.net.http; @@ -25,7 +27,9 @@ import java.io.IOException; /** + * Handles requests to the HTTP Bind service. * + * @author Alexander Wenckus */ public class HttpBindServlet extends HttpServlet { private HttpSessionManager sessionManager; @@ -41,14 +45,14 @@ } } - public HttpBindServlet(HttpSessionManager sessionManager) { + HttpBindServlet(HttpSessionManager sessionManager) { this.sessionManager = sessionManager; } @Override protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { - if(isContinuation(request, response)) { + if (isContinuation(request, response)) { return; } Document document; @@ -63,7 +67,7 @@ } Element node = document.getRootElement(); - if(node == null || !"body".equals(node.getName())) { + if (node == null || !"body".equals(node.getName())) { Log.warn("Body missing from request content. [" + request.getRemoteAddr() + "]"); response.sendError(HttpServletResponse.SC_BAD_REQUEST, "Body missing from request content."); @@ -72,7 +76,7 @@ String sid = node.attributeValue("sid"); // We have a new session - if(sid == null) { + if (sid == null) { createNewSession(response, node); } else { @@ -81,10 +85,9 @@ } private boolean isContinuation(HttpServletRequest request, HttpServletResponse response) - throws IOException - { + throws IOException { HttpConnection connection = (HttpConnection) request.getAttribute("request-connection"); - if(connection == null) { + if (connection == null) { return false; } respond(response, connection); @@ -93,22 +96,21 @@ private void handleSessionRequest(String sid, HttpServletRequest request, HttpServletResponse response, Element rootNode) - throws IOException - { + throws IOException { long rid = getLongAttribue(rootNode.attributeValue("rid"), -1); - if(rid <= 0) { + if (rid <= 0) { response.sendError(HttpServletResponse.SC_BAD_REQUEST, "Body missing RID (Request ID)"); return; } HttpSession session = sessionManager.getSession(sid); - if(session == null) { + if (session == null) { Log.warn("Client provided invalid session: " + sid + ". [" + request.getRemoteAddr() + "]"); response.sendError(HttpServletResponse.SC_NOT_FOUND, "Invalid SID."); return; } - synchronized(session) { + synchronized (session) { HttpConnection connection = sessionManager.forwardRequest(rid, session, rootNode); connection.setContinuation(ContinuationSupport.getContinuation(request, connection)); request.setAttribute("request-connection", connection); @@ -117,10 +119,9 @@ } private void createNewSession(HttpServletResponse response, Element rootNode) - throws IOException - { + throws IOException { long rid = getLongAttribue(rootNode.attributeValue("rid"), -1); - if(rid <= 0) { + if (rid <= 0) { response.sendError(HttpServletResponse.SC_BAD_REQUEST, "Body missing RID (Request ID)"); return; } @@ -131,9 +132,8 @@ } private void respond(HttpServletResponse response, HttpConnection connection) - throws IOException - { - byte [] content; + throws IOException { + byte[] content; try { content = connection.getDeliverable().getBytes("utf-8"); } @@ -154,7 +154,7 @@ } private long getLongAttribue(String value, long defaultValue) { - if(value == null || "".equals(value)) { + if (value == null || "".equals(value)) { return defaultValue; } try { @@ -166,8 +166,7 @@ } private Document createDocument(HttpServletRequest request) throws - DocumentException, IOException, XmlPullParserException - { + DocumentException, IOException, XmlPullParserException { // Reader is associated with a new XMPPPacketReader XMPPPacketReader reader = new XMPPPacketReader(); reader.setXPPFactory(factory); diff --git a/src/java/org/jivesoftware/multiplexer/net/http/HttpBindTimeoutException.java b/src/java/org/jivesoftware/multiplexer/net/http/HttpBindTimeoutException.java index 5e2aa1b..e7e8324 100644 --- a/src/java/org/jivesoftware/multiplexer/net/http/HttpBindTimeoutException.java +++ b/src/java/org/jivesoftware/multiplexer/net/http/HttpBindTimeoutException.java @@ -1,10 +1,12 @@ /** - * $RCSfile: $ - * $Revision: $ - * $Date: $ + * $RCSfile$ + * $Revision: $ + * $Date: $ * * Copyright (C) 2006 Jive Software. All rights reserved. - * This software is the proprietary information of Jive Software. Use is subject to license terms. + * + * 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.multiplexer.net.http; diff --git a/src/java/org/jivesoftware/multiplexer/net/http/HttpConnection.java b/src/java/org/jivesoftware/multiplexer/net/http/HttpConnection.java index d9d45fb..08f12c2 100644 --- a/src/java/org/jivesoftware/multiplexer/net/http/HttpConnection.java +++ b/src/java/org/jivesoftware/multiplexer/net/http/HttpConnection.java @@ -13,7 +13,10 @@ /** + * A connection to a client. The client will wait on getDeliverable() until the server forwards a + * message to it or the wait time on the session timesout. * + * @author Alexander Wenckus */ public class HttpConnection { private Connection.CompressionPolicy compressionPolicy; @@ -35,7 +38,7 @@ * The connection should be closed without delivering a stanza to the requestor. */ public void close() { - if(isClosed) { + if (isClosed) { return; } @@ -55,9 +58,19 @@ return false; } + /** + * Delivers content to the client. The content should be valid XMPP wrapped inside of a body. + * A null value for body indicates that the connection should be closed and the client + * sent an empty body. + * + * @param body the XMPP content to be forwarded to the client inside of a body tag. + * + * @throws HttpConnectionClosedException when this connection to the client has already recieved + * a deliverable to forward to the client + */ public void deliverBody(String body) throws HttpConnectionClosedException { // We only want to use this function once so we will close it when the body is delivered. - if(isClosed) { + if (isClosed) { throw new HttpConnectionClosedException("The http connection is no longer " + "available to deliver content"); } @@ -75,13 +88,13 @@ } /** - * A call that will cause a wait, or in the case of Jetty the thread to be freed, if there - * is no deliverable currently available. Once the deliverable becomes available it is returned. + * A call that will cause a wait, or in the case of Jetty the thread to be freed, if there is no + * deliverable currently available. Once the deliverable becomes available it is returned. * * @return the deliverable to send to the client + * * @throws HttpBindTimeoutException to indicate that the maximum wait time requested by the - * client - * has been surpassed and an empty response should be returned. + * client has been surpassed and an empty response should be returned. */ public String getDeliverable() throws HttpBindTimeoutException { if (body == null && continuation != null) { @@ -94,10 +107,10 @@ } private String waitForDeliverable() throws HttpBindTimeoutException { - if(continuation.suspend(session.getWait() * 1000)) { + if (continuation.suspend(session.getWait() * 1000)) { String deliverable = (String) continuation.getObject(); // This will occur when the hold attribute of a session has been exceded. - if(deliverable == null) { + if (deliverable == null) { throw new HttpBindTimeoutException(); } return deliverable; diff --git a/src/java/org/jivesoftware/multiplexer/net/http/HttpConnectionClosedException.java b/src/java/org/jivesoftware/multiplexer/net/http/HttpConnectionClosedException.java index 275da31..d490f89 100644 --- a/src/java/org/jivesoftware/multiplexer/net/http/HttpConnectionClosedException.java +++ b/src/java/org/jivesoftware/multiplexer/net/http/HttpConnectionClosedException.java @@ -1,15 +1,20 @@ /** - * $RCSfile: $ - * $Revision: $ - * $Date: $ + * $RCSfile$ + * $Revision: $ + * $Date: $ * * Copyright (C) 2006 Jive Software. All rights reserved. - * This software is the proprietary information of Jive Software. Use is subject to license terms. + * + * 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.multiplexer.net.http; /** + * This exception is thrown when an action attempted on the connection to the client but the + * connection has been closed. * + * @author Alexander Wenckus */ public class HttpConnectionClosedException extends Exception { public HttpConnectionClosedException(String message) { diff --git a/src/java/org/jivesoftware/multiplexer/net/http/HttpSession.java b/src/java/org/jivesoftware/multiplexer/net/http/HttpSession.java index 1759e4a..8222cb7 100644 --- a/src/java/org/jivesoftware/multiplexer/net/http/HttpSession.java +++ b/src/java/org/jivesoftware/multiplexer/net/http/HttpSession.java @@ -1,10 +1,12 @@ /** - * $RCSfile: $ - * $Revision: $ - * $Date: $ + * $RCSfile$ + * $Revision: $ + * $Date: $ * * Copyright (C) 2006 Jive Software. All rights reserved. - * This software is the proprietary information of Jive Software. Use is subject to license terms. + * + * 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.multiplexer.net.http; @@ -15,7 +17,13 @@ import java.util.*; /** + * A session represents a serious of interactions with an XMPP client sending packets using the HTTP + * Binding protocol specified in + * XEP-0124. A session can have several + * client connections open simultaneously while awaiting packets bound for the client from the + * server. * + * @author Alexander Wenckus */ public class HttpSession extends Session { private int wait; @@ -25,7 +33,7 @@ private final List pendingElements = new ArrayList(); - public HttpSession(String serverName, String streamID) { + protected HttpSession(String serverName, String streamID) { super(serverName, null, streamID); } @@ -148,7 +156,10 @@ /** * Sets the max interval within which a client can send polling requests. If more than one - * @param pollingInterval + * request occurs in the interval the session will be terminated. + * + * @param pollingInterval time in seconds a client needs to wait before sending polls to the + * server, a negative int indicates that there is no limit. */ public void setMaxPollingInterval(int pollingInterval) { } diff --git a/src/java/org/jivesoftware/multiplexer/net/http/HttpSessionManager.java b/src/java/org/jivesoftware/multiplexer/net/http/HttpSessionManager.java index b31c155..b1b6807 100644 --- a/src/java/org/jivesoftware/multiplexer/net/http/HttpSessionManager.java +++ b/src/java/org/jivesoftware/multiplexer/net/http/HttpSessionManager.java @@ -1,10 +1,12 @@ /** - * $RCSfile: $ - * $Revision: $ - * $Date: $ + * $RCSfile$ + * $Revision: $ + * $Date: $ * * Copyright (C) 2006 Jive Software. All rights reserved. - * This software is the proprietary information of Jive Software. Use is subject to license terms. + * + * 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.multiplexer.net.http;