aop:config
/aop:aspect
/aop:config
package com.paic.mercury.vigilant.aop;
import org.apache.commons.logging.Log;
import org.aspectj.lang.ProceedingJoinPoint;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.paic.mercury.vigilant.entity.UIResult;
import com.paic.mercury.vigilant.secure.ResourceUser;
import com.paic.mercury.vigilant.utils.ServletUtil;
public class ControllerTracer {
// implements AfterReturningAdvice {
private static Logger LOG = LoggerFactory.getLogger(ControllerTracer.class);
// @Override
// public void afterReturning(Object arg0, Method arg1, Object[] arg2,
// Object arg3) throws Throwable {
// System.out.println("通常情况下睡觉之前要脱衣服!");
// }
public Object doAround(ProceedingJoinPoint pjp) throws Throwable {
// System.out.println("通常情况下睡觉之前要脱衣服!");
Object retVal = pjp.proceed();
// System.out.println("log Ending method: "
// + pjp.getTarget().getClass().getName() + " . "
// + pjp.getSignature().getName());
//
//
//
// LOG.info("args:" + args);
// LOG.info("kind:" + pjp.getKind());
// LOG.info("source location:" + pjp.getSourceLocation());
// LOG.info("target:" + pjp.getTarget().toString());
//
//
// LOG.info("USER:"+);
// LOG.info("result:" + retVal.toString());
String userName = "NULL";
Object user = ServletUtil.getResourceUser();
if (user != null && user instanceof ResourceUser) {
userName = ((ResourceUser) user).getUsername();
}
StringBuffer sb = new StringBuffer();
sb.append("User(").append(userName).append(") invoke ")
.append(pjp.getTarget().getClass().getSimpleName()).append(".")
.append(pjp.getSignature().getName());
if (retVal instanceof UIResult) {
UIResult result = (UIResult) retVal;
if (!result.isFlag()) {
sb.append(" ERROR! code:").append(result.getErrorCode())
.append(" message:").append(result.getMessage());
}
}
LOG.info(sb.toString());
// if (LOG.isDebugEnabled()) {
Object[] args = pjp.getArgs();
// latest arg is request.
if (args != null && args.length > 1) {
LOG.info("PRINTING ARGS. ===================");
StringBuffer argSb = new StringBuffer();
for (int index = 0; index < args.length - 1; index++) {
Object arg = args[index];
if (arg != null) {
argSb.append("arg type:")
.append(args[index].getClass().getSimpleName())
.append(" value:").append(args[index] + "");
}
LOG.info(argSb.toString());
}
LOG.info("PRINTING ARGS END. ==============");
}
// }
return retVal;
}
// @Override
// public void before(Method arg0, Object[] arg1, Object arg2)
// throws Throwable {
// System.out.println("起床后要先穿衣服!");
// }
}