Do you want to know the request headers and other parameters for each of the HTTP requests coming into the application server? If yes, a Sniffer filter like the one show below can dump all the incoming parameters to be analyzed later. This for sure helps in debugging. Later this can be extended to dump only when you want to trace some bug or issue by adding a property switch that dumps this information. Further you can store this information to a file or database are required.
<!--break-->Snippet
- packagelivrona.servlets;
- importjava.io.IOException;
- importjava.util.Enumeration;
- importjavax.servlet.Filter;
- importjavax.servlet.FilterChain;
- importjavax.servlet.FilterConfig;
- importjavax.servlet.ServletException;
- importjavax.servlet.ServletRequest;
- importjavax.servlet.ServletResponse;
- importjavax.servlet.http.HttpServletRequest;
- publicfinalclass SniffFilter implements Filter {
- private FilterConfig filterConfig =null;
- publicvoid init(FilterConfig filterConfig)throws ServletException {
- this.filterConfig= filterConfig;
- }
- publicvoid destroy(){
- this.filterConfig=null;
- }
- publicvoid doFilter(
- ServletRequest request,
- ServletResponse response,
- FilterChain chain)
- throwsIOException, ServletException {
- if(filterConfig ==null)
- return;
- HttpServletRequest req =(HttpServletRequest) request;
- Enumeration e = req.getHeaderNames();
- while(e.hasMoreElements()){
- String headerName =(String) e.nextElement();
- System.out.println(headerName +"="+ req.getHeader(headerName));
- }
- System.out.println("RemoteHost = "+ req.getRemoteHost());
- chain.doFilter(request, response);
- }
- }