Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
S
shop
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
曲欣亮
shop
Commits
5fe8b35b
Commit
5fe8b35b
authored
Oct 19, 2023
by
张永
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
1
parent
34e15bb1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
60 additions
and
1 deletion
+60
-1
IDCSystemLogAspect.java
...a/com/egolm/shop/common/component/IDCSystemLogAspect.java
+1
-1
ShopUtil.java
src/main/java/com/egolm/shop/common/utils/ShopUtil.java
+59
-0
No files found.
src/main/java/com/egolm/shop/common/component/IDCSystemLogAspect.java
View file @
5fe8b35b
...
...
@@ -98,7 +98,7 @@ public class IDCSystemLogAspect {
if
(
request
!=
null
)
{
log
.
setsUserAgent
(
request
.
getHeader
(
HttpHeaders
.
USER_AGENT
));
log
.
setsHttpMethod
(
request
.
getMethod
());
log
.
setsIp
(
request
.
getRemoteAddr
(
));
log
.
setsIp
(
ShopUtil
.
getIpAddress
(
request
));
log
.
setsRequestText
(
GsonUtil
.
toJson
(
ShopUtil
.
getParameterMap
(
request
)));
}
...
...
src/main/java/com/egolm/shop/common/utils/ShopUtil.java
View file @
5fe8b35b
...
...
@@ -7,7 +7,13 @@ import java.util.Map.Entry;
import
javax.servlet.http.HttpServletRequest
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
public
class
ShopUtil
{
private
static
final
Logger
logger
=
LoggerFactory
.
getLogger
(
ShopUtil
.
class
);
public
static
Map
<
String
,
Object
>
getParameterMap
(
HttpServletRequest
request
)
{
// 参数Map
Map
<
String
,
String
[]>
properties
=
request
.
getParameterMap
();
...
...
@@ -36,5 +42,58 @@ public class ShopUtil {
}
return
returnMap
;
}
public
static
String
getIpAddress
(
HttpServletRequest
request
)
{
//注意本地测试时,浏览器请求不要用localhost,要用本机IP访问项目地址,不然这里取不到ip
// 获取请求主机IP地址,如果通过代理进来,则透过防火墙获取真实IP地址
String
ip
=
request
.
getHeader
(
"X-Forwarded-For"
);
if
(
logger
.
isInfoEnabled
())
{
logger
.
info
(
"getIpAddress(HttpServletRequest) - X-Forwarded-For - String ip="
+
ip
);
}
if
(
ip
==
null
||
ip
.
length
()
==
0
||
"unknown"
.
equalsIgnoreCase
(
ip
))
{
if
(
ip
==
null
||
ip
.
length
()
==
0
||
"unknown"
.
equalsIgnoreCase
(
ip
))
{
ip
=
request
.
getHeader
(
"Proxy-Client-IP"
);
if
(
logger
.
isInfoEnabled
())
{
logger
.
info
(
"getIpAddress(HttpServletRequest) - Proxy-Client-IP - String ip="
+
ip
);
}
}
if
(
ip
==
null
||
ip
.
length
()
==
0
||
"unknown"
.
equalsIgnoreCase
(
ip
))
{
ip
=
request
.
getHeader
(
"WL-Proxy-Client-IP"
);
if
(
logger
.
isInfoEnabled
())
{
logger
.
info
(
"getIpAddress(HttpServletRequest) - WL-Proxy-Client-IP - String ip="
+
ip
);
}
}
if
(
ip
==
null
||
ip
.
length
()
==
0
||
"unknown"
.
equalsIgnoreCase
(
ip
))
{
ip
=
request
.
getHeader
(
"HTTP_CLIENT_IP"
);
if
(
logger
.
isInfoEnabled
())
{
logger
.
info
(
"getIpAddress(HttpServletRequest) - HTTP_CLIENT_IP - String ip="
+
ip
);
}
}
if
(
ip
==
null
||
ip
.
length
()
==
0
||
"unknown"
.
equalsIgnoreCase
(
ip
))
{
ip
=
request
.
getHeader
(
"HTTP_X_FORWARDED_FOR"
);
if
(
logger
.
isInfoEnabled
())
{
logger
.
info
(
"getIpAddress(HttpServletRequest) - HTTP_X_FORWARDED_FOR - String ip="
+
ip
);
}
}
if
(
ip
==
null
||
ip
.
length
()
==
0
||
"unknown"
.
equalsIgnoreCase
(
ip
))
{
ip
=
request
.
getRemoteAddr
();
if
(
logger
.
isInfoEnabled
())
{
logger
.
info
(
"getIpAddress(HttpServletRequest) - getRemoteAddr - String ip="
+
ip
);
}
}
}
else
if
(
ip
.
length
()
>
15
)
{
String
[]
ips
=
ip
.
split
(
","
);
for
(
int
index
=
0
;
index
<
ips
.
length
;
index
++)
{
String
strIp
=
(
String
)
ips
[
index
];
if
(!(
"unknown"
.
equalsIgnoreCase
(
strIp
)))
{
ip
=
strIp
;
break
;
}
}
}
return
ip
;
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment