cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From reinh...@apache.org
Subject svn commit: r787364 - in /cocoon/cocoon3/trunk/cocoon-rest/src/main/java/org/apache/cocoon/rest/controller: MethodDelegator.java SpringRESTController.java
Date Mon, 22 Jun 2009 19:34:00 GMT
Author: reinhard
Date: Mon Jun 22 19:34:00 2009
New Revision: 787364

URL: http://svn.apache.org/viewvc?rev=787364&view=rev
Log:
Static initialization of method delegators (since they are stateless they can be singletons)
improve logging

Modified:
    cocoon/cocoon3/trunk/cocoon-rest/src/main/java/org/apache/cocoon/rest/controller/MethodDelegator.java
    cocoon/cocoon3/trunk/cocoon-rest/src/main/java/org/apache/cocoon/rest/controller/SpringRESTController.java

Modified: cocoon/cocoon3/trunk/cocoon-rest/src/main/java/org/apache/cocoon/rest/controller/MethodDelegator.java
URL: http://svn.apache.org/viewvc/cocoon/cocoon3/trunk/cocoon-rest/src/main/java/org/apache/cocoon/rest/controller/MethodDelegator.java?rev=787364&r1=787363&r2=787364&view=diff
==============================================================================
--- cocoon/cocoon3/trunk/cocoon-rest/src/main/java/org/apache/cocoon/rest/controller/MethodDelegator.java
(original)
+++ cocoon/cocoon3/trunk/cocoon-rest/src/main/java/org/apache/cocoon/rest/controller/MethodDelegator.java
Mon Jun 22 19:34:00 2009
@@ -30,27 +30,33 @@
 import org.apache.cocoon.rest.controller.method.Put;
 import org.apache.cocoon.rest.controller.response.RestResponse;
 import org.apache.cocoon.rest.controller.response.Status;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
 
 public class MethodDelegator {
 
-    private Map<String, MethodDelegate> delegates = new HashMap<String, MethodDelegate>();
+    private static Map<String, MethodDelegate> delegates = new HashMap<String, MethodDelegate>();
+
+    private final Log logger = LogFactory.getLog(this.getClass());
+
+    static {
+        delegates.put("DELETE", new DeleteDelegate());
+        delegates.put("GET", new GetDelegate());
+        delegates.put("HEAD", new HeadDelegate());
+        delegates.put("OPTIONS", new OptionsDelegate());
+        delegates.put("POST", new PostDelegate());
+        delegates.put("PUT", new PutDelegate());
+    }
 
     public MethodDelegator() {
         super();
-
-        this.delegates.put("DELETE", new DeleteDelegate());
-        this.delegates.put("GET", new GetDelegate());
-        this.delegates.put("HEAD", new HeadDelegate());
-        this.delegates.put("OPTIONS", new OptionsDelegate());
-        this.delegates.put("POST", new PostDelegate());
-        this.delegates.put("PUT", new PutDelegate());
     }
 
     public RestResponse delegate(HttpServletRequest request, Object controller) throws Exception
{
         if (request != null && request.getMethod() != null) {
             String method = this.getMethod(request);
 
-            MethodDelegate methodDelegate = this.delegates.get(method);
+            MethodDelegate methodDelegate = delegates.get(method);
             if (methodDelegate != null) {
                 return methodDelegate.execute(controller);
             }
@@ -62,17 +68,25 @@
     private String getMethod(HttpServletRequest request) {
         String alternativeMethod = request.getParameter("_method");
         if (alternativeMethod != null) {
-            if (this.delegates.keySet().contains(alternativeMethod.toUpperCase())) {
-                return alternativeMethod.toUpperCase();
+            alternativeMethod = alternativeMethod.toUpperCase();
+            if (delegates.keySet().contains(alternativeMethod)) {
+                if (this.logger.isDebugEnabled()) {
+                    this.logger.debug("Using alternative request method '" + alternativeMethod
+                            + "' as provided by the request parameter '_method'");
+                }
+
+                return alternativeMethod;
             }
 
-            // TODO log the unsupported method name
+            if (this.logger.isWarnEnabled()) {
+                this.logger.warn("The request parameter '_request' refers to an unsupported
request method: _method='" + alternativeMethod + "'");
+            }
         }
 
         return request.getMethod().toUpperCase();
     }
 
-    private class DeleteDelegate extends MethodDelegate {
+    private static class DeleteDelegate extends MethodDelegate {
 
         public DeleteDelegate() {
             super();
@@ -88,7 +102,7 @@
         }
     }
 
-    private class GetDelegate extends MethodDelegate {
+    private static class GetDelegate extends MethodDelegate {
 
         public GetDelegate() {
             super();
@@ -104,7 +118,7 @@
         }
     }
 
-    private class HeadDelegate extends MethodDelegate {
+    private static class HeadDelegate extends MethodDelegate {
 
         public HeadDelegate() {
             super();
@@ -120,7 +134,7 @@
         }
     }
 
-    private abstract class MethodDelegate {
+    private static abstract class MethodDelegate {
 
         public MethodDelegate() {
             super();
@@ -131,7 +145,7 @@
         }
     }
 
-    private class OptionsDelegate extends MethodDelegate {
+    private static class OptionsDelegate extends MethodDelegate {
 
         public OptionsDelegate() {
             super();
@@ -147,7 +161,7 @@
         }
     }
 
-    private class PostDelegate extends MethodDelegate {
+    private static class PostDelegate extends MethodDelegate {
 
         public PostDelegate() {
             super();
@@ -164,7 +178,7 @@
         }
     }
 
-    private class PutDelegate extends MethodDelegate {
+    private static class PutDelegate extends MethodDelegate {
 
         public PutDelegate() {
             super();

Modified: cocoon/cocoon3/trunk/cocoon-rest/src/main/java/org/apache/cocoon/rest/controller/SpringRESTController.java
URL: http://svn.apache.org/viewvc/cocoon/cocoon3/trunk/cocoon-rest/src/main/java/org/apache/cocoon/rest/controller/SpringRESTController.java?rev=787364&r1=787363&r2=787364&view=diff
==============================================================================
--- cocoon/cocoon3/trunk/cocoon-rest/src/main/java/org/apache/cocoon/rest/controller/SpringRESTController.java
(original)
+++ cocoon/cocoon3/trunk/cocoon-rest/src/main/java/org/apache/cocoon/rest/controller/SpringRESTController.java
Mon Jun 22 19:34:00 2009
@@ -66,9 +66,7 @@
 public class SpringRESTController implements Controller, ApplicationContextAware {
 
     private AnnotationCollector annotationCollector;
-
     private ApplicationContext applicationContext;
-
     private MethodDelegator methodDelegator;
 
     public String invoke(OutputStream outputStream, String controllerName, Map<String,
Object> inputParameters,



Mime
View raw message