Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
D
datax-cloud
Overview
Overview
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
黄营
datax-cloud
Commits
b82bf289
Commit
b82bf289
authored
Aug 21, 2020
by
yuwei
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
项目初始化
parent
8ae1cefd
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
88 additions
and
0 deletions
+88
-0
ApiLogAspect.java
...atax/service/data/market/mapping/config/ApiLogAspect.java
+88
-0
No files found.
datax-modules/data-market-service-parent/data-market-service-mapping/src/main/java/cn/datax/service/data/market/mapping/config/ApiLogAspect.java
0 → 100644
View file @
b82bf289
package
cn
.
datax
.
service
.
data
.
market
.
mapping
.
config
;
import
cn.datax.common.core.DataConstant
;
import
cn.datax.common.utils.IPUtil
;
import
cn.datax.common.utils.MD5Util
;
import
cn.datax.common.utils.RequestHolder
;
import
cn.datax.service.data.market.api.dto.ApiLogDto
;
import
cn.datax.service.data.market.mapping.async.AsyncTask
;
import
lombok.extern.slf4j.Slf4j
;
import
org.aspectj.lang.JoinPoint
;
import
org.aspectj.lang.ProceedingJoinPoint
;
import
org.aspectj.lang.annotation.AfterThrowing
;
import
org.aspectj.lang.annotation.Around
;
import
org.aspectj.lang.annotation.Aspect
;
import
org.aspectj.lang.annotation.Pointcut
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Component
;
import
javax.servlet.http.HttpServletRequest
;
import
java.time.LocalDateTime
;
@Slf4j
@Aspect
@Component
public
class
ApiLogAspect
{
@Autowired
private
AsyncTask
asyncTask
;
@Pointcut
(
"execution(* cn.datax.service.data.market.mapping.handler.RequestHandler.invoke(..))"
)
public
void
logPointCut
()
{}
/**
* 通知方法会将目标方法封装起来
*
* @param joinPoint 切点
*/
@Around
(
value
=
"logPointCut()"
)
public
Object
doAround
(
ProceedingJoinPoint
joinPoint
)
throws
Throwable
{
long
startTime
=
System
.
currentTimeMillis
();
Object
result
=
joinPoint
.
proceed
();
long
endTime
=
System
.
currentTimeMillis
();
ApiLogDto
log
=
getLog
();
log
.
setTime
(
endTime
-
startTime
);
handleLog
(
joinPoint
,
log
);
return
result
;
}
/**
* 通知方法会在目标方法抛出异常后执行
*
* @param joinPoint
* @param e
*/
@AfterThrowing
(
value
=
"logPointCut()"
,
throwing
=
"e"
)
public
void
doAfterThrowing
(
JoinPoint
joinPoint
,
Exception
e
)
{
ApiLogDto
log
=
getLog
();
log
.
setStatus
(
DataConstant
.
EnableState
.
DISABLE
.
getKey
());
log
.
setMsg
(
e
.
getMessage
());
handleLog
(
joinPoint
,
log
);
}
private
ApiLogDto
getLog
()
{
ApiLogDto
log
=
new
ApiLogDto
();
HttpServletRequest
request
=
RequestHolder
.
getHttpServletRequest
();
String
apiKey
=
request
.
getHeader
(
"api_key"
);
String
secretKey
=
request
.
getHeader
(
"secret_key"
);
MD5Util
mt
=
null
;
try
{
mt
=
MD5Util
.
getInstance
();
String
apiId
=
mt
.
decode
(
apiKey
);
String
userId
=
mt
.
decode
(
secretKey
);
log
.
setCallerId
(
userId
);
log
.
setApiId
(
apiId
);
}
catch
(
Exception
e
)
{}
String
uri
=
request
.
getRequestURI
();
log
.
setCallerUrl
(
uri
);
String
ipAddr
=
IPUtil
.
getIpAddr
(
request
);
log
.
setCallerIp
(
ipAddr
);
log
.
setCallerDate
(
LocalDateTime
.
now
());
log
.
setStatus
(
DataConstant
.
EnableState
.
ENABLE
.
getKey
());
return
log
;
}
protected
void
handleLog
(
final
JoinPoint
joinPoint
,
ApiLogDto
log
)
{
// asyncTask.doTask(log);
}
}
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