dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #35989
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 18431: bugfix for AppCacheFilter, uses HttpServletResponseWrapper to allow for modified response
------------------------------------------------------------
revno: 18431
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Thu 2015-02-26 21:32:40 +0700
message:
bugfix for AppCacheFilter, uses HttpServletResponseWrapper to allow for modified response
modified:
dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/servlet/filter/AppCacheFilter.java
--
lp:dhis2
https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk
Your team DHIS 2 developers is subscribed to branch lp:dhis2.
To unsubscribe from this branch go to https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk/+edit-subscription
=== modified file 'dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/servlet/filter/AppCacheFilter.java'
--- dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/servlet/filter/AppCacheFilter.java 2015-02-26 08:12:03 +0000
+++ dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/servlet/filter/AppCacheFilter.java 2015-02-26 14:32:40 +0000
@@ -41,7 +41,10 @@
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
+import javax.servlet.http.HttpServletResponseWrapper;
+import java.io.CharArrayWriter;
import java.io.IOException;
+import java.io.PrintWriter;
/**
* @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
@@ -62,13 +65,17 @@
HttpServletRequest request = (HttpServletRequest) req;
HttpServletResponse response = (HttpServletResponse) res;
- chain.doFilter( request, response );
+ PrintWriter writer = response.getWriter();
+ CharResponseWrapper responseWrapper = new CharResponseWrapper( response );
+
+ chain.doFilter( request, responseWrapper );
SystemInfo systemInfo = systemService.getSystemInfo();
- response.getOutputStream().println( "# User: " + currentUserService.getCurrentUsername() );
- response.getOutputStream().println( "# Revision: " + systemInfo.getRevision() );
- response.getOutputStream().println( "# Calendar: " + systemInfo.getCalendar() );
+ writer.print( responseWrapper.toString() );
+ writer.println( "# User: " + currentUserService.getCurrentUsername() );
+ writer.println( "# Revision: " + systemInfo.getRevision() );
+ writer.println( "# Calendar: " + systemInfo.getCalendar() );
}
}
@@ -82,3 +89,25 @@
{
}
}
+
+class CharResponseWrapper extends HttpServletResponseWrapper
+{
+ private CharArrayWriter output;
+
+ public String toString()
+ {
+ return output.toString();
+ }
+
+ public CharResponseWrapper( HttpServletResponse response )
+ {
+ super( response );
+ output = new CharArrayWriter();
+ }
+
+ @Override
+ public PrintWriter getWriter()
+ {
+ return new PrintWriter( output );
+ }
+}