rajjaiswalsaumya / webutilities

Automatically exported from code.google.com/p/webutilities
0 stars 0 forks source link

ResponseCacheFilter returns StatusCode 0 when original filter calls no setStatus() or sendError() methods #35

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. chain the filters so that ResponseCacheFilter caches other filter result, 
e.g. css files, but calls no response.setStatus() or sendError() methods
2. call the css url
3. servlet container returns following:
HTTP/1.1 0 
Server: Apache-Coyote/1.1
Set-Cookie: JSESSIONID=0D44FA697E1B2A6B8EA58F1C2602096F; Path=/te-pes1
Content-Type: text/css;charset=utf-8
Content-Length: 6560
Date: Wed, 21 Mar 2012 10:41:53 GMT
Connection: keep-alive

What is the expected output? What do you see instead?
expected output is:
HTTP/1.1 200 OK
Server: Apache-Coyote/1.1
Set-Cookie: JSESSIONID=9BEF591C136F8D7B1787EA4508E84821; Path=/te-pes1
Content-Type: text/css;charset=utf-8
Content-Length: 6560
Date: Wed, 21 Mar 2012 10:50:16 GMT
Connection: keep-alive

What version of the product are you using? On what operating system?
0.0.5, but same problem occurs on HEAD

Please provide any additional information below.
The problem is that filters must not call any setStatus() or sendError() 
methods and it is still 200 OK. WebUtilitiesResponseWrapper sets status to the 
value of zero on it'c creation and in fill() method it sets this code even if 
the setStatus() was not called, thus calls setStatus(0) - on every copy of the 
result from cache. Most modern browsers accept this (i.e. accepts HTTP/1.1 0), 
but not all - e.g. apache-JK-tomcat bridge fails and returns 500 ISE status 
code, so the ResponseCacheFilter is not usable for Apache-infrontOf-Tomcat 
setup.

can be solved following way:

diff --git 
a/src/main/java/com/googlecode/webutilities/common/WebUtilitiesResponseWrapper.j
ava b/src/main/java/com/googlecode/webutilities/common/WebUtilitiesRespon
index e5573ab..67df857 100644
--- 
a/src/main/java/com/googlecode/webutilities/common/WebUtilitiesResponseWrapper.j
ava
+++ 
b/src/main/java/com/googlecode/webutilities/common/WebUtilitiesResponseWrapper.j
ava
@@ -238,7 +238,9 @@ public class WebUtilitiesResponseWrapper extends 
HttpServletResponseWrapper {
                 response.setHeader(headerName, value.toString());
             }
         }
-        response.setStatus(this.getStatus());
+               if (this.getStatus() > 0)
+                       response.setStatus(this.getStatus());
+
         this.flushWriter();
         try {
             response.getOutputStream().write(this.getBytes());

Original issue reported on code.google.com by jindrich...@gmail.com on 21 Mar 2012 at 12:16

GoogleCodeExporter commented 8 years ago
OS: Linux- debian/stable (squeeze), kernel 2.6.32-5-xen-amd64

java version "1.6.0_26"
Java(TM) SE Runtime Environment (build 1.6.0_26-b03)
Java HotSpot(TM) 64-Bit Server VM (build 20.1-b02, mixed mode)

Original comment by jindrich...@gmail.com on 21 Mar 2012 at 12:22

GoogleCodeExporter commented 8 years ago
Thanks for findings and also for proposing possible fix. 

Original comment by rr.patil...@gmail.com on 21 Mar 2012 at 5:20

GoogleCodeExporter commented 8 years ago
Pull request merged - https://github.com/rpatil26/webutilities/pull/4

Original comment by rr.patil...@gmail.com on 4 Apr 2012 at 2:44