/** * Optionally logs out the ending request attributes and session for the first {@link * HttpServletRequest} argument to the method. */ public void traceAfter(JoinPoint jp, Object retVal) { if (!logger.isDebugEnabled()) return; Log logger = LoggerHelper.getLogger(jp.getStaticPart().getSignature().getDeclaringType()); if (logger.isDebugEnabled()) { HttpServletRequest req = findRequest(jp); if (req == null) return; if (logger.isTraceEnabled()) logRequestAttributes(req, logger); if (logger.isDebugEnabled()) logSessionAttributes(req, logger); } }
/** * Helper to log out the request attributes at trace level * * @param req The request * @param logger The logger */ @SuppressWarnings("unchecked") private void logRequestAttributes(HttpServletRequest req, Log logger) { StringBuilder buf = new StringBuilder(); buf.append("Request Attributes: "); buf.append("\n\t**** Request Attributes ****"); Enumeration e = req.getAttributeNames(); while (e.hasMoreElements()) { String k = (String) e.nextElement(); buf.append("\n\t").append(k).append("=").append(LoggerHelper.getValue(req.getAttribute(k))); } buf.append("\n\t**** End Request Attrobites ****"); logger.trace(buf.toString()); }
/** * Helper to log out the session attributes at debug level * * @param req The request * @param logger The logger */ @SuppressWarnings("unchecked") private void logSessionAttributes(HttpServletRequest req, Log logger) { HttpSession session = req.getSession(false); if (session == null) return; StringBuilder buf = new StringBuilder(); buf.append("Session Contents: "); buf.append("\n\t**** Session Contents ****"); Enumeration e = session.getAttributeNames(); while (e.hasMoreElements()) { String k = (String) e.nextElement(); buf.append("\n\t") .append(k) .append("=") .append(LoggerHelper.getValue(session.getAttribute(k))); } buf.append("\n\t**** End Session Contents ****"); logger.debug(buf.toString()); }