You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pivot.apache.org by gb...@apache.org on 2010/01/30 03:21:48 UTC

svn commit: r904711 - in /pivot/trunk: web-server/src/org/apache/pivot/web/server/QueryServlet.java web/src/org/apache/pivot/web/QueryDictionary.java

Author: gbrown
Date: Sat Jan 30 02:21:48 2010
New Revision: 904711

URL: http://svn.apache.org/viewvc?rev=904711&view=rev
Log:
Add prepare()/dispose() methods to QueryServlet (e.g. to allow callers to create a database connection that can be used for the life of the request); fix logic bug in QueryDictionary.

Modified:
    pivot/trunk/web-server/src/org/apache/pivot/web/server/QueryServlet.java
    pivot/trunk/web/src/org/apache/pivot/web/QueryDictionary.java

Modified: pivot/trunk/web-server/src/org/apache/pivot/web/server/QueryServlet.java
URL: http://svn.apache.org/viewvc/pivot/trunk/web-server/src/org/apache/pivot/web/server/QueryServlet.java?rev=904711&r1=904710&r2=904711&view=diff
==============================================================================
--- pivot/trunk/web-server/src/org/apache/pivot/web/server/QueryServlet.java (original)
+++ pivot/trunk/web-server/src/org/apache/pivot/web/server/QueryServlet.java Sat Jan 30 02:21:48 2010
@@ -44,7 +44,7 @@
  * Abstract base class for query servlets.
  */
 public abstract class QueryServlet extends HttpServlet {
-    private static final long serialVersionUID = 0;
+    private static final long serialVersionUID = 4881638232902478092L;
 
     private boolean determineContentLength = false;
     private HashMap<String, Class<? extends Serializer<?>>> serializerTypes
@@ -142,6 +142,28 @@
     }
 
     /**
+     * Prepares a servlet for request execution. This method is called immediately
+     * prior to the HTTP handler method.
+     * <p>
+     * The default implementation is a no-op.
+     *
+     * @throws ServletException
+     */
+    public void prepare() throws ServletException {
+    }
+
+    /**
+     * Disposes any resources allocated in {@link #prepare()}. This method is
+     * guaranteed to be called even if the HTTP handler method throws.
+     * <p>
+     * The default implementation is a no-op.
+     *
+     * @throws ServletException
+     */
+    public void dispose() throws ServletException {
+    }
+
+    /**
      * Handles an HTTP GET request. The default implementation throws an HTTP
      * 405 query exception.
      *
@@ -255,9 +277,15 @@
                 requestHeaderDictionary.add(headerName, headerValue);
             }
 
-            // Call the base method to process the request
+            // Prepare the servlet for request processing
+            prepare();
+
+            // Process the request
             super.service(request, response);
         } finally {
+            // Clean up any allocated resources
+            dispose();
+
             // Clean up thread local variables
             hostname.remove();
             port.remove();

Modified: pivot/trunk/web/src/org/apache/pivot/web/QueryDictionary.java
URL: http://svn.apache.org/viewvc/pivot/trunk/web/src/org/apache/pivot/web/QueryDictionary.java?rev=904711&r1=904710&r2=904711&view=diff
==============================================================================
--- pivot/trunk/web/src/org/apache/pivot/web/QueryDictionary.java (original)
+++ pivot/trunk/web/src/org/apache/pivot/web/QueryDictionary.java Sat Jan 30 02:21:48 2010
@@ -37,7 +37,7 @@
 
     @Override
     public String get(String key) {
-        if (caseSensitiveKeys) {
+        if (!caseSensitiveKeys) {
             key = key.toLowerCase();
         }
 
@@ -50,7 +50,7 @@
     }
 
     public String get(String key, int index) {
-        if (caseSensitiveKeys) {
+        if (!caseSensitiveKeys) {
             key = key.toLowerCase();
         }
 
@@ -64,7 +64,7 @@
 
     @Override
     public String put(String key, String value) {
-        if (caseSensitiveKeys) {
+        if (!caseSensitiveKeys) {
             key = key.toLowerCase();
         }
 
@@ -80,7 +80,7 @@
     }
 
     public int add(String key, String value) {
-        if (caseSensitiveKeys) {
+        if (!caseSensitiveKeys) {
             key = key.toLowerCase();
         }
 
@@ -95,7 +95,7 @@
     }
 
     public void insert(String key, String value, int index) {
-        if (caseSensitiveKeys) {
+        if (!caseSensitiveKeys) {
             key = key.toLowerCase();
         }
 
@@ -111,7 +111,7 @@
 
     @Override
     public String remove(String key) {
-        if (caseSensitiveKeys) {
+        if (!caseSensitiveKeys) {
             key = key.toLowerCase();
         }
 
@@ -124,7 +124,7 @@
     }
 
     public String remove(String key, int index) {
-        if (caseSensitiveKeys) {
+        if (!caseSensitiveKeys) {
             key = key.toLowerCase();
         }
 
@@ -142,7 +142,7 @@
 
     @Override
     public boolean containsKey(String key) {
-        if (caseSensitiveKeys) {
+        if (!caseSensitiveKeys) {
             key = key.toLowerCase();
         }
 
@@ -151,7 +151,7 @@
 
 
     public int getLength(String key) {
-        if (caseSensitiveKeys) {
+        if (!caseSensitiveKeys) {
             key = key.toLowerCase();
         }