Author: ngn
Date: Thu Jul 15 13:47:29 2010
New Revision: 964428

URL: http://svn.apache.org/viewvc?rev=964428&view=rev
Log:
Improved Javadoc and naming (VYSPER-217, by Bogdan Pistol)

Modified:
    
mina/vysper/trunk/server/extensions/xep0124-xep0206-bosh/src/main/java/org/apache/vysper/xmpp/extension/xep0124/BoshBackedSessionContext.java
    
mina/vysper/trunk/server/extensions/xep0124-xep0206-bosh/src/main/java/org/apache/vysper/xmpp/extension/xep0124/BoshDecoder.java
    
mina/vysper/trunk/server/extensions/xep0124-xep0206-bosh/src/main/java/org/apache/vysper/xmpp/extension/xep0124/BoshHandler.java
    
mina/vysper/trunk/server/extensions/xep0124-xep0206-bosh/src/main/java/org/apache/vysper/xmpp/extension/xep0124/BoshResponse.java
    
mina/vysper/trunk/server/extensions/xep0124-xep0206-bosh/src/main/java/org/apache/vysper/xmpp/extension/xep0124/BoshSaxContentHandler.java
    
mina/vysper/trunk/server/extensions/xep0124-xep0206-bosh/src/main/java/org/apache/vysper/xmpp/extension/xep0124/BoshServlet.java
    
mina/vysper/trunk/server/extensions/xep0124-xep0206-bosh/src/test/java/org/apache/vysper/xmpp/extension/xep0124/BoshBackedSessionContextTest.java
    
mina/vysper/trunk/server/extensions/xep0124-xep0206-bosh/src/test/java/org/apache/vysper/xmpp/extension/xep0124/BoshDecoderTest.java

Modified: 
mina/vysper/trunk/server/extensions/xep0124-xep0206-bosh/src/main/java/org/apache/vysper/xmpp/extension/xep0124/BoshBackedSessionContext.java
URL: 
http://svn.apache.org/viewvc/mina/vysper/trunk/server/extensions/xep0124-xep0206-bosh/src/main/java/org/apache/vysper/xmpp/extension/xep0124/BoshBackedSessionContext.java?rev=964428&r1=964427&r2=964428&view=diff
==============================================================================
--- 
mina/vysper/trunk/server/extensions/xep0124-xep0206-bosh/src/main/java/org/apache/vysper/xmpp/extension/xep0124/BoshBackedSessionContext.java
 (original)
+++ 
mina/vysper/trunk/server/extensions/xep0124-xep0206-bosh/src/main/java/org/apache/vysper/xmpp/extension/xep0124/BoshBackedSessionContext.java
 Thu Jul 15 13:47:29 2010
@@ -38,7 +38,7 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 /**
- * Keeps the session state
+ * Keeps the session state of a BOSH client
  *
  * @author The Apache MINA Project ([email protected])
  */
@@ -62,18 +62,29 @@ public class BoshBackedSessionContext ex
 
     private int hold = 1;
 
+    /*
+     * Keeps the suspended HTTP requests (does not respond to them) until the 
server has an asynchronous message
+     * to send to the client. (Comet HTTP Long Polling technique - described 
in XEP-0124)
+     */
     private Queue<HttpServletRequest> requestQueue;
 
+    /*
+     * Keeps the asynchronous messages sent from server that cannot be 
delivered to the client because there are
+     * no available HTTP requests to respond to (requestQueue is empty).
+     */
     private Queue<Stanza> delayedResponseQueue;
 
     /**
      * Creates a new context for a session
-     * @param serverRuntimeContext
      * @param boshHandler
+     * @param serverRuntimeContext
      */
     public BoshBackedSessionContext(BoshHandler boshHandler, 
ServerRuntimeContext serverRuntimeContext) {
         super(serverRuntimeContext, new SessionStateHolder());
+
+        // in BOSH we jump directly to the encrypted state
         sessionStateHolder.setState(SessionState.ENCRYPTED);
+
         this.boshHandler = boshHandler;
         requestQueue = new LinkedList<HttpServletRequest>();
         delayedResponseQueue = new LinkedList<Stanza>();
@@ -88,24 +99,34 @@ public class BoshBackedSessionContext ex
     }
 
     public void setIsReopeningXMLStream() {
+        // BOSH does not use XML streams, the BOSH equivalent for reopening an 
XML stream is to restart the BOSH connection,
+        // and this is done in BoshHandler when the client requests it
     }
 
+    /*
+     * This method is synchronized on the session object to prevent concurrent 
writes to the same BOSH client
+     */
     synchronized public void write(Stanza stanza) {
         write0(boshHandler.wrapStanza(stanza));
     }
 
-    /*
-     *  package access
+    /**
+     * Writes a BOSH response (that is wrapped in a &lt;body/&gt; element) if 
there are available HTTP requests
+     * to respond to, otherwise the response is queued to be sent later (when 
a HTTP request will be available).
+     * <p>
+     * (package access)
+     * 
+     * @param response The BOSH response to write
      */
-    void write0(Stanza boshStanza) {
+    void write0(Stanza response) {
         HttpServletRequest req = requestQueue.poll();
         if (req == null) {
-            delayedResponseQueue.offer(boshStanza);
+            delayedResponseQueue.offer(response);
             return;
         }
-        BoshResponse boshResponse = getBoshResponse(boshStanza);
+        BoshResponse boshResponse = getBoshResponse(response);
         if (LOGGER.isDebugEnabled()) {
-            LOGGER.debug("BOSH writing stanza: {}", new 
String(boshResponse.getContent()));
+            LOGGER.debug("BOSH writing response: {}", new 
String(boshResponse.getContent()));
         }
         Continuation continuation = ContinuationSupport.getContinuation(req);
         continuation.setAttribute("response", boshResponse);
@@ -117,26 +138,50 @@ public class BoshBackedSessionContext ex
     }
 
     public void switchToTLS() {
-        // BOSH cannot switch dynamically,
+        // BOSH cannot switch dynamically (because STARTTLS cannot be used 
with HTTP),
         // SSL can be enabled/disabled in BoshEndpoint#setSSLEnabled()
     }
 
+    /**
+     * Setter for the Content-Type header of the HTTP responses sent to the 
BOSH client associated with this session
+     * @param contentType
+     */
     public void setContentType(String contentType) {
         this.contentType = contentType;
     }
 
+    /**
+     * Getter for the Content-Type header
+     * @return the configured Content-Type
+     */
     public String getContentType() {
         return contentType;
     }
 
+    /**
+     * Setter for the BOSH 'wait' parameter, the longest time (in seconds) 
that the connection manager is allowed to
+     * wait before responding to any request during the session. The BOSH 
client can only configure this parameter to
+     * a lower value than the default value from this session context.
+     * @param wait the BOSH 'wait' parameter
+     */
     public void setWait(int wait) {
         this.wait = Math.min(wait, this.wait);
     }
 
+    /**
+     * Getter for the BOSH 'wait' parameter
+     * @return The BOSH 'wait' parameter
+     */
     public int getWait() {
         return wait;
     }
 
+    /**
+     * Setter for the BOSH 'hold' parameter, the maximum number of HTTP 
requests the connection manager is allowed to
+     * keep waiting at any one time during the session. The value of this 
parameter can trigger the modification of
+     * the BOSH 'requests' parameter.
+     * @param hold
+     */
     public void setHold(int hold) {
         this.hold = hold;
         if (hold >= 2) {
@@ -144,10 +189,19 @@ public class BoshBackedSessionContext ex
         }
     }
 
+    /**
+     * Getter for the BOSH 'hold' parameter
+     * @return the BOSH 'hold' parameter
+     */
     public int getHold() {
         return hold;
     }
 
+    /**
+     * Setter for the highest version of the BOSH protocol that the connection 
manager supports, or the version
+     * specified by the client in its request, whichever is lower.
+     * @param version the BOSH version
+     */
     public void setBoshVersion(String version) {
         String[] v = boshVersion.split("\\.");
         int major = Integer.parseInt(v[0]);
@@ -164,41 +218,68 @@ public class BoshBackedSessionContext ex
         }
     }
 
+    /**
+     * Getter for the BOSH protocol version
+     * @return the BOSH version
+     */
     public String getBoshVersion() {
         return boshVersion;
     }
 
+    /**
+     * Getter for the BOSH 'inactivity' parameter, the longest allowable 
inactivity period (in seconds).
+     * @return the BOSH 'inactivity' parameter
+     */
     public int getInactivity() {
         return inactivity;
     }
 
+    /**
+     * Getter for the BOSH 'polling' parameter, the shortest allowable polling 
interval (in seconds).
+     * @return the BOSH 'polling' parameter
+     */
     public int getPolling() {
         return polling;
     }
 
+    /**
+     * Getter for the BOSH 'requests' parameter, the limit number of 
simultaneous requests the client makes.
+     * @return the BOSH 'requests' parameter
+     */
     public int getRequests() {
         return requests;
     }
 
+    /*
+     * A request expires when it stays enqueued in the requestQueue longer 
than the allowed 'wait' time.
+     * The synchronization on the session object ensures that there will be no 
concurrent writes or other concurrent
+     * expirations for the BOSH client while the current request expires.
+     */
     synchronized private void requestExpired(Continuation continuation) {
         HttpServletRequest req = (HttpServletRequest) 
continuation.getAttribute("request");
         if (req == null) {
             LOGGER.warn("Continuation expired without having an associated 
request!");
             return;
         }
-        continuation.setAttribute("response", 
getBoshResponse(boshHandler.getEmptyStanza()));
+        continuation.setAttribute("response", 
getBoshResponse(boshHandler.getEmptyResponse()));
         for (;;) {
             HttpServletRequest r = requestQueue.peek();
             if (r == null) {
                 break;
             }
-            write0(boshHandler.getEmptyStanza());
+            write0(boshHandler.getEmptyResponse());
             if (r == req) {
                 break;
             }
         }
     }
 
+    /**
+     * Suspends and enqueues an HTTP request to be used later when an 
asynchronous message needs to be sent from
+     * the connection manager to the BOSH client.
+     * 
+     * @param req the HTTP request
+     */
     public void addRequest(HttpServletRequest req) {
         Continuation continuation = ContinuationSupport.getContinuation(req);
         continuation.setTimeout(wait * 1000);
@@ -206,6 +287,7 @@ public class BoshBackedSessionContext ex
         continuation.setAttribute("request", req);
         requestQueue.offer(req);
 
+        // listen the continuation to be notified when the request expires
         continuation.addContinuationListener(new ContinuationListener() {
 
             public void onTimeout(Continuation continuation) {
@@ -218,21 +300,25 @@ public class BoshBackedSessionContext ex
 
         });
 
-        Stanza delayedStanza;
-        Stanza mergedStanza = null;
-        while ((delayedStanza = delayedResponseQueue.poll()) != null) {
-            mergedStanza = boshHandler.mergeStanzas(mergedStanza, 
delayedStanza);
+        // If there are delayed responses waiting to be sent to the BOSH 
client, then we wrap them all in
+        // a <body/> element and send them as a HTTP response to the current 
HTTP request.
+        Stanza delayedResponse;
+        Stanza mergedResponse = null;
+        while ((delayedResponse = delayedResponseQueue.poll()) != null) {
+            mergedResponse = boshHandler.mergeResponses(mergedResponse, 
delayedResponse);
         }
-        if (mergedStanza != null) {
-            write0(mergedStanza);
+        if (mergedResponse != null) {
+            write0(mergedResponse);
             return;
         }
 
+        // If there are more suspended enqueued requests than it is allowed by 
the BOSH 'hold' parameter,
+        // than we release the oldest one by sending an empty response.
         if (requestQueue.size() > hold) {
-            write0(boshHandler.getEmptyStanza());
+            write0(boshHandler.getEmptyResponse());
         }
     }
-    
+
     private BoshResponse getBoshResponse(Stanza stanza) {
         byte[] content = new Renderer(stanza).getComplete().getBytes();
         return new BoshResponse(contentType, content);

Modified: 
mina/vysper/trunk/server/extensions/xep0124-xep0206-bosh/src/main/java/org/apache/vysper/xmpp/extension/xep0124/BoshDecoder.java
URL: 
http://svn.apache.org/viewvc/mina/vysper/trunk/server/extensions/xep0124-xep0206-bosh/src/main/java/org/apache/vysper/xmpp/extension/xep0124/BoshDecoder.java?rev=964428&r1=964427&r2=964428&view=diff
==============================================================================
--- 
mina/vysper/trunk/server/extensions/xep0124-xep0206-bosh/src/main/java/org/apache/vysper/xmpp/extension/xep0124/BoshDecoder.java
 (original)
+++ 
mina/vysper/trunk/server/extensions/xep0124-xep0206-bosh/src/main/java/org/apache/vysper/xmpp/extension/xep0124/BoshDecoder.java
 Thu Jul 15 13:47:29 2010
@@ -32,7 +32,7 @@ import org.xml.sax.ContentHandler;
 import org.xml.sax.SAXException;
 
 /**
- * Decodes bytes into BOSH stanzas
+ * Decodes bytes into BOSH requests
  * <p>
  * Uses nbxml for XML processing.
  * For every HTTP request there is a BoshDecoder instance
@@ -46,6 +46,11 @@ public class BoshDecoder {
 
     private final HttpServletRequest request;
 
+    /**
+     * Creates a new decoder to parse an HTTP request
+     * @param boshHandler
+     * @param req
+     */
     public BoshDecoder(BoshHandler boshHandler, HttpServletRequest req) {
         request = req;
         reader = new DefaultNonBlockingXMLReader();
@@ -55,7 +60,7 @@ public class BoshDecoder {
 
     /**
      * Decodes the bytes from the {...@link InputStream} provided by the 
current {...@link HttpServletRequest} of
-     * the request context into a BOSH stanza.
+     * the request context into a BOSH requests.
      * @throws IOException
      * @throws SAXException
      */

Modified: 
mina/vysper/trunk/server/extensions/xep0124-xep0206-bosh/src/main/java/org/apache/vysper/xmpp/extension/xep0124/BoshHandler.java
URL: 
http://svn.apache.org/viewvc/mina/vysper/trunk/server/extensions/xep0124-xep0206-bosh/src/main/java/org/apache/vysper/xmpp/extension/xep0124/BoshHandler.java?rev=964428&r1=964427&r2=964428&view=diff
==============================================================================
--- 
mina/vysper/trunk/server/extensions/xep0124-xep0206-bosh/src/main/java/org/apache/vysper/xmpp/extension/xep0124/BoshHandler.java
 (original)
+++ 
mina/vysper/trunk/server/extensions/xep0124-xep0206-bosh/src/main/java/org/apache/vysper/xmpp/extension/xep0124/BoshHandler.java
 Thu Jul 15 13:47:29 2010
@@ -38,8 +38,7 @@ import org.slf4j.LoggerFactory;
 /**
  * Processes the BOSH requests from the clients
  * <p>
- * This class is thread safe.
- * Concurrent BOSH clients can be handled simultaneously by this class safely. 
+ * This class is thread safe, it handles concurrent BOSH requests safely.
  * 
  * @author The Apache MINA Project ([email protected])
  */
@@ -52,72 +51,79 @@ public class BoshHandler {
     private Map<String, BoshBackedSessionContext> sessions;
 
     public BoshHandler() {
+        // The sessions are stored in a ConcurrentHashMap to maintain the 
"happens before relationship" memory consistency.
+        // Although the operations on specific sessions are synchronized, the 
session creation and retrieval need the memory
+        // consistency guarantee too.
         sessions = new ConcurrentHashMap<String, BoshBackedSessionContext>();
     }
 
+    /**
+     * Setter for the {...@link ServerRuntimeContext}
+     * @param serverRuntimeContext
+     */
     public void setServerRuntimeContext(ServerRuntimeContext 
serverRuntimeContext) {
         this.serverRuntimeContext = serverRuntimeContext;
     }
 
     /**
-     * Processes BOSH stanzas concurrently
-     * @param httpContext
-     * @param stanza
+     * Processes BOSH requests
+     * @param httpRequest the HTTP request
+     * @param boshRequest the decoded BOSH request
      */
-    public void process(HttpServletRequest req, Stanza stanza) {
-        if 
(!stanza.getNamespaceURI().equalsIgnoreCase(NamespaceURIs.XEP0124_BOSH)) {
-            LOGGER.error("Invalid namespace for body wrapper '{}', must be 
'{}'!", stanza.getNamespaceURI(),
+    public void process(HttpServletRequest httpRequest, Stanza boshRequest) {
+        if 
(!boshRequest.getNamespaceURI().equalsIgnoreCase(NamespaceURIs.XEP0124_BOSH)) {
+            LOGGER.error("Invalid namespace for body wrapper '{}', must be 
'{}'!", boshRequest.getNamespaceURI(),
                     NamespaceURIs.XEP0124_BOSH);
             return;
         }
-        if (!stanza.getName().equalsIgnoreCase("body")) {
-            LOGGER.error("Invalid body wrapper '{}'!", stanza.getName());
+        if (!boshRequest.getName().equalsIgnoreCase("body")) {
+            LOGGER.error("Invalid body wrapper '{}'!", boshRequest.getName());
             return;
         }
-        if (stanza.getAttribute("rid") == null) {
+        if (boshRequest.getAttribute("rid") == null) {
             LOGGER.error("Invalid request that does not have a request 
identifier (rid) attribute!");
             return;
         }
 
-        if (stanza.getAttribute("sid") == null) {
+        if (boshRequest.getAttribute("sid") == null) {
             // the session creation request (first request) does not have a 
"sid" attribute
             try {
-                createSession(req, stanza);
+                createSession(httpRequest, boshRequest);
             } catch (IOException e) {
                 LOGGER.error("Exception thrown while processing the session 
creation request", e);
                 return;
             }
         } else {
-            BoshBackedSessionContext session = 
sessions.get(stanza.getAttributeValue("sid"));
+            BoshBackedSessionContext session = 
sessions.get(boshRequest.getAttributeValue("sid"));
             if (session == null) {
                 LOGGER.warn("Received an invalid 'sid'!");
                 return;
             }
             synchronized (session) {
-                session.addRequest(req);
-                processSession(session, stanza);
+                session.addRequest(httpRequest);
+                processSession(session, boshRequest);
             }
         }
     }
     
-    private void processSession(BoshBackedSessionContext session, Stanza 
stanza) {
+    private void processSession(BoshBackedSessionContext session, Stanza 
boshRequest) {
         if (session.getState() == SessionState.ENCRYPTED) {
-            if (stanza.getInnerElements().isEmpty()) {
+            if (boshRequest.getInnerElements().isEmpty()) {
                 // session needs authentication
                 return;
             }
-            for (XMLElement element : stanza.getInnerElements()) {
+            for (XMLElement element : boshRequest.getInnerElements()) {
                 if 
(element.getNamespaceURI().equals(NamespaceURIs.URN_IETF_PARAMS_XML_NS_XMPP_SASL))
 {
                     processStanza(session, element);
                 }
             }
         } else if (session.getState() == SessionState.AUTHENTICATED) {
-            if 
("true".equals(stanza.getAttributeValue(NamespaceURIs.URN_XMPP_XBOSH, 
"restart"))) {
+            if 
("true".equals(boshRequest.getAttributeValue(NamespaceURIs.URN_XMPP_XBOSH, 
"restart"))) {
                 // restart request
-                session.write0(getRestartResponseStanza());
+                session.write0(getRestartResponse());
             } else {
                 // any other request
-                for (XMLElement element : stanza.getInnerElements()) {
+                for (XMLElement element : boshRequest.getInnerElements()) {
                     processStanza(session, element);
                 }
             }
@@ -125,41 +131,41 @@ public class BoshHandler {
     }
 
     private void processStanza(BoshBackedSessionContext session, XMLElement 
element) {
-        Stanza innerStanza;
+        Stanza stanza;
         if (element instanceof Stanza) {
-            innerStanza = (Stanza) element;
+            stanza = (Stanza) element;
         } else {
-            innerStanza = new Stanza(element.getNamespaceURI(), 
element.getName(), element.getNamespacePrefix(),
+            stanza = new Stanza(element.getNamespaceURI(), element.getName(), 
element.getNamespacePrefix(),
                     element.getAttributes(), element.getInnerFragments());
         }
-        
serverRuntimeContext.getStanzaProcessor().processStanza(serverRuntimeContext, 
session, innerStanza,
+        
serverRuntimeContext.getStanzaProcessor().processStanza(serverRuntimeContext, 
session, stanza,
                 session.getStateHolder());
     }
 
-    private void createSession(HttpServletRequest req, Stanza stanza) throws 
IOException {
+    private void createSession(HttpServletRequest httpRequest, Stanza 
boshRequest) throws IOException {
         BoshBackedSessionContext session = new BoshBackedSessionContext(this, 
serverRuntimeContext);
-        if (stanza.getAttribute("content") != null) {
-            session.setContentType(stanza.getAttributeValue("content"));
+        if (boshRequest.getAttribute("content") != null) {
+            session.setContentType(boshRequest.getAttributeValue("content"));
         }
-        if (stanza.getAttribute("wait") != null) {
-            int wait = Integer.parseInt(stanza.getAttributeValue("wait"));
+        if (boshRequest.getAttribute("wait") != null) {
+            int wait = Integer.parseInt(boshRequest.getAttributeValue("wait"));
             session.setWait(wait);
         }
-        if (stanza.getAttribute("hold") != null) {
-            int hold = Integer.parseInt(stanza.getAttributeValue("hold"));
+        if (boshRequest.getAttribute("hold") != null) {
+            int hold = Integer.parseInt(boshRequest.getAttributeValue("hold"));
             session.setHold(hold);
         }
-        if (stanza.getAttribute("ver") != null) {
-            String ver = stanza.getAttributeValue("ver");
+        if (boshRequest.getAttribute("ver") != null) {
+            String ver = boshRequest.getAttributeValue("ver");
             session.setBoshVersion(ver);
         }
-        session.addRequest(req);
+        session.addRequest(httpRequest);
         sessions.put(session.getSessionId(), session);
 
-        session.write0(getSessionCreationStanza(session));
+        session.write0(getSessionCreationResponse(session));
     }
 
-    public Stanza getSessionCreationStanza(BoshBackedSessionContext session) {
+    private Stanza getSessionCreationResponse(BoshBackedSessionContext 
session) {
         StanzaBuilder body = new StanzaBuilder("body", 
NamespaceURIs.XEP0124_BOSH);
         body.addAttribute("wait", Integer.toString(session.getWait()));
         body.addAttribute("inactivity", 
Integer.toString(session.getInactivity()));
@@ -176,38 +182,56 @@ public class BoshHandler {
         return body.build();
     }
 
-    public Stanza getEmptyStanza() {
+    /**
+     * Creates an empty BOSH response.
+     * <p>
+     * The empty BOSH response looks like <code>&lt;body 
xmlns='http://jabber.org/protocol/httpbind'/&gt;</code>
+     * @return the empty BOSH response
+     */
+    public Stanza getEmptyResponse() {
         StanzaBuilder stanzaBuilder = new StanzaBuilder("body", 
NamespaceURIs.XEP0124_BOSH);
         return stanzaBuilder.build();
     }
 
+    /**
+     * Creates a BOSH response by wrapping a stanza in a &lt;body/&gt; element
+     * @param stanza the XMPP stanza to wrap
+     * @return the BOSH response
+     */
     public Stanza wrapStanza(Stanza stanza) {
         StanzaBuilder body = new StanzaBuilder("body", 
NamespaceURIs.XEP0124_BOSH);
         body.addPreparedElement(stanza);
         return body.build();
     }
     
-    public Stanza mergeStanzas(Stanza stanza1, Stanza stanza2) {
-        if (stanza1 == null && stanza2 == null) {
+    /**
+     * Creates a BOSH response by merging 2 other BOSH responses, this is 
useful when sending more than one message as
+     * a response to a HTTP request.
+     * @param response1 the first BOSH response to merge
+     * @param response2 the second BOSH response to merge
+     * @return the merged BOSH response
+     */
+    public Stanza mergeResponses(Stanza response1, Stanza response2) {
+        if (response1 == null && response2 == null) {
             return null;
         }
-        if (stanza1 == null) {
-            return stanza2;
+        if (response1 == null) {
+            return response2;
         }
-        if (stanza2 == null) {
-            return stanza1;
+        if (response2 == null) {
+            return response1;
         }
         StanzaBuilder body = new StanzaBuilder("body", 
NamespaceURIs.XEP0124_BOSH);
-        for (XMLElement element : stanza1.getInnerElements()) {
+        for (XMLElement element : response1.getInnerElements()) {
             body.addPreparedElement(element);
         }
-        for (XMLElement element : stanza2.getInnerElements()) {
+        for (XMLElement element : response2.getInnerElements()) {
             body.addPreparedElement(element);
         }
         return body.build();
     }
     
-    private Stanza getRestartResponseStanza() {
+    private Stanza getRestartResponse() {
         Stanza features = new ServerResponses().getFeaturesForSession();
         return wrapStanza(features);
     }

Modified: 
mina/vysper/trunk/server/extensions/xep0124-xep0206-bosh/src/main/java/org/apache/vysper/xmpp/extension/xep0124/BoshResponse.java
URL: 
http://svn.apache.org/viewvc/mina/vysper/trunk/server/extensions/xep0124-xep0206-bosh/src/main/java/org/apache/vysper/xmpp/extension/xep0124/BoshResponse.java?rev=964428&r1=964427&r2=964428&view=diff
==============================================================================
--- 
mina/vysper/trunk/server/extensions/xep0124-xep0206-bosh/src/main/java/org/apache/vysper/xmpp/extension/xep0124/BoshResponse.java
 (original)
+++ 
mina/vysper/trunk/server/extensions/xep0124-xep0206-bosh/src/main/java/org/apache/vysper/xmpp/extension/xep0124/BoshResponse.java
 Thu Jul 15 13:47:29 2010
@@ -20,7 +20,7 @@
 package org.apache.vysper.xmpp.extension.xep0124;
 
 /**
- * The response sent to BOSH clients
+ * An encapsulation of an HTTP response that will be sent to BOSH clients
  * 
  * @author The Apache MINA Project ([email protected])
  */

Modified: 
mina/vysper/trunk/server/extensions/xep0124-xep0206-bosh/src/main/java/org/apache/vysper/xmpp/extension/xep0124/BoshSaxContentHandler.java
URL: 
http://svn.apache.org/viewvc/mina/vysper/trunk/server/extensions/xep0124-xep0206-bosh/src/main/java/org/apache/vysper/xmpp/extension/xep0124/BoshSaxContentHandler.java?rev=964428&r1=964427&r2=964428&view=diff
==============================================================================
--- 
mina/vysper/trunk/server/extensions/xep0124-xep0206-bosh/src/main/java/org/apache/vysper/xmpp/extension/xep0124/BoshSaxContentHandler.java
 (original)
+++ 
mina/vysper/trunk/server/extensions/xep0124-xep0206-bosh/src/main/java/org/apache/vysper/xmpp/extension/xep0124/BoshSaxContentHandler.java
 Thu Jul 15 13:47:29 2010
@@ -36,7 +36,7 @@ import org.xml.sax.Locator;
 import org.xml.sax.SAXException;
 
 /**
- * SAX handler that constructs stanzas by parsing XML from BOSH clients.
+ * SAX handler that constructs BOSH requests by parsing the XML from BOSH 
clients.
  * <p>
  * This class is similar to {...@link XMPPContentHandler}
  *
@@ -86,7 +86,7 @@ public class BoshSaxContentHandler imple
         isBodyPayloadDecoded = true;
         XMLElement element = builder.build();
         if (LOGGER.isDebugEnabled()) {
-            LOGGER.debug("BOSH decoding stanza: {}", new 
Renderer(element).getComplete());
+            LOGGER.debug("BOSH decoding request: {}", new 
Renderer(element).getComplete());
         }
         boshHandler.process(request, (Stanza) element);
         builder = null;

Modified: 
mina/vysper/trunk/server/extensions/xep0124-xep0206-bosh/src/main/java/org/apache/vysper/xmpp/extension/xep0124/BoshServlet.java
URL: 
http://svn.apache.org/viewvc/mina/vysper/trunk/server/extensions/xep0124-xep0206-bosh/src/main/java/org/apache/vysper/xmpp/extension/xep0124/BoshServlet.java?rev=964428&r1=964427&r2=964428&view=diff
==============================================================================
--- 
mina/vysper/trunk/server/extensions/xep0124-xep0206-bosh/src/main/java/org/apache/vysper/xmpp/extension/xep0124/BoshServlet.java
 (original)
+++ 
mina/vysper/trunk/server/extensions/xep0124-xep0206-bosh/src/main/java/org/apache/vysper/xmpp/extension/xep0124/BoshServlet.java
 Thu Jul 15 13:47:29 2010
@@ -128,7 +128,7 @@ public class BoshServlet extends HttpSer
     protected void doPost(HttpServletRequest req, HttpServletResponse resp) 
throws ServletException, IOException {
         BoshResponse boshResponse = (BoshResponse) 
req.getAttribute("response");
         if (boshResponse != null) {
-            // if continuation is resumed or expired
+            // if the continuation is resumed or expired
             writeResponse(resp, boshResponse);
             return;
         }
@@ -146,7 +146,7 @@ public class BoshServlet extends HttpSer
         resp.addHeader("Server", SERVER_IDENTIFICATION);
         resp.setContentType(respData.getContentType());
         resp.setContentLength(respData.getContent().length);
-        resp.addHeader("Access-control-allow-origin", 
accessControlAllowOrigin);
+        resp.addHeader("Access-Control-Allow-Origin", 
accessControlAllowOrigin);
         resp.getOutputStream().write(respData.getContent());
         resp.flushBuffer();
     }

Modified: 
mina/vysper/trunk/server/extensions/xep0124-xep0206-bosh/src/test/java/org/apache/vysper/xmpp/extension/xep0124/BoshBackedSessionContextTest.java
URL: 
http://svn.apache.org/viewvc/mina/vysper/trunk/server/extensions/xep0124-xep0206-bosh/src/test/java/org/apache/vysper/xmpp/extension/xep0124/BoshBackedSessionContextTest.java?rev=964428&r1=964427&r2=964428&view=diff
==============================================================================
--- 
mina/vysper/trunk/server/extensions/xep0124-xep0206-bosh/src/test/java/org/apache/vysper/xmpp/extension/xep0124/BoshBackedSessionContextTest.java
 (original)
+++ 
mina/vysper/trunk/server/extensions/xep0124-xep0206-bosh/src/test/java/org/apache/vysper/xmpp/extension/xep0124/BoshBackedSessionContextTest.java
 Thu Jul 15 13:47:29 2010
@@ -19,8 +19,12 @@
  */
 package org.apache.vysper.xmpp.extension.xep0124;
 
-import static org.easymock.EasyMock.*;
-import static org.junit.Assert.*;
+import static org.easymock.EasyMock.anyLong;
+import static org.easymock.EasyMock.createControl;
+import static org.easymock.EasyMock.eq;
+import static org.easymock.EasyMock.expect;
+import static org.easymock.EasyMock.expectLastCall;
+import static org.junit.Assert.assertEquals;
 
 import javax.servlet.http.HttpServletRequest;
 
@@ -80,13 +84,13 @@ public class BoshBackedSessionContextTes
 
         boshBackedSessionContext = new BoshBackedSessionContext(boshHandler, 
serverRuntimeContext);
         boshBackedSessionContext.addRequest(httpServletRequest);
-        Stanza stanza = new StanzaBuilder("body", 
NamespaceURIs.XEP0124_BOSH).build();
-        boshBackedSessionContext.write0(stanza);
+        Stanza body = new StanzaBuilder("body", 
NamespaceURIs.XEP0124_BOSH).build();
+        boshBackedSessionContext.write0(body);
         mocksControl.verify();
 
         BoshResponse boshResponse = captured.getValue();
         assertEquals(BoshServlet.XML_CONTENT_TYPE, 
boshResponse.getContentType());
-        assertEquals(new Renderer(stanza).getComplete(), new 
String(boshResponse.getContent()));
+        assertEquals(new Renderer(body).getComplete(), new 
String(boshResponse.getContent()));
     }
 
     @Test
@@ -107,7 +111,7 @@ public class BoshBackedSessionContextTes
 
     @Test
     public void testRequestExpired() {
-        Stanza stanza = new StanzaBuilder("body", 
NamespaceURIs.XEP0124_BOSH).build();
+        Stanza body = new StanzaBuilder("body", 
NamespaceURIs.XEP0124_BOSH).build();
 
         // addRequest
         HttpServletRequest httpServletRequest = 
mocksControl.createMock(HttpServletRequest.class);
@@ -126,7 +130,7 @@ public class BoshBackedSessionContextTes
         Capture<BoshResponse> responseCaptured = new Capture<BoshResponse>();
         continuation.setAttribute(eq("response"), EasyMock.<BoshResponse> 
capture(responseCaptured));
 
-        expect(boshHandler.getEmptyStanza()).andReturn(stanza);
+        expect(boshHandler.getEmptyResponse()).andReturn(body);
         expectLastCall().atLeastOnce();
 
         // write0
@@ -139,7 +143,7 @@ public class BoshBackedSessionContextTes
         listenerCaptured.getValue().onTimeout(continuation);
         mocksControl.verify();
 
-        assertEquals(new Renderer(stanza).getComplete(), new 
String(responseCaptured.getValue().getContent()));
+        assertEquals(new Renderer(body).getComplete(), new 
String(responseCaptured.getValue().getContent()));
         assertEquals(BoshServlet.XML_CONTENT_TYPE, 
responseCaptured.getValue().getContentType());
     }
 
@@ -174,11 +178,11 @@ public class BoshBackedSessionContextTes
         boshBackedSessionContext.setHold(2);
         boshBackedSessionContext.addRequest(httpServletRequest1);
         boshBackedSessionContext.addRequest(httpServletRequest2);
-        Stanza stanza = new StanzaBuilder("body", 
NamespaceURIs.XEP0124_BOSH).build();
-        boshBackedSessionContext.write0(stanza);
+        Stanza body = new StanzaBuilder("body", 
NamespaceURIs.XEP0124_BOSH).build();
+        boshBackedSessionContext.write0(body);
         mocksControl.verify();
 
-        assertEquals(new Renderer(stanza).getComplete(), new 
String(captured.getValue().getContent()));
+        assertEquals(new Renderer(body).getComplete(), new 
String(captured.getValue().getContent()));
         assertEquals(BoshServlet.XML_CONTENT_TYPE, 
captured.getValue().getContentType());
     }
 
@@ -194,9 +198,9 @@ public class BoshBackedSessionContextTes
 
         continuation.addContinuationListener(EasyMock.<ContinuationListener> 
anyObject());
 
-        Stanza stanza1 = mocksControl.createMock(Stanza.class);
-        Stanza stanza2 = mocksControl.createMock(Stanza.class);
-        expect(boshHandler.mergeStanzas(EasyMock.<Stanza> anyObject(), 
EasyMock.<Stanza> anyObject())).andReturn(
+        Stanza body1 = mocksControl.createMock(Stanza.class);
+        Stanza body2 = mocksControl.createMock(Stanza.class);
+        expect(boshHandler.mergeResponses(EasyMock.<Stanza> anyObject(), 
EasyMock.<Stanza> anyObject())).andReturn(
                 new StanzaBuilder("body", NamespaceURIs.XEP0124_BOSH).build());
         expectLastCall().times(2);
 
@@ -206,8 +210,8 @@ public class BoshBackedSessionContextTes
         mocksControl.replay();
 
         boshBackedSessionContext = new BoshBackedSessionContext(boshHandler, 
serverRuntimeContext);
-        boshBackedSessionContext.write0(stanza1);
-        boshBackedSessionContext.write0(stanza2);
+        boshBackedSessionContext.write0(body1);
+        boshBackedSessionContext.write0(body2);
         boshBackedSessionContext.addRequest(httpServletRequest);
         mocksControl.verify();
     }

Modified: 
mina/vysper/trunk/server/extensions/xep0124-xep0206-bosh/src/test/java/org/apache/vysper/xmpp/extension/xep0124/BoshDecoderTest.java
URL: 
http://svn.apache.org/viewvc/mina/vysper/trunk/server/extensions/xep0124-xep0206-bosh/src/test/java/org/apache/vysper/xmpp/extension/xep0124/BoshDecoderTest.java?rev=964428&r1=964427&r2=964428&view=diff
==============================================================================
--- 
mina/vysper/trunk/server/extensions/xep0124-xep0206-bosh/src/test/java/org/apache/vysper/xmpp/extension/xep0124/BoshDecoderTest.java
 (original)
+++ 
mina/vysper/trunk/server/extensions/xep0124-xep0206-bosh/src/test/java/org/apache/vysper/xmpp/extension/xep0124/BoshDecoderTest.java
 Thu Jul 15 13:47:29 2010
@@ -67,17 +67,17 @@ public class BoshDecoderTest {
         mocksControl.replay();
         boshDecoder.decode();
         mocksControl.verify();
-        Stanza stanza = captured.getValue();
-        assertNotNull(stanza);
-        assertEquals("body", stanza.getName());
-        assertEquals("http://jabber.org/protocol/httpbind";, 
stanza.getNamespaceURI());
-        assertEquals("3549788615", stanza.getAttributeValue("rid"));
-        assertEquals("vysper.org", stanza.getAttributeValue("to"));
-        assertEquals("60", stanza.getAttributeValue("wait"));
-        assertEquals("1", stanza.getAttributeValue("hold"));
-        assertEquals("1.6", stanza.getAttributeValue("ver"));
-        assertEquals("1.0", stanza.getAttributeValue("urn:xmpp:xbosh", 
"version"));
-        assertEquals("en", 
stanza.getAttributeValue("http://www.w3.org/XML/1998/namespace";, "lang"));
+        Stanza request = captured.getValue();
+        assertNotNull(request);
+        assertEquals("body", request.getName());
+        assertEquals("http://jabber.org/protocol/httpbind";, 
request.getNamespaceURI());
+        assertEquals("3549788615", request.getAttributeValue("rid"));
+        assertEquals("vysper.org", request.getAttributeValue("to"));
+        assertEquals("60", request.getAttributeValue("wait"));
+        assertEquals("1", request.getAttributeValue("hold"));
+        assertEquals("1.6", request.getAttributeValue("ver"));
+        assertEquals("1.0", request.getAttributeValue("urn:xmpp:xbosh", 
"version"));
+        assertEquals("en", 
request.getAttributeValue("http://www.w3.org/XML/1998/namespace";, "lang"));
     }
 
 }


Reply via email to