Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in / Register
Toggle navigation
Y
yzg-util
Project
Project
Details
Activity
Releases
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
YZG
yzg-util
Commits
2110a4da
Commit
2110a4da
authored
6 years ago
by
yanzg
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
日志处理服务
parent
0bd070a2
Changes
14
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
14 changed files
with
677 additions
and
387 deletions
+677
-387
ExceptionHelper.java
.../java/com/yanzuoguang/util/exception/ExceptionHelper.java
+22
-1
DateHelper.java
...src/main/java/com/yanzuoguang/util/helper/DateHelper.java
+1
-0
EnumHelper.java
...src/main/java/com/yanzuoguang/util/helper/EnumHelper.java
+2
-0
StringHelper.java
...c/main/java/com/yanzuoguang/util/helper/StringHelper.java
+1
-2
RunPlan.java
...se/src/main/java/com/yanzuoguang/util/thread/RunPlan.java
+1
-1
ThreadHelper.java
...c/main/java/com/yanzuoguang/util/thread/ThreadHelper.java
+1
-1
ThreadNext.java
...src/main/java/com/yanzuoguang/util/thread/ThreadNext.java
+60
-0
LogVo.java
...til-base/src/main/java/com/yanzuoguang/util/vo/LogVo.java
+101
-0
pom.xml
yzg-util-cloud/pom.xml
+60
-0
AbstractValidateAspect.java
...ava/com/yanzuoguang/cloud/aop/AbstractValidateAspect.java
+30
-0
FeignAspect.java
.../src/main/java/com/yanzuoguang/cloud/aop/FeignAspect.java
+71
-71
LogFeign.java
...oud/src/main/java/com/yanzuoguang/cloud/aop/LogFeign.java
+17
-0
RequestCacheResult.java
...in/java/com/yanzuoguang/cloud/aop/RequestCacheResult.java
+61
-61
WebAspect.java
...ud/src/main/java/com/yanzuoguang/cloud/aop/WebAspect.java
+249
-250
No files found.
yzg-util-base/src/main/java/com/yanzuoguang/util/
helper
/ExceptionHelper.java
→
yzg-util-base/src/main/java/com/yanzuoguang/util/
exception
/ExceptionHelper.java
View file @
2110a4da
package
com
.
yanzuoguang
.
util
.
helper
;
package
com
.
yanzuoguang
.
util
.
exception
;
import
com.yanzuoguang.util.contants.ResultConstants
;
import
com.yanzuoguang.util.vo.ResponseResult
;
import
java.util.logging.Logger
;
/**
/**
* 异常处理帮助类
* 异常处理帮助类
...
@@ -41,4 +46,20 @@ public class ExceptionHelper {
...
@@ -41,4 +46,20 @@ public class ExceptionHelper {
String
exception
=
local
+
"/n"
+
"开始:"
+
start
+
" 结束:"
+
end
+
"总长:"
+
allsize
+
"/n"
+
str
;
String
exception
=
local
+
"/n"
+
"开始:"
+
start
+
" 结束:"
+
end
+
"总长:"
+
allsize
+
"/n"
+
str
;
throw
new
Exception
(
exception
);
throw
new
Exception
(
exception
);
}
}
/**
* 根据异常获取返回数据
*
* @param e 异常信息
* @return 返回的数据
*/
public
static
ResponseResult
getError
(
Exception
e
)
{
if
(
e
instanceof
CodeException
)
{
CodeException
code
=
(
CodeException
)
e
;
return
new
ResponseResult
(
code
.
getCode
(),
code
.
getMessage
());
}
else
{
return
new
ResponseResult
(
ResultConstants
.
UNKNOW_ERROR
,
e
.
getMessage
());
}
}
}
}
This diff is collapsed.
Click to expand it.
yzg-util-base/src/main/java/com/yanzuoguang/util/helper/DateHelper.java
View file @
2110a4da
package
com
.
yanzuoguang
.
util
.
helper
;
package
com
.
yanzuoguang
.
util
.
helper
;
import
com.yanzuoguang.util.exception.CodeException
;
import
com.yanzuoguang.util.exception.CodeException
;
import
com.yanzuoguang.util.exception.ExceptionHelper
;
import
java.sql.Timestamp
;
import
java.sql.Timestamp
;
import
java.text.ParseException
;
import
java.text.ParseException
;
...
...
This diff is collapsed.
Click to expand it.
yzg-util-base/src/main/java/com/yanzuoguang/util/helper/EnumHelper.java
View file @
2110a4da
package
com
.
yanzuoguang
.
util
.
helper
;
package
com
.
yanzuoguang
.
util
.
helper
;
import
com.yanzuoguang.util.exception.ExceptionHelper
;
import
java.lang.reflect.Method
;
import
java.lang.reflect.Method
;
import
java.util.HashMap
;
import
java.util.HashMap
;
...
...
This diff is collapsed.
Click to expand it.
yzg-util-base/src/main/java/com/yanzuoguang/util/helper/StringHelper.java
View file @
2110a4da
package
com
.
yanzuoguang
.
util
.
helper
;
package
com
.
yanzuoguang
.
util
.
helper
;
import
com.yanzuoguang.util.exception.CodeException
;
import
com.yanzuoguang.util.exception.CodeException
;
import
com.yanzuoguang.util.exception.ExceptionHelper
;
import
java.io.UnsupportedEncodingException
;
import
java.io.UnsupportedEncodingException
;
import
java.security.MessageDigest
;
import
java.security.MessageDigest
;
...
@@ -9,8 +10,6 @@ import java.util.Arrays;
...
@@ -9,8 +10,6 @@ import java.util.Arrays;
import
java.util.Date
;
import
java.util.Date
;
import
java.util.List
;
import
java.util.List
;
import
java.util.UUID
;
import
java.util.UUID
;
import
java.util.regex.Matcher
;
import
java.util.regex.Pattern
;
/**
/**
* 字符串帮主类
* 字符串帮主类
...
...
This diff is collapsed.
Click to expand it.
yzg-util-base/src/main/java/com/yanzuoguang/util/thread/RunPlan.java
View file @
2110a4da
package
com
.
yanzuoguang
.
util
.
thread
;
package
com
.
yanzuoguang
.
util
.
thread
;
import
com.yanzuoguang.util.helper.Event
;
import
com.yanzuoguang.util.helper.Event
;
import
com.yanzuoguang.util.
helper
.ExceptionHelper
;
import
com.yanzuoguang.util.
exception
.ExceptionHelper
;
import
com.yanzuoguang.util.helper.StringHelper
;
import
com.yanzuoguang.util.helper.StringHelper
;
import
java.util.ArrayList
;
import
java.util.ArrayList
;
...
...
This diff is collapsed.
Click to expand it.
yzg-util-base/src/main/java/com/yanzuoguang/util/thread/ThreadHelper.java
View file @
2110a4da
package
com
.
yanzuoguang
.
util
.
thread
;
package
com
.
yanzuoguang
.
util
.
thread
;
import
com.yanzuoguang.util.helper.DateHelper
;
import
com.yanzuoguang.util.helper.DateHelper
;
import
com.yanzuoguang.util.
helper
.ExceptionHelper
;
import
com.yanzuoguang.util.
exception
.ExceptionHelper
;
import
java.util.Date
;
import
java.util.Date
;
import
java.util.concurrent.ExecutorService
;
import
java.util.concurrent.ExecutorService
;
...
...
This diff is collapsed.
Click to expand it.
yzg-util-base/src/main/java/com/yanzuoguang/util/thread/ThreadNext.java
0 → 100644
View file @
2110a4da
package
com
.
yanzuoguang
.
util
.
thread
;
import
com.yanzuoguang.util.helper.StringHelper
;
import
com.yanzuoguang.util.log.Log
;
/**
* 线程执行类
*/
public
class
ThreadNext
{
public
interface
Next
{
/**
* 执行下一个函数,出现异常会继续执行
*
* @return 是否继续执行
*/
boolean
next
()
throws
Exception
;
/**
* 沉睡时间
*
* @return
*/
int
getNextTime
();
}
public
static
void
start
(
Next
next
,
String
error
)
{
if
(
next
==
null
)
{
return
;
}
new
Thread
(
new
Runnable
()
{
@Override
public
void
run
()
{
boolean
isExecute
=
true
;
Exception
frontEx
=
null
;
while
(
isExecute
)
{
try
{
isExecute
=
next
.
next
();
}
catch
(
Exception
ex
)
{
if
(
frontEx
==
null
||
!(
frontEx
.
getClass
()
==
ex
.
getClass
()
&&
StringHelper
.
compare
(
frontEx
.
getMessage
(),
ex
.
getMessage
())))
{
Log
.
error
(
ThreadNext
.
class
,
ex
);
}
frontEx
=
ex
;
}
if
(
isExecute
)
{
try
{
int
max
=
Math
.
max
(
next
.
getNextTime
(),
100
);
Thread
.
sleep
(
max
);
}
catch
(
InterruptedException
e
)
{
e
.
printStackTrace
();
}
}
else
{
break
;
}
}
}
}).
start
();
}
}
This diff is collapsed.
Click to expand it.
yzg-util-base/src/main/java/com/yanzuoguang/util/vo/LogVo.java
0 → 100644
View file @
2110a4da
package
com
.
yanzuoguang
.
util
.
vo
;
/**
* 日志实例
*/
public
class
LogVo
extends
BaseReqVo
{
private
static
final
long
serialVersionUID
=
-
8629960247077620458L
;
/**
* 日志id
*/
private
String
logId
;
/**
* 工程实例名
*/
private
String
logSources
;
/**
* 请求接口地址
*/
private
String
interUrl
;
/**
* 请求内容
*/
private
String
content
;
/**
* 返回参数
*/
private
String
result
;
/**
* 接口处理状态,是否有异常
*/
private
int
status
;
/**
* 创建时间
*/
private
String
createDate
;
public
String
getLogId
()
{
return
logId
;
}
public
void
setLogId
(
String
logId
)
{
this
.
logId
=
logId
;
}
public
String
getLogSources
()
{
return
logSources
;
}
public
void
setLogSources
(
String
logSources
)
{
this
.
logSources
=
logSources
;
}
public
String
getInterUrl
()
{
return
interUrl
;
}
public
void
setInterUrl
(
String
interUrl
)
{
this
.
interUrl
=
interUrl
;
}
public
String
getContent
()
{
return
content
;
}
public
void
setContent
(
String
content
)
{
this
.
content
=
content
;
}
public
String
getResult
()
{
return
result
;
}
public
void
setResult
(
String
result
)
{
this
.
result
=
result
;
}
public
int
getStatus
()
{
return
status
;
}
public
void
setStatus
(
int
status
)
{
this
.
status
=
status
;
}
public
String
getCreateDate
()
{
return
createDate
;
}
public
void
setCreateDate
(
String
createDate
)
{
this
.
createDate
=
createDate
;
}
}
This diff is collapsed.
Click to expand it.
yzg-util-cloud/pom.xml
View file @
2110a4da
...
@@ -23,6 +23,66 @@
...
@@ -23,6 +23,66 @@
</properties>
</properties>
<dependencies>
<dependency>
<groupId>
junit
</groupId>
<artifactId>
junit
</artifactId>
<scope>
test
</scope>
</dependency>
<!-- 感知服务器端配置变化 -->
<dependency>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-actuator
</artifactId>
</dependency>
<dependency>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-aop
</artifactId>
</dependency>
<dependency>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-web
</artifactId>
</dependency>
<dependency>
<groupId>
org.springframework.cloud
</groupId>
<artifactId>
spring-cloud-starter-config
</artifactId>
</dependency>
<dependency>
<groupId>
org.springframework.cloud
</groupId>
<artifactId>
spring-cloud-starter-netflix-eureka-client
</artifactId>
</dependency>
<dependency>
<groupId>
org.springframework.cloud
</groupId>
<artifactId>
spring-cloud-starter-openfeign
</artifactId>
</dependency>
<dependency>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-devtools
</artifactId>
<optional>
true
</optional>
</dependency>
<!-- HTTP请求组件 -->
<dependency>
<groupId>
org.apache.httpcomponents
</groupId>
<artifactId>
httpclient
</artifactId>
</dependency>
<dependency>
<groupId>
org.apache.httpcomponents
</groupId>
<artifactId>
httpmime
</artifactId>
</dependency>
<dependency>
<groupId>
${project.groupId}
</groupId>
<artifactId>
yzg-util-base
</artifactId>
<version>
${project.version}
</version>
</dependency>
</dependencies>
<dependencyManagement>
<dependencyManagement>
<dependencies>
<dependencies>
<dependency>
<dependency>
...
...
This diff is collapsed.
Click to expand it.
yzg-util-cloud/src/main/java/com/yanzuoguang/cloud/aop/AbstractValidateAspect.java
0 → 100644
View file @
2110a4da
package
com
.
yanzuoguang
.
cloud
.
aop
;
import
org.springframework.web.context.request.RequestContextHolder
;
import
org.springframework.web.context.request.ServletRequestAttributes
;
import
javax.servlet.http.HttpServletRequest
;
/**
* 虚拟拦截类
*/
public
abstract
class
AbstractValidateAspect
{
/**
* 获取 http request
*
* @return
*/
protected
static
HttpServletRequest
getRequest
()
{
return
((
ServletRequestAttributes
)
RequestContextHolder
.
getRequestAttributes
()).
getRequest
();
}
/**
* 获取 http request url
*
* @return
*/
protected
static
String
getHttpRequestUrl
()
{
return
getRequest
().
getServletPath
();
}
}
This diff is collapsed.
Click to expand it.
yzg-util-cloud/src/main/java/com/yanzuoguang/cloud/aop/FeignAspect.java
View file @
2110a4da
//
package com.yanzuoguang.cloud.aop;
package
com
.
yanzuoguang
.
cloud
.
aop
;
//
//import com.tourbida.sys.common.AbstractValidateAspect
;
import
com.yanzuoguang.util.contants.ResultConstants
;
//import com.tourbida.sys
.exception.CodeException;
import
com.yanzuoguang.util
.exception.CodeException
;
//import com.tourbida.sys.vo.ResponseResult
;
import
com.yanzuoguang.util.exception.ExceptionHelper
;
//import com.tourbida.sys.vo.ResponseResultBuilder
;
import
com.yanzuoguang.util.vo.ResponseResult
;
//import com.tourbida.sys.web.BaseController
;
import
org.aspectj.lang.ProceedingJoinPoint
;
//import org.aspectj.lang.ProceedingJoinPoint
;
import
org.aspectj.lang.annotation.Around
;
//import org.aspectj.lang.annotation.Around
;
import
org.aspectj.lang.annotation.Aspect
;
//import org.aspectj.lang.annotation.Aspec
t;
import
org.aspectj.lang.annotation.Pointcu
t
;
//import org.aspectj.lang.annotation.Pointcut
;
import
org.slf4j.Logger
;
//import org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
//import org.slf4j.LoggerFactory
;
import
org.springframework.stereotype.Component
;
//import org.springframework.stereotype.Component;
/
/
/
**
///**
* 接口切面,用于验证接口回调返回参数
// * 接口切面,用于验证接口回调返回参数
*/
// */
@Aspect
//@Aspec
t
@Componen
t
//@Component
public
class
FeignAspect
extends
AbstractValidateAspect
{
//public class FeignAspect extends AbstractValidateAspect {
//
private
static
final
Logger
logger
=
LoggerFactory
.
getLogger
(
FeignAspect
.
class
);
// private static final Logger logger = LoggerFactory.getLogger(FeignAspect.class);
//
/**
// /**
* AOP的表达式
// * AOP的表达式
*/
// */
@Pointcut
(
"execution(* *..feign..*(..))"
)
// @Pointcut("execution(* com.panding..feign..*(..))")
public
void
feignAspect
()
{
// public void feignAspect() {
}
// }
//
/**
// /**
* 执行环形切面
// * 执行环形切面
*
// *
* @param joinPoint
// * @param joinPoint
* @return
// * @return
*/
// */
@Around
(
value
=
"feignAspect()"
)
// @Around(value = "feignAspect()")
public
Object
requestFeignAround
(
ProceedingJoinPoint
joinPoint
)
throws
Throwable
{
// public Object requestFeignAround(ProceedingJoinPoint joinPoint) throws Throwable {
String
name
=
joinPoint
.
getSignature
().
getName
();
// String name = joinPoint.getSignature().getName()
;
Object
result
=
null
;
// Object result = null
;
long
start
=
System
.
currentTimeMillis
()
;
// long start = System.currentTimeMillis();
try
{
// try {
logger
.
info
(
"=================[ {} ] feign params is {} ================="
,
name
,
joinPoint
.
getArgs
());
// logger.info("=================[ {} ] feign params is {} =================", name, joinPoint.getArgs()
);
result
=
joinPoint
.
proceed
(
);
// result = joinPoint.proceed();
//
// 假如是标准格式,则验证接口是否成功,不成功则抛出异常
// // 假如是标准格式,则验证接口是否成功,不成功则抛出异常
if
(
result
instanceof
ResponseResult
)
{
// if (result instanceof ResponseResult) {
ResponseResult
responseResult
=
(
ResponseResult
)
result
;
// ResponseResult responseResult = (ResponseResult) result;
if
(!
ResultConstants
.
SUCCESS
.
equals
(
responseResult
.
getCode
()))
{
// if (!ResponseResultBuilder.SUCCESS.equals(responseResult.getCode())) {
throw
new
CodeException
(
responseResult
.
getCode
(),
responseResult
.
getMessage
());
// throw new CodeException(responseResult.getCode(), responseResult.getMessage());
}
//
}
}
// }
return
result
;
// return result;
}
catch
(
CodeException
ex
)
{
// } catch (CodeException ex) {
logger
.
info
(
"=================[ {} ] feign is error {} ================="
,
name
,
ex
);
// logger.info("=================[ {} ] feign is error {} =================", name, ex
);
result
=
new
ResponseResult
(
ex
.
getCode
(),
ex
.
getMessage
()
);
// result = new ResponseResult(ex.getCode(), ex.getMessage())
;
throw
ex
;
// throw ex;
}
catch
(
Exception
e
)
{
// } catch (Exception e) {
ResponseResult
responseResult
=
ExceptionHelper
.
getError
(
e
);
// ResponseResult responseResult = BaseController.getError(logger,
"=================[ " + name + " ] feign is error {} =================", e);
logger
.
error
(
"=================[ "
+
name
+
" ] feign is error {} ================="
,
e
);
//
result = responseResult;
result
=
responseResult
;
//
throw new CodeException(responseResult.getCode(), responseResult.getMessage());
throw
new
CodeException
(
responseResult
.
getCode
(),
responseResult
.
getMessage
());
//
} finally {
}
finally
{
//
// 记录服务调用时间,请求日志
// 记录服务调用时间,请求日志
//
long end = System.currentTimeMillis();
long
end
=
System
.
currentTimeMillis
();
//
logger.info("=================[ {} ] feign time ({})ms, result is {} =================", name, (end - start), result);
logger
.
info
(
"=================[ {} ] feign time ({})ms, result is {} ================="
,
name
,
(
end
-
start
),
result
);
//
}
}
//
}
}
//
//
//
}
}
This diff is collapsed.
Click to expand it.
yzg-util-cloud/src/main/java/com/yanzuoguang/cloud/aop/LogFeign.java
0 → 100644
View file @
2110a4da
package
com
.
yanzuoguang
.
cloud
.
aop
;
import
com.yanzuoguang.util.vo.LogVo
;
import
com.yanzuoguang.util.vo.ResponseResult
;
/**
* 调用外置服务保存日志对象
*/
public
interface
LogFeign
{
/**
* 保存日志对象
*
* @param log 需要保存的日志对象
*/
ResponseResult
<
String
>
save
(
LogVo
log
);
}
This diff is collapsed.
Click to expand it.
yzg-util-cloud/src/main/java/com/yanzuoguang/cloud/aop/RequestCacheResult.java
View file @
2110a4da
//
package com.yanzuoguang.cloud.aop;
package
com
.
yanzuoguang
.
cloud
.
aop
;
//
//
import java.util.Date;
import
java.util.Date
;
//
/
//
**
/**
//
* 请求缓存的数据
* 请求缓存的数据
//
*/
*/
//
public class RequestCacheResult {
public
class
RequestCacheResult
{
//
//
/**
/**
//
* 构造函数
* 构造函数
//
*/
*/
//
public RequestCacheResult(String reqID) {
public
RequestCacheResult
(
String
reqID
)
{
//
this.date = new Date();
this
.
date
=
new
Date
();
//
this.reqID = reqID;
this
.
reqID
=
reqID
;
//
this.result = null;
this
.
result
=
null
;
//
}
}
//
//
/**
/**
//
* 请求编号
* 请求编号
//
*/
*/
//
private String reqID;
private
String
reqID
;
//
//
/**
/**
//
* 结果
* 结果
//
*/
*/
//
private Object result;
private
Object
result
;
//
//
/**
/**
//
* 时间
* 时间
//
*/
*/
//
private Date date;
private
Date
date
;
//
//
/**
/**
//
* 获取毫秒数
* 获取毫秒数
//
*
*
//
* @return
* @return
//
*/
*/
//
public long getMillsecond() {
public
long
getMillsecond
()
{
//
return new Date().getTime() - date.getTime();
return
new
Date
().
getTime
()
-
date
.
getTime
();
//
}
}
//
//
/**
/**
//
* 获取结果
* 获取结果
//
*
*
//
* @return
* @return
//
*/
*/
//
public Object getResult() {
public
Object
getResult
()
{
//
return result;
return
result
;
//
}
}
//
//
/**
/**
//
* 返回结果
* 返回结果
//
*
*
//
* @param result
* @param result
//
*/
*/
//
public void setResult(Object result) {
public
void
setResult
(
Object
result
)
{
//
this.date = new Date();
this
.
date
=
new
Date
();
//
this.result = result;
this
.
result
=
result
;
//
}
}
//
}
}
This diff is collapsed.
Click to expand it.
yzg-util-cloud/src/main/java/com/yanzuoguang/cloud/aop/WebAspect.java
View file @
2110a4da
This diff is collapsed.
Click to expand it.
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