cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From reinh...@apache.org
Subject svn commit: r720891 - in /cocoon/cocoon3/trunk: cocoon-docs/src/changes/ cocoon-rest/src/main/java/org/apache/cocoon/rest/controller/ cocoon-rest/src/main/java/org/apache/cocoon/rest/controller/response/ cocoon-sample/src/main/java/org/apache/cocoon/sa...
Date Wed, 26 Nov 2008 14:43:15 GMT
Author: reinhard
Date: Wed Nov 26 06:43:14 2008
New Revision: 720891

URL: http://svn.apache.org/viewvc?rev=720891&view=rev
Log:
<action dev="reinhard" type="update">
  [cocoon-rest] Introduce the interface org.apache.cocoon.rest.controller.response.StreamingResponse
that
  can be used for controller results. The most prominent use case for it is the 
  org.apache.cocoon.rest.controller.response.UrlResponse (before it was named 'PageResult'
which is a
  misleading name).
</action>      

Added:
    cocoon/cocoon3/trunk/cocoon-rest/src/main/java/org/apache/cocoon/rest/controller/response/StreamingResponse.java
  (with props)
    cocoon/cocoon3/trunk/cocoon-rest/src/main/java/org/apache/cocoon/rest/controller/response/URLResponse.java
  (contents, props changed)
      - copied, changed from r701953, cocoon/cocoon3/trunk/cocoon-rest/src/main/java/org/apache/cocoon/rest/controller/response/Page.java
Removed:
    cocoon/cocoon3/trunk/cocoon-rest/src/main/java/org/apache/cocoon/rest/controller/response/Page.java
Modified:
    cocoon/cocoon3/trunk/cocoon-docs/src/changes/changes.xml
    cocoon/cocoon3/trunk/cocoon-rest/src/main/java/org/apache/cocoon/rest/controller/SpringRESTController.java
    cocoon/cocoon3/trunk/cocoon-sample/src/main/java/org/apache/cocoon/sample/controller/DemoRESTController.java

Modified: cocoon/cocoon3/trunk/cocoon-docs/src/changes/changes.xml
URL: http://svn.apache.org/viewvc/cocoon/cocoon3/trunk/cocoon-docs/src/changes/changes.xml?rev=720891&r1=720890&r2=720891&view=diff
==============================================================================
--- cocoon/cocoon3/trunk/cocoon-docs/src/changes/changes.xml (original)
+++ cocoon/cocoon3/trunk/cocoon-docs/src/changes/changes.xml Wed Nov 26 06:43:14 2008
@@ -26,6 +26,12 @@
   <body>
     <release version="3.0.0-alpha-2" date="2008-00-00" description="unreleased">
       <action dev="reinhard" type="update">
+        [cocoon-rest] Introduce the interface org.apache.cocoon.rest.controller.response.StreamingResponse
that
+        can be used for controller results. The most prominent use case for it is the 
+        org.apache.cocoon.rest.controller.response.UrlResponse (before it was named 'PageResult'
which is a
+        misleading name).
+      </action>    
+      <action dev="reinhard" type="update">
         [all] Upgrade to Spring 2.5.6 and AspectJ 1.6.1.
       </action>    
       <action dev="reinhard" type="add" issue="COCOON3-7" due-to="Simone Tripodi">

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=720891&r1=720890&r2=720891&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
Wed Nov 26 06:43:14 2008
@@ -22,7 +22,6 @@
 import java.lang.annotation.Annotation;
 import java.lang.reflect.Field;
 import java.net.URL;
-import java.net.URLConnection;
 import java.util.List;
 import java.util.Map;
 
@@ -33,22 +32,19 @@
 
 import org.apache.cocoon.controller.Controller;
 import org.apache.cocoon.pipeline.ProcessingException;
-import org.apache.cocoon.pipeline.util.URLConnectionUtils;
 import org.apache.cocoon.rest.controller.annotation.BaseURL;
 import org.apache.cocoon.rest.controller.annotation.Inject;
 import org.apache.cocoon.rest.controller.annotation.RESTController;
 import org.apache.cocoon.rest.controller.annotation.RequestHeader;
 import org.apache.cocoon.rest.controller.annotation.RequestParameter;
 import org.apache.cocoon.rest.controller.annotation.SitemapParameter;
-import org.apache.cocoon.rest.controller.response.Page;
 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.controller.ControllerContextHelper;
 import org.apache.cocoon.servlet.node.StatusCodeCollector;
 import org.apache.cocoon.servlet.util.HttpContextHelper;
 import org.apache.cocoon.sitemap.util.ExceptionHandler;
-import org.apache.commons.io.IOUtils;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.springframework.beans.BeansException;
@@ -87,17 +83,9 @@
 
             // forward the response
             if (restResponse instanceof Status) {
-                Status status = (Status) restResponse;
-                StatusCodeCollector.setStatusCode(status.getStatus());
-            } else if (restResponse instanceof Page) {
-                Page page = (Page) restResponse;
-
-                ControllerContextHelper.storeContext(page.getData(), inputParameters);
-
-                URL pageUri = new URL(new URL("servlet:"), page.getUri());
-                URLConnection servletConnection = pageUri.openConnection();
-                IOUtils.copy(servletConnection.getInputStream(), outputStream);
-                URLConnectionUtils.closeQuietly(servletConnection);
+                StatusCodeCollector.setStatusCode(((Status) restResponse).getStatus());
+            } else if (restResponse instanceof StreamingResponse) {
+                ((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/StreamingResponse.java
URL: http://svn.apache.org/viewvc/cocoon/cocoon3/trunk/cocoon-rest/src/main/java/org/apache/cocoon/rest/controller/response/StreamingResponse.java?rev=720891&view=auto
==============================================================================
--- cocoon/cocoon3/trunk/cocoon-rest/src/main/java/org/apache/cocoon/rest/controller/response/StreamingResponse.java
(added)
+++ cocoon/cocoon3/trunk/cocoon-rest/src/main/java/org/apache/cocoon/rest/controller/response/StreamingResponse.java
Wed Nov 26 06:43:14 2008
@@ -0,0 +1,28 @@
+/*
+ * 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;
+
+/**
+ * This interface can be used as {@link RestResponse} if the result of a controller is a
{@link OutputStream}.
+ */
+public interface StreamingResponse extends RestResponse {
+
+    void stream(OutputStream outputStream, Map<String, Object> inputParameters) throws
Exception;
+}

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

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

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

Copied: cocoon/cocoon3/trunk/cocoon-rest/src/main/java/org/apache/cocoon/rest/controller/response/URLResponse.java
(from r701953, cocoon/cocoon3/trunk/cocoon-rest/src/main/java/org/apache/cocoon/rest/controller/response/Page.java)
URL: http://svn.apache.org/viewvc/cocoon/cocoon3/trunk/cocoon-rest/src/main/java/org/apache/cocoon/rest/controller/response/URLResponse.java?p2=cocoon/cocoon3/trunk/cocoon-rest/src/main/java/org/apache/cocoon/rest/controller/response/URLResponse.java&p1=cocoon/cocoon3/trunk/cocoon-rest/src/main/java/org/apache/cocoon/rest/controller/response/Page.java&r1=701953&r2=720891&rev=720891&view=diff
==============================================================================
--- cocoon/cocoon3/trunk/cocoon-rest/src/main/java/org/apache/cocoon/rest/controller/response/Page.java
(original)
+++ cocoon/cocoon3/trunk/cocoon-rest/src/main/java/org/apache/cocoon/rest/controller/response/URLResponse.java
Wed Nov 26 06:43:14 2008
@@ -16,17 +16,33 @@
  */
 package org.apache.cocoon.rest.controller.response;
 
+import java.io.OutputStream;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.net.URLConnection;
 import java.util.HashMap;
 import java.util.Map;
 
-public class Page implements RestResponse {
+import org.apache.cocoon.pipeline.util.URLConnectionUtils;
+import org.apache.cocoon.servlet.controller.ControllerContextHelper;
+import org.apache.commons.io.IOUtils;
 
-    private String uri;
+/**
+ * A {@link URL} as controller response.
+ */
+public class URLResponse implements StreamingResponse {
+
+    private URL url;
 
     private Map<String, Object> data;
 
-    public Page(String uri, Map<String, Object> data) {
-        this.uri = uri;
+    public URLResponse(URL url, Map<String, Object> data) {
+        this.url = url;
+        this.data = data;
+    }
+
+    public URLResponse(String url, Map<String, Object> data) throws MalformedURLException
{
+        this.url = new URL(new URL("servlet:"), url);
         this.data = data;
     }
 
@@ -37,7 +53,19 @@
         return this.data;
     }
 
-    public String getUri() {
-        return this.uri;
+    public URL getUrl() {
+        return this.url;
+    }
+
+    public void stream(OutputStream outputStream, Map<String, Object> inputParameters)
throws Exception {
+        URLConnection servletConnection = null;
+        try {
+            ControllerContextHelper.storeContext(this.data, inputParameters);
+
+            servletConnection = this.url.openConnection();
+            IOUtils.copy(servletConnection.getInputStream(), outputStream);
+        } finally {
+            URLConnectionUtils.closeQuietly(servletConnection);
+        }
     }
 }

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

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

Propchange: cocoon/cocoon3/trunk/cocoon-rest/src/main/java/org/apache/cocoon/rest/controller/response/URLResponse.java
------------------------------------------------------------------------------
    svn:mergeinfo = 

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

Modified: cocoon/cocoon3/trunk/cocoon-sample/src/main/java/org/apache/cocoon/sample/controller/DemoRESTController.java
URL: http://svn.apache.org/viewvc/cocoon/cocoon3/trunk/cocoon-sample/src/main/java/org/apache/cocoon/sample/controller/DemoRESTController.java?rev=720891&r1=720890&r2=720891&view=diff
==============================================================================
--- cocoon/cocoon3/trunk/cocoon-sample/src/main/java/org/apache/cocoon/sample/controller/DemoRESTController.java
(original)
+++ cocoon/cocoon3/trunk/cocoon-sample/src/main/java/org/apache/cocoon/sample/controller/DemoRESTController.java
Wed Nov 26 06:43:14 2008
@@ -23,8 +23,8 @@
 import org.apache.cocoon.rest.controller.annotation.RequestParameter;
 import org.apache.cocoon.rest.controller.annotation.SitemapParameter;
 import org.apache.cocoon.rest.controller.method.Get;
-import org.apache.cocoon.rest.controller.response.Page;
 import org.apache.cocoon.rest.controller.response.RestResponse;
+import org.apache.cocoon.rest.controller.response.URLResponse;
 
 @RESTController
 public class DemoRESTController implements Get {
@@ -44,6 +44,6 @@
         data.put("name", this.name);
         data.put("reqparam", this.reqparam);
 
-        return new Page("servlet:/controller/screen", data);
+        return new URLResponse("servlet:/controller/screen", data);
     }
 }



Mime
View raw message