Tuesday, March 17, 2015

Honouring Terry Pratchett: Java Web Application

This Blogs name is Grumpy Apache. These days, there are excellent reasons, for being grumpy: After all, my favourite author Terry Pratchett has died, way too early. But, as Terry wrote in Going Postal about John Dearheart:

His name, however, continues to be sent in the so-called Overhead of the clacks. The full message is "GNU John Dearheart", where the G means, that the message should be passed on, the N means "Not Logged" and the U that it should be turned around at the end of the line. So as the name "John Dearheart" keeps going up and down the line, this tradition applies a kind of immortality as "a man is not dead while his name is still spoken".
This means, we'll be celebrating "Being childish day" today, by adding the HTTP Header

      X-Clacks-Overhead: GNU Terry Pratchett

to our web sites. And, here's how to do that with any Java Web Application.

Its simple. First of all, you'll be adding this class to your web application. It is a so-called servlet filter. I'll quote the relevant method here:

public void doFilter(ServletRequest pReq, ServletResponse pRes,
                                         FilterChain pChain) throws IOException,
ServletException {
if (pRes instanceof HttpServletResponse) {
final HttpServletResponse res = (HttpServletResponse) pRes;
res.addHeader("X-Clacks-Overhead", "GNU-Terry-Pratchett");
}
pChain.doFilter(pReq, pRes);
}
Besides, add the following snippets to your web.xml:

 
    ClacksOverheadFilter
    com.github.jochenw.clacksov.ClacksOverheadFilter
 

 
    ClacksOverheadFilter
    *
 
And, that's it! No modification of servlets, or the like, just a simple addition, that you can make to any web application.

Keep in mind:

As long as we are shifting his name on the Internet, Terry isn't dead.