package com.yeshi.fanli.aspect;
|
|
import java.util.Iterator;
|
import java.util.Map;
|
|
import javax.servlet.http.HttpServletRequest;
|
|
import org.aspectj.lang.ProceedingJoinPoint;
|
import org.aspectj.lang.annotation.Around;
|
import org.aspectj.lang.annotation.Aspect;
|
import org.springframework.stereotype.Component;
|
import org.springframework.web.context.request.RequestContextHolder;
|
import org.springframework.web.context.request.ServletRequestAttributes;
|
|
import com.yeshi.fanli.log.LogHelper;
|
|
import net.sf.json.JSONObject;
|
|
@Component
|
@Aspect
|
public class ErrorAspect {
|
public static final String EDP = "execution(* com.yeshi.fanli.controller.ClientJspController.*(..))";
|
|
@Around(EDP)
|
public Object testAround(ProceedingJoinPoint joinPoint) {
|
ServletRequestAttributes servletContainer = (ServletRequestAttributes) RequestContextHolder
|
.getRequestAttributes();
|
HttpServletRequest request = servletContainer.getRequest();
|
Object[] args = joinPoint.getArgs();
|
Object obj = null;
|
try {
|
obj = joinPoint.proceed(args);
|
} catch (Throwable e) {
|
|
LogHelper.errorDetailInfo(e, getHttpServletParams(request), request.getRequestURI().toString());
|
|
}
|
|
return obj;
|
}
|
|
private String getHttpServletParams(HttpServletRequest request) {
|
if (request == null) {
|
return "";
|
}
|
Map map = request.getParameterMap();
|
if (map != null) {
|
Iterator<String> its = map.keySet().iterator();
|
JSONObject json = new JSONObject();
|
while (its.hasNext()) {
|
String next = its.next();
|
if (map.get(next) != null) {
|
Object[] objects = (Object[]) map.get(next);
|
if (objects != null && objects.length > 0) {
|
json.put(next, objects[0].toString());
|
}
|
}
|
}
|
return json.toString();
|
}
|
return "";
|
}
|
|
}
|