Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
N
nouiWithSpringMVC
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
gechengyang
nouiWithSpringMVC
Commits
15e4af32
Commit
15e4af32
authored
Aug 18, 2020
by
WeiCong
Browse files
Options
Browse Files
Download
Plain Diff
Merge remote-tracking branch 'origin/master'
parents
0131a50b
a2939fb5
Show whitespace changes
Inline
Side-by-side
Showing
15 changed files
with
269 additions
and
72 deletions
+269
-72
pom.xml
pom.xml
+6
-5
NoUiVersion.java
...a/org/sss/presentation/noui/api/response/NoUiVersion.java
+14
-0
Result.java
...n/java/org/sss/presentation/noui/api/response/Result.java
+13
-2
ResultUtil.java
...va/org/sss/presentation/noui/api/response/ResultUtil.java
+4
-4
AbstractCommonController.java
...resentation/noui/controller/AbstractCommonController.java
+7
-2
LoginController.java
...org/sss/presentation/noui/controller/LoginController.java
+11
-4
FileTypeInterceptor.java
...org/sss/presentation/noui/filter/FileTypeInterceptor.java
+6
-1
OpenTransInterceptor.java
...a/org/sss/presentation/noui/jwt/OpenTransInterceptor.java
+7
-2
TokenInterceptor.java
.../java/org/sss/presentation/noui/jwt/TokenInterceptor.java
+11
-6
SqlLogAppender.java
...in/java/org/sss/presentation/noui/log/SqlLogAppender.java
+96
-0
LogAnnotation.java
...java/org/sss/presentation/noui/log/aop/LogAnnotation.java
+12
-0
LogAop.java
src/main/java/org/sss/presentation/noui/log/aop/LogAop.java
+39
-0
log4j.xml
src/main/resources/log4j.xml
+26
-21
log4j2.xml
src/main/resources/log4j2.xml
+0
-22
spring-mvc.xml
src/main/resources/spring-mvc.xml
+17
-3
No files found.
pom.xml
View file @
15e4af32
...
...
@@ -29,6 +29,12 @@
<dependencies>
<dependency>
<groupId>
org.aspectj
</groupId>
<artifactId>
aspectjweaver
</artifactId>
<version>
1.9.6
</version>
</dependency>
<dependency>
<groupId>
com.fasterxml.jackson.core
</groupId>
<artifactId>
jackson-databind
</artifactId>
<version>
2.9.4
</version>
...
...
@@ -140,11 +146,6 @@
<version>
2.5
</version>
</dependency>
<dependency>
<groupId>
commons-logging
</groupId>
<artifactId>
commons-logging
</artifactId>
<version>
1.2
</version>
</dependency>
<dependency>
<groupId>
commons-io
</groupId>
<artifactId>
commons-io
</artifactId>
<version>
2.5
</version>
...
...
src/main/java/org/sss/presentation/noui/api/response/NoUiVersion.java
0 → 100644
View file @
15e4af32
package
org
.
sss
.
presentation
.
noui
.
api
.
response
;
public
class
NoUiVersion
{
private
String
version
;
public
String
getVersion
()
{
return
version
;
}
public
void
setVersion
(
String
version
)
{
this
.
version
=
version
;
}
}
src/main/java/org/sss/presentation/noui/api/response/Result.java
View file @
15e4af32
...
...
@@ -9,19 +9,30 @@ public class Result {
private
Map
<
String
,
Object
>
error
;
// 错误信息
private
Map
<
String
,
Object
>
codetable
;
private
Object
data
;
private
String
verison
;
public
Result
(
String
retcod
,
String
retmsg
,
Object
data
)
{
public
String
getVerison
()
{
return
verison
;
}
public
void
setVerison
(
String
verison
)
{
this
.
verison
=
verison
;
}
public
Result
(
String
retcod
,
String
retmsg
,
Object
data
,
String
verison
)
{
this
.
retcod
=
retcod
;
this
.
retmsg
=
retmsg
;
this
.
data
=
data
;
this
.
verison
=
verison
;
}
public
Result
(
String
retcod
,
String
retmsg
,
Map
<
String
,
Object
>
error
,
Map
<
String
,
Object
>
codetable
,
Object
data
)
{
public
Result
(
String
retcod
,
String
retmsg
,
Map
<
String
,
Object
>
error
,
Map
<
String
,
Object
>
codetable
,
Object
data
,
String
verison
)
{
this
.
retcod
=
retcod
;
this
.
retmsg
=
retmsg
;
this
.
error
=
error
;
this
.
codetable
=
codetable
;
this
.
data
=
data
;
this
.
verison
=
verison
;
}
public
String
getRetcod
()
{
...
...
src/main/java/org/sss/presentation/noui/api/response/ResultUtil.java
View file @
15e4af32
...
...
@@ -4,11 +4,11 @@ import java.util.Map;
public
class
ResultUtil
{
public
static
Result
result
(
String
retcod
,
String
retmsg
,
Object
data
)
{
return
new
Result
(
retcod
,
retmsg
,
data
);
public
static
Result
result
(
String
retcod
,
String
retmsg
,
Object
data
,
String
version
)
{
return
new
Result
(
retcod
,
retmsg
,
data
,
version
);
}
public
static
Result
result
(
String
retcod
,
String
retmsg
,
Map
<
String
,
Object
>
data
,
Map
<
String
,
Object
>
error
,
Map
<
String
,
Object
>
codetable
)
{
return
new
Result
(
retcod
,
retmsg
,
error
,
codetable
,
data
);
public
static
Result
result
(
String
retcod
,
String
retmsg
,
Map
<
String
,
Object
>
data
,
Map
<
String
,
Object
>
error
,
Map
<
String
,
Object
>
codetable
,
String
version
)
{
return
new
Result
(
retcod
,
retmsg
,
error
,
codetable
,
data
,
version
);
}
}
src/main/java/org/sss/presentation/noui/controller/AbstractCommonController.java
View file @
15e4af32
...
...
@@ -10,6 +10,7 @@ import javax.servlet.http.HttpServletResponse;
import
org.apache.commons.io.IOUtils
;
import
org.apache.commons.lang.StringUtils
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.web.multipart.MultipartFile
;
import
org.sss.common.model.EventType
;
import
org.sss.common.model.IBaseObject
;
...
...
@@ -22,6 +23,7 @@ import org.sss.presentation.noui.api.exception.NoUiException;
import
org.sss.presentation.noui.api.model.Alias
;
import
org.sss.presentation.noui.api.request.NoUiRequest
;
import
org.sss.presentation.noui.api.response.ErrorCodes
;
import
org.sss.presentation.noui.api.response.NoUiVersion
;
import
org.sss.presentation.noui.api.response.Result
;
import
org.sss.presentation.noui.api.response.ResultUtil
;
import
org.sss.presentation.noui.common.Constants
;
...
...
@@ -45,6 +47,9 @@ public abstract class AbstractCommonController {
protected
static
String
ON_STREAM_UPLOAD
=
"ON_STREAM_UPLOAD"
;
protected
static
String
ON_STREAM_DOWNLOAD
=
"ON_STREAM_DOWNLOAD"
;
@Autowired
private
NoUiVersion
noUiVersion
;
public
String
getMainPanel
(){
return
""
;
}
...
...
@@ -134,10 +139,10 @@ public abstract class AbstractCommonController {
Map
<
String
,
Object
>
afterReturnData
=
handleReturnData
(
eventType
,
context
,
noUiRequest
,
alias
);
ret
=
ResultUtil
.
result
(
NoUiPresentationUtil
.
retCode
(
context
),
NoUiPresentationUtil
.
retMsg
(
context
),
afterReturnData
,
NoUiPresentationUtil
.
handleErrorReturnData
(
context
,
alias
),
NoUiPresentationUtil
.
handleCodeTableReturnData
(
context
,
alias
));
NoUiPresentationUtil
.
handleErrorReturnData
(
context
,
alias
),
NoUiPresentationUtil
.
handleCodeTableReturnData
(
context
,
alias
)
,
noUiVersion
.
getVersion
()
);
}
catch
(
Exception
e
)
{
log
.
error
(
"OnClick command error"
,
e
);
ret
=
ResultUtil
.
result
(
ErrorCodes
.
ERROR
,
"hander error"
,
e
.
getMessage
());
ret
=
ResultUtil
.
result
(
ErrorCodes
.
ERROR
,
"hander error"
,
e
.
getMessage
()
,
noUiVersion
.
getVersion
()
);
}
finally
{
if
(
context
!=
null
)
{
...
...
src/main/java/org/sss/presentation/noui/controller/LoginController.java
View file @
15e4af32
...
...
@@ -8,6 +8,7 @@ import javax.servlet.http.HttpSession;
import
log.Log
;
import
log.LogFactory
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Controller
;
import
org.springframework.web.bind.annotation.RequestBody
;
import
org.springframework.web.bind.annotation.RequestMapping
;
...
...
@@ -20,6 +21,7 @@ import org.sss.presentation.noui.api.model.Menu;
import
org.sss.presentation.noui.api.request.NoUiRequest
;
import
org.sss.presentation.noui.api.response.ErrorCode
;
import
org.sss.presentation.noui.api.response.ErrorCodes
;
import
org.sss.presentation.noui.api.response.NoUiVersion
;
import
org.sss.presentation.noui.api.response.ResultUtil
;
import
org.sss.presentation.noui.common.Constants
;
import
org.sss.presentation.noui.context.NoUiContext
;
...
...
@@ -27,6 +29,7 @@ import org.sss.presentation.noui.context.NoUiContextManager;
import
org.sss.presentation.noui.jwt.JWT
;
import
org.sss.presentation.noui.jwt.JwtLogin
;
import
org.sss.presentation.noui.jwt.RedisLoginInfo
;
import
org.sss.presentation.noui.log.aop.LogAnnotation
;
import
org.sss.presentation.noui.util.NoUiPresentationUtil
;
import
org.sss.presentation.noui.util.NumericUtil
;
import
org.sss.presentation.noui.util.RedisUtil
;
...
...
@@ -37,6 +40,10 @@ public class LoginController {
private
static
final
Log
log
=
LogFactory
.
getLog
(
LoginController
.
class
);
public
static
final
String
ERROR
=
"error"
;
@Autowired
private
NoUiVersion
noUiVersion
;
@LogAnnotation
@ResponseBody
@RequestMapping
(
value
=
"/login"
,
method
=
RequestMethod
.
POST
)
public
Object
login
(
@RequestBody
Map
<
String
,
Object
>
dataMap
,
HttpServletRequest
request
,
HttpSession
session
)
{
...
...
@@ -84,22 +91,22 @@ public class LoginController {
//解决初次登陆,超期限登陆
final
Object
o
=
map
.
get
(
ERROR
);
if
(
Objects
.
isNull
(
o
))
{
return
ResultUtil
.
result
(
ErrorCodes
.
SUCCESS
,
ErrorCodes
.
SUCCESS_INFO
,
retDatamap
);
return
ResultUtil
.
result
(
ErrorCodes
.
SUCCESS
,
ErrorCodes
.
SUCCESS_INFO
,
retDatamap
,
noUiVersion
.
getVersion
()
);
}
else
{
ErrorCode
errorCode
=
(
ErrorCode
)
o
;
log
.
error
(
errorCode
);
return
ResultUtil
.
result
(
errorCode
.
getCode
(),
errorCode
.
getMessage
(),
retDatamap
);
return
ResultUtil
.
result
(
errorCode
.
getCode
(),
errorCode
.
getMessage
(),
retDatamap
,
noUiVersion
.
getVersion
()
);
}
}
else
{
final
ErrorCode
errorCode
=
(
ErrorCode
)
map
.
get
(
ERROR
);
log
.
error
(
errorCode
);
return
ResultUtil
.
result
(
errorCode
.
getCode
(),
errorCode
.
getMessage
(),
null
);
return
ResultUtil
.
result
(
errorCode
.
getCode
(),
errorCode
.
getMessage
(),
null
,
noUiVersion
.
getVersion
()
);
}
}
catch
(
Exception
e
)
{
log
.
error
(
"Login command error"
,
e
);
//throw new NoUiException("Login command error", e);
// return ResultUtil.result(ErrorCodes.ERROR, "login failed with exception", null);
return
ResultUtil
.
result
(
ErrorCode
.
SYSTEM_ERROR
.
getCode
(),
ErrorCode
.
SYSTEM_ERROR
.
getMessage
(),
null
);
return
ResultUtil
.
result
(
ErrorCode
.
SYSTEM_ERROR
.
getCode
(),
ErrorCode
.
SYSTEM_ERROR
.
getMessage
(),
null
,
noUiVersion
.
getVersion
()
);
}
finally
{
if
(
context
!=
null
)
...
...
src/main/java/org/sss/presentation/noui/filter/FileTypeInterceptor.java
View file @
15e4af32
...
...
@@ -2,10 +2,12 @@ package org.sss.presentation.noui.filter;
import
com.google.gson.Gson
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.web.multipart.MultipartFile
;
import
org.springframework.web.multipart.MultipartHttpServletRequest
;
import
org.springframework.web.servlet.handler.HandlerInterceptorAdapter
;
import
org.sss.presentation.noui.api.response.ErrorCodes
;
import
org.sss.presentation.noui.api.response.NoUiVersion
;
import
org.sss.presentation.noui.api.response.Result
;
import
javax.servlet.http.HttpServletRequest
;
...
...
@@ -19,6 +21,9 @@ import java.util.Map;
*/
public
class
FileTypeInterceptor
extends
HandlerInterceptorAdapter
{
@Autowired
private
NoUiVersion
noUiVersion
;
private
String
type_list
;
@Override
...
...
@@ -39,7 +44,7 @@ public class FileTypeInterceptor extends HandlerInterceptorAdapter {
//限制文件类型,请求转发到原始请求页面,并携带错误提示信息
flag
=
false
;
response
.
setContentType
(
"application/json; charset=utf-8"
);
Result
result
=
new
Result
(
ErrorCodes
.
ERROR
,
"不支持的文件类型!"
,
null
);
Result
result
=
new
Result
(
ErrorCodes
.
ERROR
,
"不支持的文件类型!"
,
null
,
noUiVersion
.
getVersion
()
);
PrintWriter
out
=
response
.
getWriter
();
String
json
=
new
Gson
().
toJson
(
result
);
out
.
print
(
json
);
...
...
src/main/java/org/sss/presentation/noui/jwt/OpenTransInterceptor.java
View file @
15e4af32
...
...
@@ -6,10 +6,12 @@ import javax.servlet.http.HttpServletRequest;
import
javax.servlet.http.HttpServletResponse
;
import
org.apache.commons.lang.StringUtils
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.web.servlet.HandlerInterceptor
;
import
org.springframework.web.servlet.ModelAndView
;
import
org.sss.presentation.noui.api.request.NoUiRequest
;
import
org.sss.presentation.noui.api.response.ErrorCodes
;
import
org.sss.presentation.noui.api.response.NoUiVersion
;
import
org.sss.presentation.noui.api.response.Result
;
import
org.sss.presentation.noui.common.Constants
;
import
org.sss.presentation.noui.context.NoUiContextManager
;
...
...
@@ -27,6 +29,9 @@ import log.LogFactory;
public
class
OpenTransInterceptor
implements
HandlerInterceptor
{
protected
static
final
Log
log
=
LogFactory
.
getLog
(
OpenTransInterceptor
.
class
);
@Autowired
private
NoUiVersion
noUiVersion
;
public
void
afterCompletion
(
HttpServletRequest
request
,
HttpServletResponse
response
,
Object
handler
,
Exception
arg3
)
throws
Exception
{
}
...
...
@@ -62,7 +67,7 @@ public class OpenTransInterceptor implements HandlerInterceptor {
trnnam
=
url
.
substring
(
begpos
,
idx2
);
if
(
trnnam
==
null
)
{
Result
rt
=
new
Result
(
ErrorCodes
.
UNKNOEW_TRANS
,
"未知的交易"
,
null
);
Result
rt
=
new
Result
(
ErrorCodes
.
UNKNOEW_TRANS
,
"未知的交易"
,
null
,
noUiVersion
.
getVersion
()
);
responseMessage
(
response
,
response
.
getWriter
(),
rt
);
return
false
;
}
...
...
@@ -70,7 +75,7 @@ public class OpenTransInterceptor implements HandlerInterceptor {
log
.
debug
(
"开放访问交易名:"
+
trnnam
);
if
(!
NoUiContextManager
.
openTransactions
.
contains
(
trnnam
))
{
Result
rt
=
new
Result
(
ErrorCodes
.
FORBIDDEN_TRANS
,
"非法访问"
,
null
);
Result
rt
=
new
Result
(
ErrorCodes
.
FORBIDDEN_TRANS
,
"非法访问"
,
null
,
noUiVersion
.
getVersion
()
);
responseMessage
(
response
,
response
.
getWriter
(),
rt
);
return
false
;
}
...
...
src/main/java/org/sss/presentation/noui/jwt/TokenInterceptor.java
View file @
15e4af32
...
...
@@ -5,10 +5,12 @@ import java.io.PrintWriter;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletResponse
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.web.servlet.HandlerInterceptor
;
import
org.springframework.web.servlet.ModelAndView
;
import
org.sss.presentation.noui.api.request.NoUiRequest
;
import
org.sss.presentation.noui.api.response.ErrorCodes
;
import
org.sss.presentation.noui.api.response.NoUiVersion
;
import
org.sss.presentation.noui.api.response.Result
;
import
org.sss.presentation.noui.common.Constants
;
import
org.sss.presentation.noui.util.NumericUtil
;
...
...
@@ -19,6 +21,9 @@ import com.google.gson.Gson;
public
class
TokenInterceptor
implements
HandlerInterceptor
{
@Autowired
private
NoUiVersion
noUiVersion
;
public
void
afterCompletion
(
HttpServletRequest
request
,
HttpServletResponse
response
,
Object
handler
,
Exception
arg3
)
throws
Exception
{
}
...
...
@@ -35,14 +40,14 @@ public class TokenInterceptor implements HandlerInterceptor {
String
terminalType
=
noUiRequest
.
getTerminalType
();
// APP WEB
// token不存在
if
(
StringUtil
.
isEmpty
(
token
))
{
Result
rt
=
new
Result
(
ErrorCodes
.
LOGIN_TOKEN_ISNULL
,
"登录token不能为空"
,
null
);
Result
rt
=
new
Result
(
ErrorCodes
.
LOGIN_TOKEN_ISNULL
,
"登录token不能为空"
,
null
,
noUiVersion
.
getVersion
()
);
responseMessage
(
response
,
response
.
getWriter
(),
rt
);
return
false
;
}
// userId不存在
if
(
StringUtil
.
isEmpty
(
userId
))
{
Result
rt
=
new
Result
(
ErrorCodes
.
LOGIN_ID_ISNULL
,
"用户id不能为空"
,
null
);
Result
rt
=
new
Result
(
ErrorCodes
.
LOGIN_ID_ISNULL
,
"用户id不能为空"
,
null
,
noUiVersion
.
getVersion
()
);
responseMessage
(
response
,
response
.
getWriter
(),
rt
);
return
false
;
}
...
...
@@ -55,20 +60,20 @@ public class TokenInterceptor implements HandlerInterceptor {
JwtLogin
login
=
JWT
.
unsign
(
token
,
JwtLogin
.
class
);
if
(
login
==
null
||
(!
userId
.
equals
((
login
.
getUserId
()))))
{
Result
rt
=
new
Result
(
ErrorCodes
.
LOGIN_TOKEN_CHECKERROR
,
"用户token或ID验证不通过"
,
null
);
Result
rt
=
new
Result
(
ErrorCodes
.
LOGIN_TOKEN_CHECKERROR
,
"用户token或ID验证不通过"
,
null
,
noUiVersion
.
getVersion
()
);
responseMessage
(
response
,
response
.
getWriter
(),
rt
);
return
false
;
}
RedisLoginInfo
redisLoginInfo
=
(
RedisLoginInfo
)
RedisUtil
.
get
(
StringUtil
.
userUniqueId
(
noUiRequest
));
if
(
redisLoginInfo
==
null
)
{
Result
rt
=
new
Result
(
ErrorCodes
.
LOGIN_ERROR
,
"登陆异常"
,
null
);
Result
rt
=
new
Result
(
ErrorCodes
.
LOGIN_ERROR
,
"登陆异常"
,
null
,
noUiVersion
.
getVersion
()
);
responseMessage
(
response
,
response
.
getWriter
(),
rt
);
return
false
;
}
//验证token是否一致
if
(!
token
.
equals
(
redisLoginInfo
.
getToken
())){
Result
rt
=
new
Result
(
ErrorCodes
.
LOGIN_TOKEN_CHECKERROR
,
"token失效,该用户被强迫下线"
,
null
);
Result
rt
=
new
Result
(
ErrorCodes
.
LOGIN_TOKEN_CHECKERROR
,
"token失效,该用户被强迫下线"
,
null
,
noUiVersion
.
getVersion
()
);
responseMessage
(
response
,
response
.
getWriter
(),
rt
);
return
false
;
}
...
...
@@ -76,7 +81,7 @@ public class TokenInterceptor implements HandlerInterceptor {
if
(
System
.
currentTimeMillis
()
>
redisLoginInfo
.
getExpiredTime
())
{
Result
rt
=
new
Result
(
ErrorCodes
.
LOGIN_TIMEOUT
,
"会话超时,请重新登录。超时时间戳:"
+
redisLoginInfo
.
getExpiredTime
()+
",当前时间戳:"
+
System
.
currentTimeMillis
(),
null
);
",当前时间戳:"
+
System
.
currentTimeMillis
(),
null
,
noUiVersion
.
getVersion
()
);
responseMessage
(
response
,
response
.
getWriter
(),
rt
);
return
false
;
}
...
...
src/main/java/org/sss/presentation/noui/log/SqlLogAppender.java
0 → 100644
View file @
15e4af32
package
org
.
sss
.
presentation
.
noui
.
log
;
import
org.apache.log4j.AppenderSkeleton
;
import
org.apache.log4j.Layout
;
import
org.apache.log4j.MDC
;
import
org.apache.log4j.PatternLayout
;
import
org.apache.log4j.spi.LoggingEvent
;
import
org.sss.presentation.noui.common.Constants
;
import
org.sss.presentation.noui.log.aop.LogAop
;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.concurrent.ConcurrentHashMap
;
public
class
SqlLogAppender
extends
AppenderSkeleton
{
private
PatternLayout
patternLayout
;
// protected String pattern;
protected
static
Map
<
String
,
List
>
map
=
new
ConcurrentHashMap
();
public
Map
<
String
,
List
>
getMap
(){
return
map
;
}
// public String getPattern() {
// return pattern;
// }
//
// public void setPattern(String pattern) {
// this.pattern = pattern;
// }
public
PatternLayout
getPatternLayout
()
{
return
patternLayout
;
}
public
void
setPatternLayout
(
PatternLayout
patternLayout
)
{
this
.
patternLayout
=
patternLayout
;
}
@Override
protected
void
append
(
LoggingEvent
loggingEvent
)
{
String
message
=
this
.
subAppend
(
loggingEvent
);
String
thread_name
=
(
String
)
MDC
.
get
(
LogAop
.
THREAD_NAME
);
if
(
thread_name
==
null
)
return
;
if
(
map
.
containsKey
(
thread_name
)){
map
.
get
(
thread_name
).
add
(
message
);
}
else
{
List
list
=
new
ArrayList
();
list
.
add
(
message
);
map
.
put
(
thread_name
,
list
);
}
}
public
String
subAppend
(
LoggingEvent
event
)
{
// PatternLayout patternLayout = new PatternLayout();
// patternLayout.setConversionPattern(pattern);
// setLayout(patternLayout);
String
result
;
if
(
layout
==
null
){
result
=
event
.
getRenderedMessage
();
}
else
{
result
=
layout
.
format
(
event
);
StringBuffer
buffer
=
new
StringBuffer
(
result
);
if
(
layout
.
ignoresThrowable
())
{
String
[]
s
=
event
.
getThrowableStrRep
();
if
(
s
!=
null
)
{
int
len
=
s
.
length
;
for
(
int
i
=
0
;
i
<
len
;
++
i
)
{
buffer
.
append
(
s
[
i
]);
buffer
.
append
(
Layout
.
LINE_SEP
);
}
}
}
result
=
new
String
(
buffer
);
}
return
result
;
}
@Override
public
void
close
()
{
}
@Override
public
boolean
requiresLayout
()
{
return
false
;
}
}
src/main/java/org/sss/presentation/noui/log/aop/LogAnnotation.java
0 → 100644
View file @
15e4af32
package
org
.
sss
.
presentation
.
noui
.
log
.
aop
;
import
java.lang.annotation.*
;
/**
* Created by cjh on 2019/12/12 0012.
*/
@Target
(
ElementType
.
METHOD
)
@Retention
(
RetentionPolicy
.
RUNTIME
)
@Documented
public
@interface
LogAnnotation
{
}
src/main/java/org/sss/presentation/noui/log/aop/LogAop.java
0 → 100644
View file @
15e4af32
package
org
.
sss
.
presentation
.
noui
.
log
.
aop
;
import
org.apache.log4j.Logger
;
import
org.apache.log4j.MDC
;
import
org.aspectj.lang.JoinPoint
;
import
org.sss.presentation.noui.log.SqlLogAppender
;
import
java.util.List
;
import
java.util.Map
;
public
class
LogAop
{
public
final
static
String
THREAD_NAME
=
"thread_name"
;
public
void
before
(
JoinPoint
joinPoint
){
MDC
.
put
(
THREAD_NAME
,
Thread
.
currentThread
().
getName
());
}
public
void
after
(
JoinPoint
joinPoint
){
String
thread_name
=
(
String
)
MDC
.
get
(
THREAD_NAME
);
MDC
.
clear
();
//发送每笔交易的日志到MQ
SqlLogAppender
sqlLogAppender
=
(
SqlLogAppender
)
Logger
.
getRootLogger
().
getAppender
(
"SqlLog"
);
if
(
sqlLogAppender
!=
null
){
Map
<
String
,
List
>
map
=
sqlLogAppender
.
getMap
();
List
<
String
>
list
=
map
.
get
(
thread_name
);
StringBuffer
buffer
=
new
StringBuffer
();
if
(
list
!=
null
){
for
(
String
str:
list
){
buffer
.
append
(
str
);
}
}
map
.
remove
(
thread_name
);
}
}
}
src/main/resources/log4j.xml
View file @
15e4af32
...
...
@@ -2,44 +2,48 @@
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
<log4j:configuration
xmlns:log4j=
"http://jakarta.apache.org/log4j/"
debug=
"false"
>
<appender
name=
"FILE"
class=
"org.apache.log4j.DailyRollingFileAppender"
>
<param
name=
"Threshold"
value=
"ERROR"
/>
<param
name=
"Encoding"
value=
"UTF-8"
/>
<param
name=
"File"
value=
"../logs/eibs.log"
/>
<param
name=
"Append"
value=
"true"
/>
<param
name=
"DatePattern"
value=
"'.'yyyy-MM-dd"
/>
<param
name=
"Threshold"
value=
"ERROR"
/>
<param
name=
"Encoding"
value=
"UTF-8"
/>
<param
name=
"File"
value=
"../logs/eibs.log"
/>
<param
name=
"Append"
value=
"true"
/>
<param
name=
"DatePattern"
value=
"'.'yyyy-MM-dd"
/>
<layout
class=
"org.apache.log4j.PatternLayout"
>
<param
name=
"ConversionPattern"
value=
"%d %-5p [%c] (%t) %m%n"
/>
<param
name=
"ConversionPattern"
value=
"%d %-5p [%c] (%t) %m%n"
/>
</layout>
<filter
class=
"log.PatternFilter"
>
<param
name=
"Pattern"
value=
"org.sss.*"
/>
<param
name=
"AcceptOnMatch"
value=
"true"
/>
</filter>
</appender>
<appender
name=
"CONSOLE"
class=
"org.apache.log4j.ConsoleAppender"
>
<param
name=
"Threshold"
value=
"TRACE"
/>
<param
name=
"Threshold"
value=
"TRACE"
/>
<layout
class=
"org.apache.log4j.PatternLayout"
>
<param
name=
"ConversionPattern"
value=
"%d{ABSOLUTE} %-5p [%-10t][%c{1}] %m%n"
/>
<param
name=
"ConversionPattern"
value=
"%d{ABSOLUTE} %-5p [%-10t][%c{1}] %m%n"
/>
</layout>
<filter
class=
"org.apache.log4j.varia.LevelRangeFilter"
>
<param
name=
"LevelMax"
value=
"ERROR"
/>
<param
name=
"LevelMin"
value=
"TRACE"
/>
<param
name=
"LevelMax"
value=
"ERROR"
/>
<param
name=
"LevelMin"
value=
"TRACE"
/>
</filter>
</appender>
<appender
name=
"SqlLog"
class=
"org.sss.presentation.noui.log.SqlLogAppender"
>
<param
name=
"Threshold"
value=
"ERROR"
/>
<layout
class=
"org.apache.log4j.PatternLayout"
>
<param
name=
"ConversionPattern"
value=
"%d %-5p [%c] (%t) %m%n"
/>
</layout>
</appender>
<category
name=
"org.sss"
>
<priority
value=
"INFO"
/>
<priority
value=
"INFO"
/>
</category>
<category
name=
"org.hibernate"
>
<priority
value=
"ERROR"
/>
<priority
value=
"ERROR"
/>
</category>
<category
name=
"org.apache"
>
<priority
value=
"ERROR"
/>
<priority
value=
"ERROR"
/>
</category>
<category
name=
"com.opensymphony"
>
<priority
value=
"ERROR"
/>
<priority
value=
"ERROR"
/>
</category>
<root>
<level
value=
"WARN"
/>
<appender-ref
ref=
"CONSOLE"
/>
<appender-ref
ref=
"FILE"
/>
<level
value=
"WARN"
/>
<appender-ref
ref=
"CONSOLE"
/>
<appender-ref
ref=
"FILE"
/>
<appender-ref
ref=
"SqlLog"
/>
</root>
</log4j:configuration>
\ No newline at end of file
src/main/resources/log4j2.xml
deleted
100644 → 0
View file @
0131a50b
<?xml version="1.0" encoding="UTF-8"?>
<Configuration
status=
"INFO"
>
<Appenders>
<Console
name=
"Console"
target=
"SYSTEM_OUT"
>
<PatternLayout
pattern=
"%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n"
/>
</Console>
<File
name=
"File"
fileName=
"log/eibs-designer.log"
>
<PatternLayout
pattern=
"%d %-5p %C{2} [%t] %m%n"
/>
</File>
</Appenders>
<Loggers>
<Logger
name=
"org.sss"
level=
"DEBUG"
/>
<Logger
name=
"org.hibernate"
level=
"ERROR"
/>
<Logger
name=
"org.apache"
level=
"ERROR"
/>
<Logger
name=
"com.opensymphony"
level=
"ERROR"
/>
<Root
level=
"DEBUG"
>
<AppenderRef
ref=
"Console"
/>
<AppenderRef
ref=
"File"
/>
</Root>
</Loggers>
</Configuration>
\ No newline at end of file
src/main/resources/spring-mvc.xml
View file @
15e4af32
<?xml version="1.0" encoding="UTF-8"?>
<beans
xmlns=
"http://www.springframework.org/schema/beans"
xmlns:xsi=
"http://www.w3.org/2001/XMLSchema-instance"
xmlns:context=
"http://www.springframework.org/schema/context"
xmlns:mvc=
"http://www.springframework.org/schema/mvc"
xmlns:xsi=
"http://www.w3.org/2001/XMLSchema-instance"
xmlns:context=
"http://www.springframework.org/schema/context"
xmlns:mvc=
"http://www.springframework.org/schema/mvc"
xmlns:aop=
"http://www.springframework.org/schema/aop"
xsi:schemaLocation=
"http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd"
>
http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd
"
>
<mvc:annotation-driven
/>
...
...
@@ -41,6 +42,19 @@
<property
name=
"maxInMemorySize"
value=
"200000"
/>
</bean>
<bean
id=
"nouiVersion"
class=
"org.sss.presentation.noui.api.response.NoUiVersion"
>
<property
name=
"version"
value=
"V1.0.0"
/>
</bean>
<bean
id=
"logAop"
class=
"org.sss.presentation.noui.log.aop.LogAop"
/>
<aop:config>
<aop:aspect
id=
"handler"
ref=
"logAop"
>
<aop:pointcut
id=
"point"
expression=
"execution(* org.sss.presentation.noui.controller..*(..)) && @annotation(org.sss.presentation.noui.log.aop.LogAnnotation)"
/>
<aop:before
method=
"before"
pointcut-ref=
"point"
/>
<aop:after
method=
"after"
pointcut-ref=
"point"
/>
</aop:aspect>
</aop:config>
<!-- 配置自动扫描的包 -->
<context:component-scan
base-package=
"org.sss.presentation.noui.controller"
></context:component-scan>
...
...
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