Skip to content

Instantly share code, notes, and snippets.

@kencoba
Last active August 29, 2015 14:23
Show Gist options
  • Save kencoba/581c98c251ac66737049 to your computer and use it in GitHub Desktop.
Save kencoba/581c98c251ac66737049 to your computer and use it in GitHub Desktop.
Kitsunebi: Tomcat Debug Filter
package filters;
import java.io.IOException;
import java.util.Enumeration;
import java.util.logging.Logger;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
public class LogFilter implements Filter {
Logger logger = Logger.getLogger("com.kitsunebi");
@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException,
ServletException {
HttpServletRequest req = (HttpServletRequest) request;
logger.info("URI :" + req.getRequestURI());
logger.info("Method :" + req.getMethod());
Enumeration<String> paramNames = req.getParameterNames();
while (paramNames.hasMoreElements()) {
String key = paramNames.nextElement();
logger.info("Request parameter :" + key + " = " + req.getParameter(key));
}
Enumeration<String> attrNames = req.getAttributeNames();
while (attrNames.hasMoreElements()) {
String key = attrNames.nextElement();
logger.info("Request attribute :" + key + " = " + req.getAttribute(key));
}
HttpSession session = req.getSession(false);
if (session == null) {
logger.info("No HttpSession instance.");
} else {
Enumeration<String> sessAttrNames = session.getAttributeNames();
while (sessAttrNames.hasMoreElements()) {
String key = sessAttrNames.nextElement();
logger.info("Session attribute :" + key + " = " + session.getAttribute(key));
}
}
chain.doFilter(request, response);
}
@Override
public void destroy() {
}
@Override
public void init(FilterConfig arg0) throws ServletException {
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment