|
|
|
@@ -1,5 +1,8 @@ |
|
|
|
package com.iformall.interceptor; |
|
|
|
|
|
|
|
import java.io.BufferedReader; |
|
|
|
import java.io.IOException; |
|
|
|
|
|
|
|
import javax.servlet.http.HttpServletRequest; |
|
|
|
|
|
|
|
import org.aspectj.lang.ProceedingJoinPoint; |
|
|
|
@@ -40,13 +43,29 @@ public class TestControllerReturnAspect { |
|
|
|
String method = request.getMethod(); |
|
|
|
String uri = request.getRequestURI(); |
|
|
|
String paraString = JSON.toJSONString(request.getParameterMap()); |
|
|
|
log.info("***************************************************"); |
|
|
|
log.info("请求开始, URI: {}, method: {}, params: {}", uri, method, paraString); |
|
|
|
String requestBody = getBodyRequest(request); |
|
|
|
//log.info("***************************************************"); |
|
|
|
//log.info("请求开始, URI: {}, method: {}, params: {}", uri, method, paraString); |
|
|
|
|
|
|
|
// result的值就是被拦截方法的返回值 |
|
|
|
Object result = pjp.proceed(); |
|
|
|
log.info("请求结束,controller的返回值是 " + JSON.toJSONString(result)); |
|
|
|
log.info("请求结束,URI: {}, method: {}, params: {},requestBody:{}. 返回值:{} " ,uri, method, paraString,requestBody, JSON.toJSONString(result)); |
|
|
|
return result; |
|
|
|
} |
|
|
|
|
|
|
|
private String getBodyRequest(HttpServletRequest request) throws IOException { |
|
|
|
// 直接从HttpServletRequest的Reader流中获取RequestBody |
|
|
|
BufferedReader reader = request.getReader(); |
|
|
|
StringBuilder builder = new StringBuilder(); |
|
|
|
String line = reader.readLine(); |
|
|
|
while(line != null){ |
|
|
|
builder.append(line); |
|
|
|
line = reader.readLine(); |
|
|
|
} |
|
|
|
reader.close(); |
|
|
|
|
|
|
|
String reqBody = builder.toString(); |
|
|
|
return reqBody; |
|
|
|
} |
|
|
|
|
|
|
|
} |