cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From stevend...@apache.org
Subject svn commit: r758669 - in /cocoon/cocoon3/trunk/cocoon-rest/src/main/java/org/apache/cocoon/rest/controller: SpringRESTController.java response/RedirectResponse.java response/RestResponse.java response/Status.java response/URLResponse.java
Date Thu, 26 Mar 2009 14:50:48 GMT
Author: stevendolg
Date: Thu Mar 26 14:50:32 2009
New Revision: 758669

URL: http://svn.apache.org/viewvc?rev=758669&view=rev
Log:
Changed RestResponse to make it easier to implement specific response implementations.
Processing the responses no longer requires the SpringRESTController to actually know anything
about the actual implementation.

Added:
    cocoon/cocoon3/trunk/cocoon-rest/src/main/java/org/apache/cocoon/rest/controller/response/RedirectResponse.java
  (with props)
Modified:
    cocoon/cocoon3/trunk/cocoon-rest/src/main/java/org/apache/cocoon/rest/controller/SpringRESTController.java
    cocoon/cocoon3/trunk/cocoon-rest/src/main/java/org/apache/cocoon/rest/controller/response/RestResponse.java
    cocoon/cocoon3/trunk/cocoon-rest/src/main/java/org/apache/cocoon/rest/controller/response/Status.java
    cocoon/cocoon3/trunk/cocoon-rest/src/main/java/org/apache/cocoon/rest/controller/response/URLResponse.java

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=758669&r1=758668&r2=758669&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
Thu Mar 26 14:50:32 2009
@@ -41,10 +41,7 @@
 import org.apache.cocoon.rest.controller.annotation.RequestParameter;
 import org.apache.cocoon.rest.controller.annotation.SitemapParameter;
 import org.apache.cocoon.rest.controller.response.RestResponse;
-import org.apache.cocoon.rest.controller.response.Status;
-import org.apache.cocoon.rest.controller.response.StreamingResponse;
 import org.apache.cocoon.rest.controller.util.AnnotationCollector;
-import org.apache.cocoon.servlet.node.StatusCodeCollector;
 import org.apache.cocoon.servlet.util.HttpContextHelper;
 import org.apache.cocoon.servlet.util.SettingsHelper;
 import org.apache.cocoon.sitemap.util.ExceptionHandler;
@@ -86,12 +83,13 @@
             HttpServletRequest request = HttpContextHelper.getRequest(inputParameters);
             RestResponse restResponse = this.methodDelegator.delegate(request, controller);
 
-            // forward the response
-            if (restResponse instanceof Status) {
-                StatusCodeCollector.setStatusCode(((Status) restResponse).getStatus());
-            } else if (restResponse instanceof StreamingResponse) {
-                return ((StreamingResponse) restResponse).stream(outputStream, inputParameters);
-            }
+            restResponse.execute(outputStream, inputParameters);
+            // // forward the response
+            // if (restResponse instanceof Status) {
+            // StatusCodeCollector.setStatusCode(((Status) restResponse).getStatus());
+            // } else if (restResponse instanceof StreamingResponse) {
+            // return ((StreamingResponse) restResponse).stream(outputStream, inputParameters);
+            // }
         } catch (Exception e) {
             throw ExceptionHandler.getInvocationException(e);
         }

Added: cocoon/cocoon3/trunk/cocoon-rest/src/main/java/org/apache/cocoon/rest/controller/response/RedirectResponse.java
URL: http://svn.apache.org/viewvc/cocoon/cocoon3/trunk/cocoon-rest/src/main/java/org/apache/cocoon/rest/controller/response/RedirectResponse.java?rev=758669&view=auto
==============================================================================
--- cocoon/cocoon3/trunk/cocoon-rest/src/main/java/org/apache/cocoon/rest/controller/response/RedirectResponse.java
(added)
+++ cocoon/cocoon3/trunk/cocoon-rest/src/main/java/org/apache/cocoon/rest/controller/response/RedirectResponse.java
Thu Mar 26 14:50:32 2009
@@ -0,0 +1,40 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.cocoon.rest.controller.response;
+
+import java.io.OutputStream;
+import java.util.Map;
+
+import javax.servlet.http.HttpServletResponse;
+
+import org.apache.cocoon.servlet.util.HttpContextHelper;
+
+public class RedirectResponse implements RestResponse {
+
+    private final String location;
+
+    public RedirectResponse(String location) {
+        super();
+        this.location = location;
+    }
+
+    public void execute(OutputStream outputStream, Map<String, Object> inputParameters)
throws Exception {
+        HttpServletResponse response = HttpContextHelper.getResponse(inputParameters);
+
+        response.sendRedirect(this.location);
+    }
+}

Propchange: cocoon/cocoon3/trunk/cocoon-rest/src/main/java/org/apache/cocoon/rest/controller/response/RedirectResponse.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cocoon/cocoon3/trunk/cocoon-rest/src/main/java/org/apache/cocoon/rest/controller/response/RedirectResponse.java
------------------------------------------------------------------------------
    svn:keywords = Id

Propchange: cocoon/cocoon3/trunk/cocoon-rest/src/main/java/org/apache/cocoon/rest/controller/response/RedirectResponse.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: cocoon/cocoon3/trunk/cocoon-rest/src/main/java/org/apache/cocoon/rest/controller/response/RestResponse.java
URL: http://svn.apache.org/viewvc/cocoon/cocoon3/trunk/cocoon-rest/src/main/java/org/apache/cocoon/rest/controller/response/RestResponse.java?rev=758669&r1=758668&r2=758669&view=diff
==============================================================================
--- cocoon/cocoon3/trunk/cocoon-rest/src/main/java/org/apache/cocoon/rest/controller/response/RestResponse.java
(original)
+++ cocoon/cocoon3/trunk/cocoon-rest/src/main/java/org/apache/cocoon/rest/controller/response/RestResponse.java
Thu Mar 26 14:50:32 2009
@@ -16,5 +16,10 @@
  */
 package org.apache.cocoon.rest.controller.response;
 
+import java.io.OutputStream;
+import java.util.Map;
+
 public interface RestResponse {
+
+    void execute(OutputStream outputStream, Map<String, Object> inputParameters) throws
Exception;
 }

Modified: cocoon/cocoon3/trunk/cocoon-rest/src/main/java/org/apache/cocoon/rest/controller/response/Status.java
URL: http://svn.apache.org/viewvc/cocoon/cocoon3/trunk/cocoon-rest/src/main/java/org/apache/cocoon/rest/controller/response/Status.java?rev=758669&r1=758668&r2=758669&view=diff
==============================================================================
--- cocoon/cocoon3/trunk/cocoon-rest/src/main/java/org/apache/cocoon/rest/controller/response/Status.java
(original)
+++ cocoon/cocoon3/trunk/cocoon-rest/src/main/java/org/apache/cocoon/rest/controller/response/Status.java
Thu Mar 26 14:50:32 2009
@@ -16,6 +16,11 @@
  */
 package org.apache.cocoon.rest.controller.response;
 
+import java.io.OutputStream;
+import java.util.Map;
+
+import org.apache.cocoon.servlet.node.StatusCodeCollector;
+
 public class Status implements RestResponse {
 
     private int status;
@@ -27,4 +32,8 @@
     public int getStatus() {
         return this.status;
     }
+
+    public void execute(OutputStream outputStream, Map<String, Object> inputParameters)
{
+        StatusCodeCollector.setStatusCode(this.status);
+    }
 }

Modified: cocoon/cocoon3/trunk/cocoon-rest/src/main/java/org/apache/cocoon/rest/controller/response/URLResponse.java
URL: http://svn.apache.org/viewvc/cocoon/cocoon3/trunk/cocoon-rest/src/main/java/org/apache/cocoon/rest/controller/response/URLResponse.java?rev=758669&r1=758668&r2=758669&view=diff
==============================================================================
--- cocoon/cocoon3/trunk/cocoon-rest/src/main/java/org/apache/cocoon/rest/controller/response/URLResponse.java
(original)
+++ cocoon/cocoon3/trunk/cocoon-rest/src/main/java/org/apache/cocoon/rest/controller/response/URLResponse.java
Thu Mar 26 14:50:32 2009
@@ -81,4 +81,8 @@
             URLConnectionUtils.closeQuietly(servletConnection);
         }
     }
+
+    public void execute(OutputStream outputStream, Map<String, Object> inputParameters)
throws Exception {
+        this.stream(outputStream, inputParameters);
+    }
 }



Mime
View raw message