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
de7369bb
Commit
de7369bb
authored
Feb 02, 2021
by
fukai
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
补充异常日志记录
parent
43d217c9
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
109 additions
and
1 deletions
+109
-1
NoUiPresentation.java
...a/org/sss/presentation/noui/context/NoUiPresentation.java
+7
-0
TxInfo.java
src/main/java/org/sss/presentation/noui/context/TxInfo.java
+87
-0
AbstractCommonController.java
...resentation/noui/controller/AbstractCommonController.java
+15
-1
No files found.
src/main/java/org/sss/presentation/noui/context/NoUiPresentation.java
View file @
de7369bb
...
...
@@ -213,6 +213,13 @@ public class NoUiPresentation extends AbstractNullPresentation {
public
boolean
message
(
MessageType
paramMessageType
,
String
paramString
,
Object
paramObject
)
throws
ContainerException
{
if
(
paramMessageType
.
equals
(
MessageType
.
ERROR
)
&&
(
paramObject
instanceof
Throwable
))
{
//记录异常日志
TxInfo
.
recordException
((
Throwable
)
paramObject
);
}
String
str1
=
""
;
try
{
if
((
paramObject
instanceof
String
))
{
...
...
src/main/java/org/sss/presentation/noui/context/TxInfo.java
0 → 100644
View file @
de7369bb
package
org
.
sss
.
presentation
.
noui
.
context
;
import
log.Log
;
import
log.LogFactory
;
import
org.apache.commons.io.IOUtils
;
import
org.hibernate.SQLQuery
;
import
org.hibernate.Session
;
import
org.hibernate.Transaction
;
import
org.hibernate.engine.spi.SessionImplementor
;
import
org.sss.module.hibernate.HibernateUtils
;
import
org.sss.module.pojo.DatabaseUtils
;
import
java.io.ByteArrayOutputStream
;
import
java.io.PrintStream
;
import
java.util.Date
;
import
java.util.Optional
;
import
java.util.stream.Stream
;
public
class
TxInfo
{
protected
static
final
Log
log
=
LogFactory
.
getLog
(
TxInfo
.
class
);
public
static
ThreadLocal
<
TxInfo
>
txInfoHolder
=
new
ThreadLocal
<>();
public
String
txCode
;
public
String
url
;
public
String
target
;
public
static
void
putTxInfo
(
String
txCode
,
String
url
,
String
target
)
{
TxInfo
txInfo
=
new
TxInfo
();
txInfo
.
txCode
=
txCode
;
txInfo
.
url
=
url
;
txInfo
.
target
=
target
;
txInfoHolder
.
set
(
txInfo
);
}
public
static
TxInfo
getTxInfo
()
{
return
txInfoHolder
.
get
();
}
public
static
void
releaseCurrTxInfo
()
{
txInfoHolder
.
remove
();
}
/**
* 记录异常信息
* @param e
*/
public
static
void
recordException
(
Throwable
e
)
{
TxInfo
txInfo
=
getTxInfo
();
Session
session
=
HibernateUtils
.
openSession
(
null
);
long
count
=
DatabaseUtils
.
executeCounter
(((
SessionImplementor
)
session
).
connection
(),
"dealog"
);
String
inr
=
String
.
format
(
"%08d"
,
count
);
Transaction
transaction
=
session
.
beginTransaction
();
SQLQuery
sqlQuery
=
session
.
createSQLQuery
(
"insert into dealog(INR,CREDATTIM,SRVCOD,SRVNAM,INIFRM,RTNMSG,LOGLEV) values(?,?,?,?,?,?,?)"
);
sqlQuery
.
setString
(
0
,
inr
);
sqlQuery
.
setTimestamp
(
1
,
new
Date
());
String
srvcod
=
txInfo
.
url
.
replace
(
"/_"
,
"-"
);
sqlQuery
.
setString
(
2
,
srvcod
);
sqlQuery
.
setString
(
3
,
srvcod
);
sqlQuery
.
setString
(
4
,
txInfo
.
txCode
);
sqlQuery
.
setString
(
5
,
genMessage
(
e
));
sqlQuery
.
setString
(
6
,
"error"
);
sqlQuery
.
executeUpdate
();
transaction
.
commit
();
session
.
close
();
log
.
debug
(
"完成异常日志记录"
);
}
private
static
String
genMessage
(
Throwable
e
)
{
while
(
e
.
getCause
()
!=
null
)
e
=
e
.
getCause
();
ByteArrayOutputStream
bos
=
new
ByteArrayOutputStream
();
PrintStream
ps
=
new
PrintStream
(
bos
);
e
.
printStackTrace
(
ps
);
String
mesg
=
bos
.
toString
();
IOUtils
.
closeQuietly
(
ps
);
IOUtils
.
closeQuietly
(
bos
);
String
[]
lines
=
mesg
.
split
(
"[\r\n]{1,2}"
);
Optional
<
String
>
rs
=
Stream
.
of
(
lines
).
filter
(
str
->{
return
str
.
charAt
(
0
)
!=
'\t'
||
(
str
.
indexOf
(
"brilliance"
)>
0
||
str
.
indexOf
(
".noui."
)>
0
);
}).
reduce
((
acc
,
item
)->{
return
acc
+
'\n'
+
item
;
});
return
rs
.
get
();
}
}
src/main/java/org/sss/presentation/noui/controller/AbstractCommonController.java
View file @
de7369bb
...
...
@@ -19,6 +19,7 @@ import org.sss.presentation.noui.common.Constants;
import
org.sss.presentation.noui.context.NoUiContext
;
import
org.sss.presentation.noui.context.NoUiContextManager
;
import
org.sss.presentation.noui.context.NoUiPresentation
;
import
org.sss.presentation.noui.context.TxInfo
;
import
org.sss.presentation.noui.jwt.RedisLoginInfo
;
import
org.sss.presentation.noui.util.DataSecurityUtil
;
import
org.sss.presentation.noui.util.NoUiPresentationUtil
;
...
...
@@ -59,6 +60,9 @@ public abstract class AbstractCommonController {
Alias
alias
=
new
Alias
(
mappingUrl
);
String
trnName
=
alias
.
getTrnName
();
putTxInfo
(
alias
,
mappingUrl
);
//记录交易信息
Map
<
String
,
?>
paramsMap
=
noUiRequest
.
getParamsMap
();
context
=
NoUiContextManager
.
createNoUiContext
(
noUiRequest
);
...
...
@@ -177,19 +181,29 @@ public abstract class AbstractCommonController {
ret
=
ResultUtil
.
result
(
NoUiPresentationUtil
.
retCode
(
context
),
NoUiPresentationUtil
.
retMsg
(
context
),
afterReturnData
,
paginationData
,
NoUiPresentationUtil
.
handleErrorReturnData
(
context
,
alias
),
NoUiPresentationUtil
.
handleCodeTableReturnData
(
context
,
alias
),
noUiVersion
.
getVersion
());
}
catch
(
Exception
e
)
{
}
catch
(
Throwable
e
)
{
log
.
error
(
"OnClick command error"
,
e
);
ret
=
ResultUtil
.
result
(
ErrorCodes
.
ERROR
,
"hander error"
,
"service error"
,
noUiVersion
.
getVersion
());
TxInfo
.
recordException
(
e
);
}
finally
{
if
(
context
!=
null
)
{
//context.getSupport().disconnect();
context
.
dispose
();
}
TxInfo
.
releaseCurrTxInfo
();
}
return
ret
;
}
private
void
putTxInfo
(
Alias
alias
,
String
mappingUrl
)
{
String
trnName
=
alias
.
getTrnName
();
String
aliasActionUrl
=
alias
.
getAliasActionUrl
();
String
actionUrl
=
alias
.
getRel
().
get
(
aliasActionUrl
);
TxInfo
.
putTxInfo
(
trnName
,
mappingUrl
,
actionUrl
);
}
private
IBaseObject
baseObject
(
NoUiContext
context
,
NoUiRequest
noUiRequest
,
Alias
alias
)
{
String
aliasActionUrl
=
alias
.
getAliasActionUrl
();
String
actionUrl
=
alias
.
getRel
().
get
(
aliasActionUrl
);
...
...
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