You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tapestry.apache.org by hl...@apache.org on 2007/06/08 17:49:32 UTC

svn commit: r545536 - in /tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry: ./ internal/services/ internal/test/ services/ util/

Author: hlship
Date: Fri Jun  8 08:49:31 2007
New Revision: 545536

URL: http://svn.apache.org/viewvc?view=rev&rev=545536
Log:
TAPESTRY-1409: Extend StreamResponse to support setting headers in the Response prior to streaming the contents from the InputStream

Modified:
    tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/StreamResponse.java
    tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/services/ResponseImpl.java
    tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/services/StreamResponseResultProcessor.java
    tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/test/TestableResponseImpl.java
    tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/services/Response.java
    tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/util/TextStreamResponse.java

Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/StreamResponse.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/StreamResponse.java?view=diff&rev=545536&r1=545535&r2=545536
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/StreamResponse.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/StreamResponse.java Fri Jun  8 08:49:31 2007
@@ -14,6 +14,8 @@
 
 package org.apache.tapestry;
 
+import org.apache.tapestry.services.Response;
+
 import java.io.BufferedInputStream;
 import java.io.IOException;
 import java.io.InputStream;
@@ -34,4 +36,13 @@
      * {@link BufferedInputStream} for efficiency.
      */
     InputStream getStream() throws IOException;
+
+
+    /**
+     * Prepare response before it is sent to the client.
+     * This is the place to set any response headers (e.g. content-disposition)
+     * @param response Response that will be sent.
+     */
+    void prepareResponse(Response response);
+
 }

Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/services/ResponseImpl.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/services/ResponseImpl.java?view=diff&rev=545536&r1=545535&r2=545536
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/services/ResponseImpl.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/services/ResponseImpl.java Fri Jun  8 08:49:31 2007
@@ -87,4 +87,16 @@
         _response.setDateHeader(name, date);
     }
 
+    public void setHeader(String name, String value)
+    {
+        _response.setHeader(name,value);
+    }
+
+    public void setIntHeader(String name, int value)
+    {
+        _response.setIntHeader(name, value);
+    }
+
+
+
 }

Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/services/StreamResponseResultProcessor.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/services/StreamResponseResultProcessor.java?view=diff&rev=545536&r1=545535&r2=545536
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/services/StreamResponseResultProcessor.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/services/StreamResponseResultProcessor.java Fri Jun  8 08:49:31 2007
@@ -40,6 +40,7 @@
                 OutputStream os = null;
                 InputStream is = null;
 
+                streamResponse.prepareResponse(response);
                 try
                 {
                     is = new BufferedInputStream(streamResponse.getStream());

Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/test/TestableResponseImpl.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/test/TestableResponseImpl.java?view=diff&rev=545536&r1=545535&r2=545536
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/test/TestableResponseImpl.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/test/TestableResponseImpl.java Fri Jun  8 08:49:31 2007
@@ -64,6 +64,16 @@
         nyi("setDateHeader");
     }
 
+    public void setHeader(String name, String value)
+    {
+        nyi("setHeader");
+    }
+
+    public void setIntHeader(String name, int value)
+    {
+        nyi("setIntHeader");
+    }
+
     public String encodeRedirectURL(String URL)
     {
         return URL;

Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/services/Response.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/services/Response.java?view=diff&rev=545536&r1=545535&r2=545536
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/services/Response.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/services/Response.java Fri Jun  8 08:49:31 2007
@@ -66,7 +66,7 @@
      * 
      * @param sc
      *            the error status code
-     * @param msg
+     * @param message
      *            the descriptive message
      * @exception IOException
      *                If an input or output exception occurs
@@ -95,6 +95,26 @@
      *            the assigned date value
      */
     void setDateHeader(String name, long date);
+
+    /**
+     * Sets a response header with the given name and value. If the header had already been set,
+     * the new value overwrites the previous one.
+     * @param name
+     *            the name of the header to set
+     * @param value
+     *            the assigned value
+     */
+    void setHeader(String name, String value);
+
+    /**
+     * Sets a response header with the given name and integer value. If the header had already been set,
+     * the new value overwrites the previous one.
+     * @param name
+     *            the name of the header to set
+     * @param value
+     *            the assigned integer value
+     */
+    void setIntHeader(String name, int value);
 
     /**
      * Encodes the URL, ensuring that a session id is included (if a session exists, and as

Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/util/TextStreamResponse.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/util/TextStreamResponse.java?view=diff&rev=545536&r1=545535&r2=545536
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/util/TextStreamResponse.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/util/TextStreamResponse.java Fri Jun  8 08:49:31 2007
@@ -22,6 +22,7 @@
 import java.io.InputStream;
 
 import org.apache.tapestry.StreamResponse;
+import org.apache.tapestry.services.Response;
 
 public class TextStreamResponse implements StreamResponse
 {
@@ -46,6 +47,11 @@
     public InputStream getStream() throws IOException
     {
         return new ByteArrayInputStream(_text.getBytes());
+    }
+
+    public void prepareResponse(Response response)
+    {
+        // No-op by default.
     }
 
 }