|
@ -0,0 +1,49 @@
|
|
|
package com.yihu.wlyy.interceptors;
|
|
|
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.aspectj.lang.ProceedingJoinPoint;
|
|
|
import org.aspectj.lang.annotation.Around;
|
|
|
import org.aspectj.lang.annotation.Aspect;
|
|
|
import org.aspectj.lang.annotation.Pointcut;
|
|
|
import org.json.JSONObject;
|
|
|
import org.springframework.http.ResponseEntity;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
import org.springframework.web.context.request.RequestContextHolder;
|
|
|
import org.springframework.web.context.request.ServletRequestAttributes;
|
|
|
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
import java.io.PrintWriter;
|
|
|
|
|
|
/**
|
|
|
* 由于用了@ResponseBody之后 拦截器返回值ModelAndView 是null 所以用线程变量解决
|
|
|
*/
|
|
|
@Aspect
|
|
|
@Component
|
|
|
public class GateWayAOP {
|
|
|
private ThreadLocal entityThreadLocal=new ThreadLocal();
|
|
|
//Controller层切点路径
|
|
|
@Pointcut("execution(* com.yihu.wlyy.web..*.*(..))")
|
|
|
public void controllerAspect() {
|
|
|
}
|
|
|
|
|
|
|
|
|
public GateWayAOP() {
|
|
|
//System.out.println("Observer---------------------------------------");
|
|
|
}
|
|
|
|
|
|
|
|
|
@Around("controllerAspect()")
|
|
|
public Object checkToken(ProceedingJoinPoint point) throws Throwable {
|
|
|
Object obj = null;
|
|
|
HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
|
|
|
try {
|
|
|
obj = point.proceed();
|
|
|
|
|
|
}catch (Exception e){
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
request.setAttribute("returnObj",obj);
|
|
|
return obj;
|
|
|
}
|
|
|
}
|