activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gr...@apache.org
Subject svn commit: r416868 - in /incubator/activemq/branches/activemq-4.0/activemq-web/src/main: java/org/apache/activemq/web/AjaxServlet.java java/org/apache/activemq/web/MessageListenerServlet.java resources/org/apache/activemq/web/_amq.js
Date Sat, 24 Jun 2006 06:30:01 GMT
Author: gregw
Date: Fri Jun 23 23:30:01 2006
New Revision: 416868

URL: http://svn.apache.org/viewvc?rev=416868&view=rev
Log:
applied 415827 416324 416640 416641

Modified:
    incubator/activemq/branches/activemq-4.0/activemq-web/src/main/java/org/apache/activemq/web/AjaxServlet.java
    incubator/activemq/branches/activemq-4.0/activemq-web/src/main/java/org/apache/activemq/web/MessageListenerServlet.java
    incubator/activemq/branches/activemq-4.0/activemq-web/src/main/resources/org/apache/activemq/web/_amq.js

Modified: incubator/activemq/branches/activemq-4.0/activemq-web/src/main/java/org/apache/activemq/web/AjaxServlet.java
URL: http://svn.apache.org/viewvc/incubator/activemq/branches/activemq-4.0/activemq-web/src/main/java/org/apache/activemq/web/AjaxServlet.java?rev=416868&r1=416867&r2=416868&view=diff
==============================================================================
--- incubator/activemq/branches/activemq-4.0/activemq-web/src/main/java/org/apache/activemq/web/AjaxServlet.java
(original)
+++ incubator/activemq/branches/activemq-4.0/activemq-web/src/main/java/org/apache/activemq/web/AjaxServlet.java
Fri Jun 23 23:30:01 2006
@@ -17,6 +17,7 @@
 import java.io.ByteArrayOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
+import java.net.URL;
 import java.util.HashMap;
 import java.util.Map;
 
@@ -47,7 +48,18 @@
             super.doGet(request, response);
     }
     
-    protected void doJavaScript(HttpServletRequest request, HttpServletResponse response)throws
IOException {
+    protected void doJavaScript(HttpServletRequest request, HttpServletResponse response)throws
IOException, ServletException {
+        
+        // Look for a local resource first.
+        String js = request.getServletPath()+request.getPathInfo();
+        URL url = getServletContext().getResource(js);
+        if (url!=null)
+        {
+            getServletContext().getNamedDispatcher("default").forward(request,response);
+            return;
+        }
+        
+        // Serve from the classpath resources
         String resource="org/apache/activemq/web"+request.getPathInfo();
         synchronized(jsCache){
             

Modified: incubator/activemq/branches/activemq-4.0/activemq-web/src/main/java/org/apache/activemq/web/MessageListenerServlet.java
URL: http://svn.apache.org/viewvc/incubator/activemq/branches/activemq-4.0/activemq-web/src/main/java/org/apache/activemq/web/MessageListenerServlet.java?rev=416868&r1=416867&r2=416868&view=diff
==============================================================================
--- incubator/activemq/branches/activemq-4.0/activemq-web/src/main/java/org/apache/activemq/web/MessageListenerServlet.java
(original)
+++ incubator/activemq/branches/activemq-4.0/activemq-web/src/main/java/org/apache/activemq/web/MessageListenerServlet.java
Fri Jun 23 23:30:01 2006
@@ -90,7 +90,16 @@
     }
 
     /**
-     * Sends a message to a destination
+     * Sends a message to a destination or manage subscriptions.
+     * 
+     * If the the content type of the POST is <code>application/x-www-form-urlencoded</code>,
then the form parameters 
+     * "destination", "message" and "type" are used to pass a message or a subscription.
 If multiple messages
+     * or subscriptions are passed in a single post, then additional parameters are shortened
to "dN", "mN" and "tN"
+     * where N is an index starting from 1. The type is either "send", "listen" or "unlisten".
 For send types,
+     * the message is the text of the TextMessage, otherwise it is the ID to be used for
the subscription.
+     * 
+     * If the content type is not <code>application/x-www-form-urlencoded</code>,
then the body of the post is
+     * sent as the message to a destination that is derived from a query parameter, the URL
or the default destination.
      * 
      * @param request
      * @param response
@@ -110,30 +119,30 @@
                 log.debug("POST client="+client+" session="+request.getSession().getId()+"
info="+request.getPathInfo()+" contentType="+request.getContentType());
             // dump(request.getParameterMap());
             }
-            String[] destinations = request.getParameterValues("destination");
-            String[] messages = request.getParameterValues("message");
-            String[] types = request.getParameterValues("type");
             
-            if (destinations.length!=messages.length || messages.length!=types.length)
-            {
-                if (log.isDebugEnabled()) {
-                    log.debug("ERROR destination="+destinations.length+" message="+messages.length+"
type="+types.length);
-                }
-                response.sendError(HttpServletResponse.SC_BAD_REQUEST,"missmatched destination,
message or type");
-                return;
-            }
+            int messages=0;
             
-            for (int i=0;i<types.length;i++)
+            // loop until no more messages
+            while (true)
             {
+                // Get the message parameters.   Multiple messages are encoded with more
compact parameter names.
+                String destination_name = request.getParameter(messages==0?"destination":("d"+messages));
+                String message = request.getParameter(messages==0?"message":("m"+messages));
+                String type = request.getParameter(messages==0?"type":("t"+messages));
+                
+                if (destination_name==null || message==null || type==null)
+                    break;
+                
                 try {
-                    String type=types[i];
-                    Destination destination=getDestination(client,request,destinations[i]);
+                    Destination destination=getDestination(client,request,destination_name);
                     
                     if (log.isDebugEnabled()) {
-                        log.debug(i+" destination="+destinations[i]+" message="+messages[i]+"
type="+types[i]);
+                        log.debug(messages+" destination="+destination_name+" message="+message+"
type="+type);
                         log.debug(destination+" is a "+destination.getClass().getName());
                     }
                     
+                    messages++;
+                    
                     if ("listen".equals(type))
                     {
                         Listener listener = getListener(request);
@@ -142,9 +151,9 @@
                         MessageAvailableConsumer consumer = (MessageAvailableConsumer) client.getConsumer(destination);
                         
                         consumer.setAvailableListener(listener);
-                        consumerIdMap.put(consumer, messages[i]);
+                        consumerIdMap.put(consumer, message);
                         if (log.isDebugEnabled()) {
-                            log.debug("Subscribed: "+consumer+" to "+destination+" id="+messages[i]);
+                            log.debug("Subscribed: "+consumer+" to "+destination+" id="+message);
                         }
                     }
                     else if ("unlisten".equals(type))
@@ -161,13 +170,13 @@
                     }
                     else if ("send".equals(type))
                     {
-                        TextMessage message = client.getSession().createTextMessage(messages[i]);
-                        appendParametersToMessage(request, message);
+                        TextMessage text = client.getSession().createTextMessage(message);
+                        appendParametersToMessage(request, text);
 
-                        client.send(destination, message);
-                        message_ids+=message.getJMSMessageID()+"\n";
+                        client.send(destination, text);
+                        message_ids+=text.getJMSMessageID()+"\n";
                         if (log.isDebugEnabled()) {
-                            log.debug("Sent "+messages[i]+" to "+destination);
+                            log.debug("Sent "+message+" to "+destination);
                         }
                     }
                     else

Modified: incubator/activemq/branches/activemq-4.0/activemq-web/src/main/resources/org/apache/activemq/web/_amq.js
URL: http://svn.apache.org/viewvc/incubator/activemq/branches/activemq-4.0/activemq-web/src/main/resources/org/apache/activemq/web/_amq.js?rev=416868&r1=416867&r2=416868&view=diff
==============================================================================
--- incubator/activemq/branches/activemq-4.0/activemq-web/src/main/resources/org/apache/activemq/web/_amq.js
(original)
+++ incubator/activemq/branches/activemq-4.0/activemq-web/src/main/resources/org/apache/activemq/web/_amq.js
Fri Jun 23 23:30:01 2006
@@ -12,6 +12,10 @@
 
   // Polling. Set to true (default) if waiting poll for messages is needed
   poll: true,
+  
+  // Poll delay. if set to positive integer, this is the time to wait in ms before
+  // sending the next poll after the last completes.
+  _pollDelay: 0,
 
   _first: true,
   _pollEvent: function(first) {},
@@ -76,13 +80,14 @@
       var body = amq._messageQueue;
       amq._messageQueue='';
       amq._messages=0;
-      new Ajax.Request(amq.uri, { method: 'post', postBody: body});
+      amq._queueMessages++;
+      new Ajax.Request(amq.uri, { method: 'post', postBody: body, onSuccess: amq.endBatch});
     }
   },
 
   _pollHandler: function(request)
   {
-    amq._queueMessages++;
+    amq.startBatch();
     try
     {
       amq._messageHandler(request);
@@ -93,20 +98,17 @@
     {
         alert(e);
     }
+    amq.endBatch();
 
-    amq._queueMessages--;
-
-    if (amq._queueMessages==0 && amq._messages>0)
-    {
-      var body = amq._messageQueue+'&poll='+amq.poll;
-      amq._messageQueue='';
-      amq._messages=0;
-      new Ajax.Request(amq.uri, { method: 'post', onSuccess: amq._pollHandler, postBody:
body });
-    }
-    else if (amq.poll)
-    {
-        new Ajax.Request(amq.uri, { method: 'get', onSuccess: amq._pollHandler });
-    }
+    if (amq._pollDelay>0)
+      setTimeout('amq._sendPoll()',amq._pollDelay);
+    else
+      amq._sendPoll();
+  },
+  
+  _sendPoll: function(request)
+  {
+    new Ajax.Request(amq.uri, { method: 'get', onSuccess: amq._pollHandler });
   },
 
   // Add a function that gets called on every poll response, after all received
@@ -126,7 +128,7 @@
   // xml content.
   sendMessage : function(destination,message)
   {
-   amq._sendMessage(destination,message,'send');
+    amq._sendMessage(destination,message,'send');
   },
 
   // Listen on a channel or topic.   handler must be a function taking a message arguement
@@ -147,18 +149,26 @@
   {
     if (amq._queueMessages>0)
     {
-      amq._messageQueue+=(amq._messages==0?'destination=':'&destination=')+destination+'&message='+message+'&type='+type;
+      if (amq._messages==0)
+      {
+        amq._messageQueue='destination='+destination+'&message='+message+'&type='+type;
+      }
+      else
+      {
+        amq._messageQueue+='&d'+amq._messages+'='+destination+'&m'+amq._messages+'='+message+'&t'+amq._messages+'='+type;
+      }
       amq._messages++;
     }
     else
     {
-      new Ajax.Request(amq.uri, { method: 'post', postBody: 'destination='+destination+'&message='+message+'&type='+type});
+      amq.startBatch();
+      new Ajax.Request(amq.uri, { method: 'post', postBody: 'destination='+destination+'&message='+message+'&type='+type,
onSuccess: amq.endBatch});
     }
   },
-
+  
   _startPolling : function()
   {
-    if (amq.poll)
+   if (amq.poll)
       new Ajax.Request(amq.uri, { method: 'get', parameters: 'timeout=0', onSuccess: amq._pollHandler
});
   }
 };



Mime
View raw message