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/02/03 16:58:29 UTC

svn commit: r906098 - /pivot/trunk/web-server/src/org/apache/pivot/web/server/QueryServlet.java

Author: gbrown
Date: Wed Feb  3 15:58:28 2010
New Revision: 906098

URL: http://svn.apache.org/viewvc?rev=906098&view=rev
Log:
Add a validate() method to QueryServlet to allow the servlet to optionally validate a request before it is passed to the HTTP handler method; add a configureSerialzer() method to allow a servlet to configure a serializer before it is used to read or write the request data.

Modified:
    pivot/trunk/web-server/src/org/apache/pivot/web/server/QueryServlet.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=906098&r1=906097&r2=906098&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 Wed Feb  3 15:58:28 2010
@@ -141,7 +141,7 @@
 
     /**
      * Prepares a servlet for request execution. This method is called immediately
-     * prior to the HTTP handler method.
+     * prior to the {@link #validate(String)} method.
      * <p>
      * The default implementation is a no-op.
      *
@@ -162,6 +162,25 @@
     }
 
     /**
+     * Validates 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 QueryException
+     */
+    public void validate(String path) throws QueryException {
+    }
+
+    /**
+     * Allows a servlet to configure a serializer
+     *
+     * @param serializer
+     */
+    public void configureSerializer(Serializer<Object> serializer, String path) {
+    }
+
+    /**
      * Handles an HTTP GET request. The default implementation throws an HTTP
      * 405 query exception.
      *
@@ -302,7 +321,10 @@
 
         Object result = null;
         try {
-            result = doGet(request.getPathInfo());
+            String path = request.getPathInfo();
+            validate(path);
+            configureSerializer(serializer, path);
+            result = doGet(path);
         } catch (QueryException exception) {
             response.setStatus(exception.getStatus());
             response.flushBuffer();
@@ -373,7 +395,10 @@
 
             URL location = null;
             try {
-                location = doPost(request.getPathInfo(), value);
+                String path = request.getPathInfo();
+                validate(path);
+                configureSerializer(serializer, path);
+                location = doPost(path, value);
             } catch (QueryException exception) {
                 response.setStatus(exception.getStatus());
                 response.flushBuffer();
@@ -387,7 +412,9 @@
             }
         } else {
             try {
-                doPostAction(request.getPathInfo(), action);
+                String path = request.getPathInfo();
+                validate(path);
+                doPostAction(path, action);
             } catch (QueryException exception) {
                 response.setStatus(exception.getStatus());
                 response.flushBuffer();
@@ -416,7 +443,10 @@
         }
 
         try {
-            doPut(request.getPathInfo(), value);
+            String path = request.getPathInfo();
+            validate(path);
+            configureSerializer(serializer, path);
+            doPut(path, value);
         } catch (QueryException exception) {
             response.setStatus(exception.getStatus());
             response.flushBuffer();
@@ -434,7 +464,9 @@
     protected final void doDelete(HttpServletRequest request, HttpServletResponse response)
         throws IOException, ServletException {
         try {
-            doDelete(request.getPathInfo());
+            String path = request.getPathInfo();
+            validate(path);
+            doDelete(path);
         } catch (QueryException exception) {
             response.setStatus(exception.getStatus());
             response.flushBuffer();