Created byDr. Xion 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 byDr. Xion 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 java.io.*; 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 byDr. Xion June 20, 2010 14:35:17
Last update: June 20, 2010 14:35:17

This XML signature validator comes from the Apache XML Security project. It validates the signature according to the core validation processing rules .
It does not verify that the key used to generate the signature is a trusted key. You can override the KeySelector class to make sure that the signing key is from a trusted store.
import javax.xml.crypto.*;
import javax.xml.cry...

Created byDr. Xion September 05, 2008 22:58:01
Last update: September 07, 2008 03:25:24

Java introduced annotations since JDK1.5. Annotations are used to decorate code and can be applied to declarations of classes, fields, methods, and other program elements. They are not part of the code per se, but frequently used to apply external logic to the code being annotated. An "Annotation Type" must accompany each type of annotation. For example, the following code will fail compilation: public class TestAnnotation { @deprecated ... Changing @deprecated to @Deprecated with an upper case D will fix the problem, since @Deprecated is a built in annotation type. There are three built in annotation types: @Deprecated , @Override , and @SuppressWarnings . This is an example of a user defined annotation (the file must be named Test.java ): import java.lang.annotation.*; /** * In......