activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jstrac...@apache.org
Subject svn commit: r397149 - in /incubator/activemq/trunk/activemq-web/src/main/java/org/apache/activemq/web: MessageListenerServlet.java MessageServlet.java MessageServletSupport.java PortfolioPublishServlet.java WebClient.java
Date Wed, 26 Apr 2006 08:54:31 GMT
Author: jstrachan
Date: Wed Apr 26 01:54:07 2006
New Revision: 397149

URL: http://svn.apache.org/viewcvs?rev=397149&view=rev
Log:
minor refactor to make the WebClient easier to use as a stand alone POJO

Modified:
    incubator/activemq/trunk/activemq-web/src/main/java/org/apache/activemq/web/MessageListenerServlet.java
    incubator/activemq/trunk/activemq-web/src/main/java/org/apache/activemq/web/MessageServlet.java
    incubator/activemq/trunk/activemq-web/src/main/java/org/apache/activemq/web/MessageServletSupport.java
    incubator/activemq/trunk/activemq-web/src/main/java/org/apache/activemq/web/PortfolioPublishServlet.java
    incubator/activemq/trunk/activemq-web/src/main/java/org/apache/activemq/web/WebClient.java

Modified: incubator/activemq/trunk/activemq-web/src/main/java/org/apache/activemq/web/MessageListenerServlet.java
URL: http://svn.apache.org/viewcvs/incubator/activemq/trunk/activemq-web/src/main/java/org/apache/activemq/web/MessageListenerServlet.java?rev=397149&r1=397148&r2=397149&view=diff
==============================================================================
--- incubator/activemq/trunk/activemq-web/src/main/java/org/apache/activemq/web/MessageListenerServlet.java
(original)
+++ incubator/activemq/trunk/activemq-web/src/main/java/org/apache/activemq/web/MessageListenerServlet.java
Wed Apr 26 01:54:07 2006
@@ -101,7 +101,7 @@
         
         // lets turn the HTTP post into a JMS Message
         
-        WebClient client = getWebClient(request);
+        WebClient client = WebClient.getWebClient(request);
         String message_ids="";
         
         synchronized (client) {
@@ -227,7 +227,7 @@
      */
     protected void doGet(HttpServletRequest request, HttpServletResponse response) throws
ServletException, IOException {
         try {
-            WebClient client = getWebClient(request);
+            WebClient client = WebClient.getWebClient(request);
             if (log.isDebugEnabled()) {
                 log.debug("GET client="+client+" session="+request.getSession().getId()+"
uri="+request.getRequestURI()+" query="+request.getQueryString());
             }
@@ -371,7 +371,7 @@
         HttpSession session = request.getSession();
         Listener listener = (Listener) session.getAttribute("mls.listener");
         if (listener == null) {
-            listener = new Listener(getWebClient(request));
+            listener = new Listener(WebClient.getWebClient(request));
             session.setAttribute("mls.listener", listener);
         }
         return listener;

Modified: incubator/activemq/trunk/activemq-web/src/main/java/org/apache/activemq/web/MessageServlet.java
URL: http://svn.apache.org/viewcvs/incubator/activemq/trunk/activemq-web/src/main/java/org/apache/activemq/web/MessageServlet.java?rev=397149&r1=397148&r2=397149&view=diff
==============================================================================
--- incubator/activemq/trunk/activemq-web/src/main/java/org/apache/activemq/web/MessageServlet.java
(original)
+++ incubator/activemq/trunk/activemq-web/src/main/java/org/apache/activemq/web/MessageServlet.java
Wed Apr 26 01:54:07 2006
@@ -80,7 +80,7 @@
     protected void doPost(HttpServletRequest request, HttpServletResponse response) throws
ServletException, IOException {
         // lets turn the HTTP post into a JMS Message
         try {
-            WebClient client = getWebClient(request);
+            WebClient client = WebClient.getWebClient(request);
 
             String text = getPostedMessageBody(request);
 
@@ -137,7 +137,7 @@
 
         int messages = 0;
         try {
-            WebClient client = getWebClient(request);
+            WebClient client = WebClient.getWebClient(request);
             Destination destination = getDestination(client, request);
             if (destination==null)
                 throw new NoDestinationSuppliedException();
@@ -254,7 +254,7 @@
 
         int messages = 0;
         try {
-            WebClient client = getWebClient(request);
+            WebClient client = WebClient.getWebClient(request);
             Destination destination = getDestination(client, request);
             long timeout = getReadTimeout(request);
             boolean ajax = isRicoAjax(request);

Modified: incubator/activemq/trunk/activemq-web/src/main/java/org/apache/activemq/web/MessageServletSupport.java
URL: http://svn.apache.org/viewcvs/incubator/activemq/trunk/activemq-web/src/main/java/org/apache/activemq/web/MessageServletSupport.java?rev=397149&r1=397148&r2=397149&view=diff
==============================================================================
--- incubator/activemq/trunk/activemq-web/src/main/java/org/apache/activemq/web/MessageServletSupport.java
(original)
+++ incubator/activemq/trunk/activemq-web/src/main/java/org/apache/activemq/web/MessageServletSupport.java
Wed Apr 26 01:54:07 2006
@@ -28,7 +28,6 @@
 import javax.servlet.ServletException;
 import javax.servlet.http.HttpServlet;
 import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpSession;
 import java.io.BufferedReader;
 import java.io.IOException;
 import java.util.HashMap;
@@ -58,7 +57,6 @@
     private int defaultMessagePriority = 5;
     private long defaultMessageTimeToLive = 0;
 
-
     public void init(ServletConfig servletConfig) throws ServletException {
         super.init(servletConfig);
 
@@ -83,10 +81,6 @@
         WebClient.initContext(getServletContext());
     }
 
-    protected WebClient createWebClient(HttpServletRequest request) {
-        return new WebClient();
-    }
-
     public static boolean asBoolean(String param) {
         return asBoolean(param, false);
     }
@@ -98,22 +92,6 @@
         else {
             return param.equalsIgnoreCase("true");
         }
-    }
-
-    /**
-     * Helper method to get the client for the current session
-     *
-     * @param request is the current HTTP request
-     * @return the current client or a newly creates
-     */
-    protected WebClient getWebClient(HttpServletRequest request) {
-        HttpSession session = request.getSession(true);
-        WebClient client = WebClient.getWebClient(session);
-        if (client == null || client.isClosed()) {
-            client = createWebClient(request);
-            session.setAttribute(WebClient.webClientAttribute, client);
-        }
-        return client;
     }
 
 

Modified: incubator/activemq/trunk/activemq-web/src/main/java/org/apache/activemq/web/PortfolioPublishServlet.java
URL: http://svn.apache.org/viewcvs/incubator/activemq/trunk/activemq-web/src/main/java/org/apache/activemq/web/PortfolioPublishServlet.java?rev=397149&r1=397148&r2=397149&view=diff
==============================================================================
--- incubator/activemq/trunk/activemq-web/src/main/java/org/apache/activemq/web/PortfolioPublishServlet.java
(original)
+++ incubator/activemq/trunk/activemq-web/src/main/java/org/apache/activemq/web/PortfolioPublishServlet.java
Wed Apr 26 01:54:07 2006
@@ -63,7 +63,7 @@
             request.getSession().setAttribute("total",total);
             
             try {
-                WebClient client = getWebClient(request);
+                WebClient client = WebClient.getWebClient(request);
                 for (int i = 0; i < count; i++) {
                     sendMessage(client, stocks);
                 }

Modified: incubator/activemq/trunk/activemq-web/src/main/java/org/apache/activemq/web/WebClient.java
URL: http://svn.apache.org/viewcvs/incubator/activemq/trunk/activemq-web/src/main/java/org/apache/activemq/web/WebClient.java?rev=397149&r1=397148&r2=397149&view=diff
==============================================================================
--- incubator/activemq/trunk/activemq-web/src/main/java/org/apache/activemq/web/WebClient.java
(original)
+++ incubator/activemq/trunk/activemq-web/src/main/java/org/apache/activemq/web/WebClient.java
Wed Apr 26 01:54:07 2006
@@ -36,6 +36,7 @@
 import javax.jms.MessageProducer;
 import javax.jms.Session;
 import javax.servlet.ServletContext;
+import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpSession;
 import javax.servlet.http.HttpSessionActivationListener;
 import javax.servlet.http.HttpSessionBindingEvent;
@@ -77,6 +78,23 @@
 
     private final Semaphore semaphore = new Semaphore(1);
 
+
+    /**
+     * Helper method to get the client for the current session, lazily creating
+     * a client if there is none currently
+     *
+     * @param request is the current HTTP request
+     * @return the current client or a newly creates
+     */
+    public static WebClient getWebClient(HttpServletRequest request) {
+        HttpSession session = request.getSession(true);
+        WebClient client = getWebClient(session);
+        if (client == null || client.isClosed()) {
+            client = WebClient.createWebClient(request);
+            session.setAttribute(webClientAttribute, client);
+        }
+        return client;
+    }
     /**
      * @return the web client for the current HTTP session or null if there is
      *         not a web client created yet
@@ -89,8 +107,6 @@
         initConnectionFactory(context);
     }
 
-    /**
-     */
     public WebClient() {
         if (factory == null)
             throw new IllegalStateException("initContext(ServletContext) not called");
@@ -284,4 +300,9 @@
     public void valueUnbound(HttpSessionBindingEvent event) {
         close();
     }
+
+    protected static WebClient createWebClient(HttpServletRequest request) {
+        return new WebClient();
+    }
+
 }



Mime
View raw message