Recent Notes

Displaying keyword search results 1 - 6
Created by Dr. Xi on March 24, 2011 12:11:14    Last update: March 24, 2011 12:22:03
This is the task: your client wants to know how the web application is used. That is pretty easy. A plethora of commercial tools or any of the free log analysis tools such as analog and AWStats would fit the bill. But here's the catch: they want to know not only what pages are visited by how many people and when, but also who logged in and did what. Your application is using form based authentication and therefore, everyone is anonymous in the web access log. What to do? This is a servlet filter that generates a web access log with authenticated user info that can be fed to log analysis tools such as analog and AWStats . Filter code (the output format is Apache...
Created by Dr. Xi on November 23, 2010 20:20:01    Last update: March 01, 2011 13:38:51
I tried to find a GZIP compression servlet filter to compress a large log file that we send down to the browser. Most of the implementations I found were overly complicated and many buggy. This is a simple implementation that worked for me. The filter: package filter.demo; import*; i... Config web.xml : <filter> <filter-name>gzipFilter</filte... The ugly anonymous inner class could have been avoided if the servlet API did not insist on ServletResponse.getOutputStream returning the bogus ServletOutputStream class (instead of the plain OutputStream ). Additional Note: In an earlier version of this filter, the gzip headers were added in doFilter , like this: // This is NOT good! if (supportsGzip) { ... It turned out that the ServletResponse methods sendError bypasses the gzip...
Created by Dr. Xi on November 23, 2010 22:11:54    Last update: November 23, 2010 22:12:49
JavaDoc says that you can call getOutputStream or getWriter on ServletResponse , but you cannot call both. The second call will get IllegalStateException . So this works: import*; import javax.servlet.*; im... So does this: import*; import javax.servlet.*; im... But not this: import*; import javax.servlet.*; im... You can make the last servlet work if you insert a filter like this: import*; import javax.servlet.*; im... But depending on the underlying implementation, the order of the output strings may be undetermined.
Created by Dr. Xi on August 27, 2010 22:35:53    Last update: August 27, 2010 22:35:53
This example decompresses a gzip compressed file with . The input is assumed to be Base64 encoded after being gzipped (such would be the case when binary data is transmitted within an XML file). You don't need the Base64InputStream if the data is not Base64 encoded. import*; import
Created by Dr. Xi on August 24, 2010 21:59:22    Last update: August 24, 2010 21:59:22
This class decodes a Base64 encoded file with the Apache commons codec package: import*; import org.apache.commons.cod...
Created by Dr. Xi on June 03, 2010 22:43:43    Last update: June 20, 2010 14:13:05
Using the Sun BASE64Encoder : import*; import sun.misc.BASE64Encoder... However, the Sun encoder is awfully slow. The Apache encoder is a lot faster. Here's the code with Apache encoder: import*; import org.apache.commons.cod... Performance comparisons between Apache and Sun: C:\>bash bash-3.2$ time java EncodeFileWithBase...