Author: hlship
Date: Tue Aug 31 17:27:21 2010
New Revision: 991267

URL: http://svn.apache.org/viewvc?rev=991267&view=rev
Log:
TAP5-1236: Add method Response.disableCompression() (to avoid use of a internal 
global key)

Modified:
    
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/ResourceStreamerImpl.java
    
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/ResponseImpl.java
    
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/StreamResponseResultProcessor.java
    
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/assets/StackAssetRequestHandler.java
    
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/test/TestableResponseImpl.java
    
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/services/Request.java
    
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/services/Response.java
    
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/services/TapestryModule.java
    
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/util/ResponseWrapper.java
    
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/ResourceStreamerImplTest.java

Modified: 
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/ResourceStreamerImpl.java
URL: 
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/ResourceStreamerImpl.java?rev=991267&r1=991266&r2=991267&view=diff
==============================================================================
--- 
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/ResourceStreamerImpl.java
 (original)
+++ 
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/ResourceStreamerImpl.java
 Tue Aug 31 17:27:21 2010
@@ -114,8 +114,8 @@ public class ResourceStreamerImpl implem
 
         // Prevent the upstream code from compressing when we don't want to.
 
-        request.setAttribute(InternalConstants.SUPPRESS_COMPRESSION, true);
-
+        response.disableCompression();
+        
         StreamableResource streamble = 
resourceCache.getStreamableResource(resource);
 
         long lastModified = streamble.getLastModified();

Modified: 
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/ResponseImpl.java
URL: 
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/ResponseImpl.java?rev=991267&r1=991266&r2=991267&view=diff
==============================================================================
--- 
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/ResponseImpl.java
 (original)
+++ 
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/ResponseImpl.java
 Tue Aug 31 17:27:21 2010
@@ -4,7 +4,7 @@
 // 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
+// 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,
@@ -21,9 +21,11 @@ import java.io.OutputStreamWriter;
 import java.io.PrintWriter;
 import java.io.Writer;
 
+import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 
 import org.apache.tapestry5.Link;
+import org.apache.tapestry5.internal.InternalConstants;
 import org.apache.tapestry5.ioc.internal.util.InternalUtils;
 import org.apache.tapestry5.services.Response;
 
@@ -32,11 +34,16 @@ import org.apache.tapestry5.services.Res
  */
 public class ResponseImpl implements Response
 {
+    private final HttpServletRequest request;
+
     private final HttpServletResponse response;
 
-    public ResponseImpl(HttpServletResponse response)
+    public ResponseImpl(HttpServletRequest request, HttpServletResponse 
response)
     {
+        assert request != null;
         assert response != null;
+
+        this.request = request;
         this.response = response;
     }
 
@@ -115,4 +122,9 @@ public class ResponseImpl implements Res
     {
         return response.isCommitted();
     }
+
+    public void disableCompression()
+    {
+        request.setAttribute(InternalConstants.SUPPRESS_COMPRESSION, true);
+    }
 }

Modified: 
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/StreamResponseResultProcessor.java
URL: 
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/StreamResponseResultProcessor.java?rev=991267&r1=991266&r2=991267&view=diff
==============================================================================
--- 
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/StreamResponseResultProcessor.java
 (original)
+++ 
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/StreamResponseResultProcessor.java
 Tue Aug 31 17:27:21 2010
@@ -1,10 +1,10 @@
-// Copyright 2007, 2008, 2009 The Apache Software Foundation
+// Copyright 2007, 2008, 2009, 2010 The Apache Software Foundation
 //
 // Licensed 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
+// 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,
@@ -14,33 +14,27 @@
 
 package org.apache.tapestry5.internal.services;
 
+import java.io.BufferedInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+
 import org.apache.tapestry5.StreamResponse;
-import org.apache.tapestry5.internal.InternalConstants;
 import org.apache.tapestry5.internal.TapestryInternalUtils;
 import org.apache.tapestry5.ioc.internal.util.InternalUtils;
 import org.apache.tapestry5.services.ComponentEventResultProcessor;
-import org.apache.tapestry5.services.Request;
 import org.apache.tapestry5.services.Response;
 
-import java.io.BufferedInputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-
 public class StreamResponseResultProcessor implements 
ComponentEventResultProcessor<StreamResponse>
 {
-    private final Request request;
-
     private final Response response;
 
-    public StreamResponseResultProcessor(Request request, Response response)
+    public StreamResponseResultProcessor(Response response)
     {
         this.response = response;
-        this.request = request;
     }
 
-    public void processResultValue(StreamResponse streamResponse)
-            throws IOException
+    public void processResultValue(StreamResponse streamResponse) throws 
IOException
     {
         OutputStream os = null;
         InputStream is = null;
@@ -49,7 +43,7 @@ public class StreamResponseResultProcess
         // if they want to compress the result, they can add their own 
GZIPOutputStream to
         // their pipeline.
 
-        request.setAttribute(InternalConstants.SUPPRESS_COMPRESSION, true);
+        response.disableCompression();
 
         streamResponse.prepareResponse(response);
 

Modified: 
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/assets/StackAssetRequestHandler.java
URL: 
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/assets/StackAssetRequestHandler.java?rev=991267&r1=991266&r2=991267&view=diff
==============================================================================
--- 
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/assets/StackAssetRequestHandler.java
 (original)
+++ 
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/assets/StackAssetRequestHandler.java
 Tue Aug 31 17:27:21 2010
@@ -92,10 +92,9 @@ public class StackAssetRequestHandler im
         if (productionMode)
             response.setDateHeader("Expires", lastModified + 
InternalConstants.TEN_YEARS);
 
-        response.setContentLength(cachedStream.size());
+        response.disableCompression();
 
-        // Inform the upper layers that we are controlled compression here.
-        request.setAttribute(InternalConstants.SUPPRESS_COMPRESSION, true);
+        response.setContentLength(cachedStream.size());
 
         if (compress)
             response.setHeader(InternalConstants.CONTENT_ENCODING_HEADER, 
InternalConstants.GZIP_CONTENT_ENCODING);

Modified: 
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/test/TestableResponseImpl.java
URL: 
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/test/TestableResponseImpl.java?rev=991267&r1=991266&r2=991267&view=diff
==============================================================================
--- 
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/test/TestableResponseImpl.java
 (original)
+++ 
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/test/TestableResponseImpl.java
 Tue Aug 31 17:27:21 2010
@@ -1,10 +1,10 @@
-// Copyright 2007, 2008, 2009 The Apache Software Foundation
+// Copyright 2007, 2008, 2009, 2010 The Apache Software Foundation
 //
 // Licensed 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
+// 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,
@@ -125,4 +125,9 @@ public class TestableResponseImpl implem
     {
         renderedDocument = document;
     }
+
+    public void disableCompression()
+    {
+    }
+
 }

Modified: 
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/services/Request.java
URL: 
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/services/Request.java?rev=991267&r1=991266&r2=991267&view=diff
==============================================================================
--- 
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/services/Request.java
 (original)
+++ 
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/services/Request.java
 Tue Aug 31 17:27:21 2010
@@ -162,7 +162,7 @@ public interface Request
      * 
      * @return a string specifying the name of the method with which this 
request was made
      */
-    public String getMethod();
+    String getMethod();
 
     /**
      * Returns the Internet Protocol (IP) port number of the interface
@@ -171,5 +171,5 @@ public interface Request
      * @return an integer specifying the port number
      * @since 5.2.0
      */
-    public int getLocalPort();
+    int getLocalPort();
 }

Modified: 
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/services/Response.java
URL: 
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/services/Response.java?rev=991267&r1=991266&r2=991267&view=diff
==============================================================================
--- 
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/services/Response.java
 (original)
+++ 
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/services/Response.java
 Tue Aug 31 17:27:21 2010
@@ -1,10 +1,10 @@
-// Copyright 2006, 2007, 2008 The Apache Software Foundation
+// Copyright 2006, 2007, 2008, 2010 The Apache Software Foundation
 //
 // Licensed 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
+// 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,
@@ -31,41 +31,46 @@ public interface Response
 {
     /**
      * Returns a PrintWriter object to which output may be sent. Invoking 
flush() on the writer will commit the output.
-     *
-     * @param contentType the MIME content type for the output, typically 
"text/html"
+     * 
+     * @param contentType
+     *            the MIME content type for the output, typically "text/html"
      */
     PrintWriter getPrintWriter(String contentType) throws IOException;
 
     /**
      * Returns an OutputStream to which byte-oriented output may be sent. 
Invoking flush() on the stream will commit the
      * output.
-     *
-     * @param contentType the MIME content type for the output, often 
"application/octet-stream" or "text/plain" or one
-     *                    of several others
+     * 
+     * @param contentType
+     *            the MIME content type for the output, often 
"application/octet-stream" or "text/plain" or one
+     *            of several others
      */
     OutputStream getOutputStream(String contentType) throws IOException;
 
     /**
      * Sends a redirect to the client.
-     *
-     * @param URL full or partial (relative) URL to send to the client
+     * 
+     * @param URL
+     *            full or partial (relative) URL to send to the client
      * @see #encodeRedirectURL(String)
      */
     void sendRedirect(String URL) throws IOException;
 
     /**
      * Sends a redirect to a link.
-     *
-     * @param link link to redirect to.
+     * 
+     * @param link
+     *            link to redirect to.
      */
     void sendRedirect(Link link) throws IOException;
 
     /**
-     * Sets the status code for this response.  This method is used to set the 
return status code when there is no error
-     * (for example, for the status codes SC_OK or SC_MOVED_TEMPORARILY).  If 
there is an error, and the caller wishes
+     * Sets the status code for this response. This method is used to set the 
return status code when there is no error
+     * (for example, for the status codes SC_OK or SC_MOVED_TEMPORARILY). If 
there is an error, and the caller wishes
      * to invoke an error-page defined in the web applicaion, the 
<code>sendError</code> method should be used instead.
-     *
-     * @param sc the status code
+     * 
+     * @param sc
+     *            the status code
      */
     public void setStatus(int sc);
 
@@ -78,52 +83,63 @@ public interface Response
      * <p/>
      * If the response has already been committed, this method throws an 
IllegalStateException. After using this method,
      * the response should be considered to be committed and should not be 
written to.
-     *
-     * @param sc      the error status code
-     * @param message the descriptive message
-     * @throws IOException           If an input or output exception occurs
-     * @throws IllegalStateException If the response was committed
+     * 
+     * @param sc
+     *            the error status code
+     * @param message
+     *            the descriptive message
+     * @throws IOException
+     *             If an input or output exception occurs
+     * @throws IllegalStateException
+     *             If the response was committed
      */
     void sendError(int sc, String message) throws IOException;
 
     /**
      * Sets the length of the content body in the response; this method sets 
the HTTP Content-Length header.
-     *
-     * @param length the length of the content
+     * 
+     * @param length
+     *            the length of the content
      */
     void setContentLength(int length);
 
     /**
      * Sets a response header with the given name and date-value. The date is 
specified in terms of milliseconds since
      * the epoch. If the header had already been set, the new value overwrites 
the previous one.
-     *
-     * @param name the name of the header to set
-     * @param date the assigned date value
+     * 
+     * @param name
+     *            the name of the header to set
+     * @param date
+     *            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
+     * 
+     * @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
+     * 
+     * @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 necessary depending on the
      * client browser's use of cookies).
-     *
+     * 
      * @param URL
      * @return the same URL or a different one with additional information to 
track the user session
      */
@@ -132,7 +148,7 @@ public interface Response
     /**
      * Encodes the URL for use as a redirect, ensuring that a session id is 
included (if a session exists, and as
      * necessary depending on the client browser's use of cookies).
-     *
+     * 
      * @param URL
      * @return the same URL or a different one with additional information to 
track the user session
      */
@@ -140,8 +156,15 @@ public interface Response
 
     /**
      * Returns true if the response has already been sent, either as a 
redirect or as a stream of content.
-     *
+     * 
      * @return true if response already sent
      */
     boolean isCommitted();
+
+    /**
+     * Invoked to indicate that the response content is either already 
compressed, or is not compressable.
+     * 
+     * @since 5.2.1
+     */
+    void disableCompression();
 }

Modified: 
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/services/TapestryModule.java
URL: 
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/services/TapestryModule.java?rev=991267&r1=991266&r2=991267&view=diff
==============================================================================
--- 
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/services/TapestryModule.java
 (original)
+++ 
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/services/TapestryModule.java
 Tue Aug 31 17:27:21 2010
@@ -257,7 +257,7 @@ public final class TapestryModule
             requestGlobals.storeServletRequestResponse(servletRequest, 
servletResponse);
 
             Request request = new RequestImpl(servletRequest, 
applicationCharset, analyzer);
-            Response response = new ResponseImpl(servletResponse);
+            Response response = new ResponseImpl(servletRequest, 
servletResponse);
 
             // TAP5-257: Make sure that the "initial guess" for 
request/response
             // is available, even if

Modified: 
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/util/ResponseWrapper.java
URL: 
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/util/ResponseWrapper.java?rev=991267&r1=991266&r2=991267&view=diff
==============================================================================
--- 
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/util/ResponseWrapper.java
 (original)
+++ 
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/util/ResponseWrapper.java
 Tue Aug 31 17:27:21 2010
@@ -4,7 +4,7 @@
 // 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
+// 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,
@@ -99,4 +99,9 @@ public class ResponseWrapper implements 
     {
         return response.isCommitted();
     }
+
+    public void disableCompression()
+    {
+        response.disableCompression();
+    }
 }

Modified: 
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/ResourceStreamerImplTest.java
URL: 
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/ResourceStreamerImplTest.java?rev=991267&r1=991266&r2=991267&view=diff
==============================================================================
--- 
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/ResourceStreamerImplTest.java
 (original)
+++ 
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/ResourceStreamerImplTest.java
 Tue Aug 31 17:27:21 2010
@@ -1,4 +1,4 @@
-// Copyright 2007, 2008, 2009 The Apache Software Foundation
+// Copyright 2007, 2008, 2009, 2010 The Apache Software Foundation
 //
 // Licensed under the Apache License, Version 2.0 (the "License");
 // you may not use this file except in compliance with the License.
@@ -60,7 +60,7 @@ public class ResourceStreamerImplTest ex
 
         replay();
 
-        Response response = new ResponseImpl(hsResponse);
+        Response response = new ResponseImpl(hsRequest, hsResponse);
         ResourceStreamer streamer = getService(ResourceStreamer.class);
         RequestGlobals globals = getService(RequestGlobals.class);
 


Reply via email to