|
@@ -1,9 +1,7 @@
|
|
|
package com.persagy.aspects;
|
|
|
|
|
|
import cn.hutool.core.util.IdUtil;
|
|
|
-import cn.hutool.core.util.StrUtil;
|
|
|
-import com.persagy.dmp.common.context.AppContext;
|
|
|
-import com.persagy.dmp.common.helper.SpringHelper;
|
|
|
+import cn.hutool.extra.servlet.ServletUtil;
|
|
|
import com.persagy.dmp.common.model.response.CommonResult;
|
|
|
import com.persagy.utils.JacksonMapper;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
@@ -18,8 +16,6 @@ import org.springframework.web.multipart.MultipartFile;
|
|
|
import javax.servlet.ServletRequest;
|
|
|
import javax.servlet.ServletResponse;
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
-import java.net.InetAddress;
|
|
|
-import java.net.UnknownHostException;
|
|
|
import java.util.LinkedList;
|
|
|
import java.util.List;
|
|
|
|
|
@@ -100,7 +96,7 @@ public class RequestLogAspect {
|
|
|
private static LogData initFlag(HttpServletRequest request) {
|
|
|
LogData data = new LogData();
|
|
|
// 请求IP
|
|
|
- data.remoteIp = getIpAddr();
|
|
|
+ data.remoteIp = ServletUtil.getClientIP(request, null);
|
|
|
// 请求端口
|
|
|
data.remotePort = request.getRemotePort();
|
|
|
data.timestamp = System.currentTimeMillis();
|
|
@@ -113,42 +109,6 @@ public class RequestLogAspect {
|
|
|
return data;
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * Description:获取ip地址
|
|
|
- *
|
|
|
- * @return String
|
|
|
- * @author lijie
|
|
|
- * @since 2018年10月22日: 下午4:57:26
|
|
|
- * Update By lijie 2018年10月22日: 下午4:57:26
|
|
|
- */
|
|
|
- public static String getIpAddr() {
|
|
|
- HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
|
|
|
- String ip = request.getHeader("x-forwarded-for");
|
|
|
- if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
|
|
|
- ip = request.getHeader("Proxy-Client-IP");
|
|
|
- }
|
|
|
- if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
|
|
|
- ip = request.getHeader("WL-Proxy-Client-IP");
|
|
|
- }
|
|
|
- if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
|
|
|
- ip = request.getRemoteAddr();
|
|
|
- if (ip.equals("127.0.0.1")) {
|
|
|
- // 根据网卡取本机配置的IP
|
|
|
- try {
|
|
|
- ip = InetAddress.getLocalHost().getHostAddress();
|
|
|
- } catch (UnknownHostException e) {
|
|
|
- log.error("获取本机IP信息失败:", e);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- // 对于通过多个代理的情况,第一个IP为客户端真实IP,多个IP按照','分割
|
|
|
- if (ip != null && ip.length() > 15) {
|
|
|
- if (ip.indexOf(",") > 0) {
|
|
|
- ip = ip.substring(0, ip.indexOf(","));
|
|
|
- }
|
|
|
- }
|
|
|
- return ip;
|
|
|
- }
|
|
|
/***
|
|
|
* Description: 日志数据实体
|
|
|
* @author : lijie
|