|
|
|
@@ -0,0 +1,52 @@ |
|
|
|
package com.iformall.interceptor; |
|
|
|
|
|
|
|
import javax.servlet.http.HttpServletRequest; |
|
|
|
|
|
|
|
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.springframework.context.annotation.Configuration; |
|
|
|
import org.springframework.web.context.request.RequestAttributes; |
|
|
|
import org.springframework.web.context.request.RequestContextHolder; |
|
|
|
import org.springframework.web.context.request.ServletRequestAttributes; |
|
|
|
|
|
|
|
import com.alibaba.fastjson.JSON; |
|
|
|
|
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
* 测试所有controler请求返回信息输出 |
|
|
|
* @author alascor |
|
|
|
* |
|
|
|
*/ |
|
|
|
@Aspect |
|
|
|
@Configuration |
|
|
|
@Slf4j |
|
|
|
public class TestControllerReturnAspect { |
|
|
|
|
|
|
|
|
|
|
|
@Pointcut("execution(* com.iformall.controller.*Controller.*(..))") |
|
|
|
public void excudeService() { |
|
|
|
} |
|
|
|
|
|
|
|
@Around("excudeService()") |
|
|
|
public Object doAround(ProceedingJoinPoint pjp) throws Throwable { |
|
|
|
RequestAttributes ra = RequestContextHolder.getRequestAttributes(); |
|
|
|
ServletRequestAttributes sra = (ServletRequestAttributes) ra; |
|
|
|
HttpServletRequest request = sra.getRequest(); |
|
|
|
|
|
|
|
String method = request.getMethod(); |
|
|
|
String uri = request.getRequestURI(); |
|
|
|
String paraString = JSON.toJSONString(request.getParameterMap()); |
|
|
|
log.info("***************************************************"); |
|
|
|
log.info("请求开始, URI: {}, method: {}, params: {}", uri, method, paraString); |
|
|
|
|
|
|
|
// result的值就是被拦截方法的返回值 |
|
|
|
Object result = pjp.proceed(); |
|
|
|
log.info("请求结束,controller的返回值是 " + JSON.toJSONString(result)); |
|
|
|
return result; |
|
|
|
} |
|
|
|
|
|
|
|
} |