Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
S
schbrain-parent
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Packages & Registries
Packages & Registries
Package Registry
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
panwangnan
schbrain-parent
Commits
77232905
Commit
77232905
authored
Jul 13, 2023
by
liaozan
🏀
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Replace Spring' StringUtils with Commons-lang3 StringUtils
parent
02db5708
Changes
20
Show whitespace changes
Inline
Side-by-side
Showing
20 changed files
with
68 additions
and
89 deletions
+68
-89
commons/common-util/src/main/java/com/schbrain/common/util/ExcelUtils.java
...il/src/main/java/com/schbrain/common/util/ExcelUtils.java
+3
-2
commons/common-util/src/main/java/com/schbrain/common/util/PortUtils.java
...til/src/main/java/com/schbrain/common/util/PortUtils.java
+2
-2
commons/common-util/src/main/java/com/schbrain/common/util/SpelUtils.java
...til/src/main/java/com/schbrain/common/util/SpelUtils.java
+5
-2
commons/common/src/main/java/com/schbrain/common/enums/BooleanEnum.java
.../src/main/java/com/schbrain/common/enums/BooleanEnum.java
+4
-7
commons/web-common/src/main/java/com/schbrain/common/web/exception/GlobalExceptionHandler.java
...schbrain/common/web/exception/GlobalExceptionHandler.java
+5
-4
commons/web-common/src/main/java/com/schbrain/common/web/servlet/RequestLoggingFilter.java
...com/schbrain/common/web/servlet/RequestLoggingFilter.java
+4
-4
commons/web-common/src/main/java/com/schbrain/common/web/support/concurrent/RateLimitAspect.java
...hbrain/common/web/support/concurrent/RateLimitAspect.java
+12
-27
commons/web-common/src/main/java/com/schbrain/common/web/support/concurrent/RateLimiter.java
...m/schbrain/common/web/support/concurrent/RateLimiter.java
+2
-6
commons/web-common/src/main/java/com/schbrain/common/web/utils/ServletUtils.java
...main/java/com/schbrain/common/web/utils/ServletUtils.java
+3
-2
pom.xml
pom.xml
+1
-1
starters/apollo-spring-boot-starter/src/main/java/com/schbrain/framework/autoconfigure/apollo/ApolloConfigurationInitializerEnvironmentPostProcessor.java
...olloConfigurationInitializerEnvironmentPostProcessor.java
+5
-5
starters/cache-spring-boot-starter/src/main/java/com/schbrain/framework/autoconfigure/cache/provider/redis/RedisCacheConfiguration.java
...nfigure/cache/provider/redis/RedisCacheConfiguration.java
+2
-3
starters/dubbo-spring-boot-starter/pom.xml
starters/dubbo-spring-boot-starter/pom.xml
+1
-5
starters/dubbo-spring-boot-starter/src/main/java/com/schbrain/framework/autoconfigure/dubbo/filter/DubboExceptionFilter.java
...work/autoconfigure/dubbo/filter/DubboExceptionFilter.java
+4
-3
starters/elasticsearch-spring-boot-starter/pom.xml
starters/elasticsearch-spring-boot-starter/pom.xml
+1
-1
starters/logger-spring-boot-starter/src/main/java/com/schbrain/framework/autoconfigure/logger/LoggerConfigurationInitializer.java
.../autoconfigure/logger/LoggerConfigurationInitializer.java
+3
-3
starters/logger-spring-boot-starter/src/main/java/com/schbrain/framework/autoconfigure/logger/apollo/DynamicLoggerConfiguration.java
...toconfigure/logger/apollo/DynamicLoggerConfiguration.java
+3
-4
starters/logger-spring-boot-starter/src/main/java/com/schbrain/framework/autoconfigure/logger/apollo/LoggingLevelChangeListener.java
...toconfigure/logger/apollo/LoggingLevelChangeListener.java
+2
-2
starters/logger-spring-boot-starter/src/main/java/com/schbrain/framework/autoconfigure/logger/listener/LoggerConfigLoadedEventListener.java
...gure/logger/listener/LoggerConfigLoadedEventListener.java
+3
-3
starters/oss-spring-boot-starter/src/main/java/com/schbrain/framework/autoconfigure/oss/util/OssUtils.java
...m/schbrain/framework/autoconfigure/oss/util/OssUtils.java
+3
-3
No files found.
commons/common-util/src/main/java/com/schbrain/common/util/ExcelUtils.java
View file @
77232905
package
com.schbrain.common.util
;
import
cn.hutool.poi.excel.ExcelUtil
;
import
com.alibaba.excel.EasyExcel
;
import
com.schbrain.common.util.support.excel.bean.ExcelReadResult
;
import
com.schbrain.common.util.support.excel.exception.ExcelException
;
...
...
@@ -21,7 +22,7 @@ import java.util.Map;
* @author liaozan
* @since 2022/1/6
*/
public
class
ExcelUtils
{
public
class
ExcelUtils
extends
ExcelUtil
{
// file
public
static
ExcelReadResult
<
Map
<
Integer
,
Object
>>
read
(
File
excelFile
)
{
...
...
commons/common-util/src/main/java/com/schbrain/common/util/PortUtils.java
View file @
77232905
...
...
@@ -23,7 +23,7 @@ public class PortUtils {
portTmp
++;
}
}
throw
new
BaseException
(
"
n
o available port."
);
throw
new
BaseException
(
"
N
o available port."
);
}
public
static
boolean
isPortUsed
(
int
port
)
{
...
...
@@ -32,7 +32,7 @@ public class PortUtils {
try
{
serverSocket
=
new
ServerSocket
(
port
);
}
catch
(
IOException
e
)
{
log
.
warn
(
"
c
urrent port[{}] is in use"
,
port
);
log
.
warn
(
"
C
urrent port[{}] is in use"
,
port
);
used
=
true
;
}
finally
{
if
(
serverSocket
!=
null
)
{
...
...
commons/common-util/src/main/java/com/schbrain/common/util/SpelUtils.java
View file @
77232905
package
com.schbrain.common.util
;
import
org.apache.commons.lang3.StringUtils
;
import
org.springframework.beans.factory.BeanFactory
;
import
org.springframework.context.expression.BeanFactoryResolver
;
import
org.springframework.expression.EvaluationContext
;
import
org.springframework.expression.Expression
;
import
org.springframework.expression.ExpressionParser
;
...
...
@@ -16,8 +18,9 @@ public class SpelUtils {
private
static
final
ConcurrentHashMap
<
String
,
Expression
>
expressionCache
=
new
ConcurrentHashMap
<>();
public
static
<
T
>
T
parse
(
String
express
,
Map
<
String
,
Object
>
variables
,
Class
<
T
>
valueType
)
{
public
static
<
T
>
T
parse
(
String
express
,
Map
<
String
,
Object
>
variables
,
Class
<
T
>
valueType
,
BeanFactory
beanFactory
)
{
StandardEvaluationContext
ctx
=
new
StandardEvaluationContext
();
ctx
.
setBeanResolver
(
new
BeanFactoryResolver
(
beanFactory
));
ctx
.
setVariables
(
variables
);
return
parse
(
express
,
ctx
,
valueType
);
}
...
...
commons/common/src/main/java/com/schbrain/common/enums/BooleanEnum.java
View file @
77232905
...
...
@@ -3,6 +3,8 @@ package com.schbrain.common.enums;
import
lombok.AllArgsConstructor
;
import
lombok.Getter
;
import
java.util.Objects
;
/**
* @author huangxi
* @since 2022/08/23
...
...
@@ -23,12 +25,7 @@ public enum BooleanEnum {
private
final
Integer
value
;
public
static
boolean
validate
(
Integer
value
)
{
for
(
BooleanEnum
booleanEnum
:
values
())
{
if
(
booleanEnum
.
getValue
().
equals
(
value
))
{
return
true
;
}
}
return
false
;
return
Objects
.
equals
(
TRUE
.
value
,
value
);
}
}
commons/web-common/src/main/java/com/schbrain/common/web/exception/GlobalExceptionHandler.java
View file @
77232905
...
...
@@ -4,7 +4,6 @@ import cn.hutool.core.exceptions.ExceptionUtil;
import
cn.hutool.core.util.StrUtil
;
import
com.schbrain.common.constants.ResponseActionConstants
;
import
com.schbrain.common.exception.BaseException
;
import
com.schbrain.common.util.support.ValidationMessageBuilder
;
import
com.schbrain.common.web.result.ResponseDTO
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.dao.DataAccessException
;
...
...
@@ -31,6 +30,8 @@ import java.util.List;
import
static
com
.
schbrain
.
common
.
constants
.
ResponseCodeConstants
.
PARAM_INVALID
;
import
static
com
.
schbrain
.
common
.
constants
.
ResponseCodeConstants
.
SERVER_ERROR
;
import
static
com
.
schbrain
.
common
.
util
.
support
.
ValidationMessageBuilder
.
buildBindingErrorMsg
;
import
static
com
.
schbrain
.
common
.
util
.
support
.
ValidationMessageBuilder
.
buildConstraintViolationErrorMsg
;
/**
* @author liaozan
...
...
@@ -183,14 +184,14 @@ public class GlobalExceptionHandler {
/************************************* Parameter Binding Exception Handing *************************************/
@ExceptionHandler
(
BindException
.
class
)
public
ResponseDTO
<
String
>
handleBindException
(
BindException
ex
)
{
String
errorMsg
=
ValidationMessageBuilder
.
buildBindingErrorMsg
(
ex
.
getBindingResult
());
String
errorMsg
=
buildBindingErrorMsg
(
ex
.
getBindingResult
());
log
.
error
(
errorMsg
);
return
buildResponse
(
ex
,
PARAM_INVALID
,
errorMsg
);
}
@ExceptionHandler
(
ConstraintViolationException
.
class
)
public
ResponseDTO
<
String
>
handleConstraintViolationException
(
ConstraintViolationException
ex
)
{
String
errorMsg
=
ValidationMessageBuilder
.
buildConstraintViolationErrorMsg
(
ex
.
getConstraintViolations
());
String
errorMsg
=
buildConstraintViolationErrorMsg
(
ex
.
getConstraintViolations
());
log
.
error
(
errorMsg
);
return
buildResponse
(
ex
,
PARAM_INVALID
,
errorMsg
);
}
...
...
commons/web-common/src/main/java/com/schbrain/common/web/servlet/RequestLoggingFilter.java
View file @
77232905
...
...
@@ -3,9 +3,9 @@ package com.schbrain.common.web.servlet;
import
cn.hutool.core.text.CharPool
;
import
cn.hutool.core.util.ArrayUtil
;
import
lombok.extern.slf4j.Slf4j
;
import
org.apache.commons.lang3.StringUtils
;
import
org.springframework.boot.web.servlet.filter.OrderedFilter
;
import
org.springframework.core.Ordered
;
import
org.springframework.util.StringUtils
;
import
org.springframework.web.cors.CorsUtils
;
import
org.springframework.web.filter.OncePerRequestFilter
;
import
org.springframework.web.util.ContentCachingRequestWrapper
;
...
...
@@ -61,10 +61,10 @@ public class RequestLoggingFilter extends OncePerRequestFilter implements Ordere
String
body
=
getRequestBody
(
request
);
StringBuilder
builder
=
new
StringBuilder
();
builder
.
append
(
"requestUri: "
).
append
(
method
).
append
(
CharPool
.
SPACE
).
append
(
requestUri
);
if
(
StringUtils
.
hasText
(
queryString
))
{
if
(
StringUtils
.
isNotBlank
(
queryString
))
{
builder
.
append
(
", queryString: "
).
append
(
queryString
);
}
if
(
StringUtils
.
hasText
(
body
))
{
if
(
StringUtils
.
isNotBlank
(
body
))
{
builder
.
append
(
", body: "
).
append
(
body
);
}
builder
.
append
(
", startTime: "
).
append
(
startTime
);
...
...
commons/web-common/src/main/java/com/schbrain/common/web/support/concurrent/RateLimitAspect.java
View file @
77232905
package
com.schbrain.common.web.support.concurrent
;
import
cn.hutool.extra.spring.SpringUtil
;
import
com.schbrain.common.exception.BaseException
;
import
com.schbrain.common.util.ApplicationName
;
import
com.schbrain.common.util.ParameterDiscoverUtils
;
import
com.schbrain.common.util.SpelUtils
;
import
com.schbrain.common.web.utils.ServletUtils
;
import
lombok.extern.slf4j.Slf4j
;
import
org.apache.commons.collections4.MapUtils
;
import
org.aspectj.lang.JoinPoint
;
import
org.aspectj.lang.annotation.Aspect
;
import
org.aspectj.lang.annotation.Before
;
import
org.aspectj.lang.reflect.Advice
;
import
org.aspectj.lang.reflect.MethodSignature
;
import
org.springframework.beans.BeanUtils
;
import
org.springframework.beans.factory.BeanFactory
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnBean
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnClass
;
import
org.springframework.data.redis.connection.RedisConnectionFactory
;
import
org.springframework.data.redis.core.BoundValueOperations
;
import
org.springframework.data.redis.core.StringRedisTemplate
;
import
org.springframework.util.CollectionUtils
;
import
java.util.HashMap
;
import
java.util.Map
;
import
java.util.Optional
;
import
java.util.concurrent.ConcurrentHashMap
;
import
static
com
.
schbrain
.
common
.
util
.
ParameterDiscoverUtils
.
getMethodArgsMap
;
/**
* @author liaozan
* @see com.schbrain.common.web.support.concurrent.RateLimiter
...
...
@@ -39,11 +38,12 @@ public class RateLimitAspect {
private
final
Map
<
Class
<?>,
RateLimitCacheKeyVariablesContributor
>
contributorMap
=
new
ConcurrentHashMap
<>();
private
final
String
keyPrefix
;
private
final
BeanFactory
beanFactory
;
private
final
StringRedisTemplate
stringRedisTemplate
;
public
RateLimitAspect
(
StringRedisTemplate
stringRedisTemplate
)
{
public
RateLimitAspect
(
StringRedisTemplate
stringRedisTemplate
,
BeanFactory
beanFactory
)
{
this
.
keyPrefix
=
ApplicationName
.
get
();
this
.
beanFactory
=
beanFactory
;
this
.
stringRedisTemplate
=
stringRedisTemplate
;
}
...
...
@@ -56,7 +56,7 @@ public class RateLimitAspect {
protected
void
doRateLimit
(
RateLimiter
rateLimiter
,
JoinPoint
joinPoint
,
MethodSignature
signature
)
{
Map
<
String
,
Object
>
variables
=
prepareVariables
(
rateLimiter
,
joinPoint
,
signature
);
String
cacheKey
=
SpelUtils
.
parse
(
rateLimiter
.
cacheKey
(),
variables
,
String
.
class
);
String
cacheKey
=
SpelUtils
.
parse
(
rateLimiter
.
cacheKey
(),
variables
,
String
.
class
,
beanFactory
);
if
(
cacheKey
==
null
)
{
throw
new
BaseException
(
"cacheKey should not be null"
);
}
...
...
@@ -67,7 +67,7 @@ public class RateLimitAspect {
try
{
long
accessCount
=
Optional
.
ofNullable
(
rateLimitOps
.
increment
()).
orElse
(
1L
);
if
(
accessCount
>
rateLimiter
.
permits
())
{
throw
new
BaseException
(
"
访问频次太快,请稍后再试。
"
);
throw
new
BaseException
(
"
The access frequency is too fast, please try again later
"
);
}
if
(
accessCount
<=
1
)
{
...
...
@@ -81,27 +81,12 @@ public class RateLimitAspect {
}
}
protected
Map
<
String
,
Object
>
createEvaluationVariables
(
MethodSignature
methodSignature
,
Object
[]
args
)
{
Map
<
String
,
Object
>
variables
=
new
HashMap
<>();
Map
<
String
,
Object
>
methodArgsMap
=
ParameterDiscoverUtils
.
getMethodArgsMap
(
methodSignature
.
getMethod
(),
args
);
if
(!
CollectionUtils
.
isEmpty
(
methodArgsMap
))
{
variables
.
putAll
(
methodArgsMap
);
}
variables
.
put
(
"request"
,
ServletUtils
.
getRequest
());
variables
.
put
(
"response"
,
ServletUtils
.
getResponse
());
variables
.
put
(
"applicationContext"
,
SpringUtil
.
getApplicationContext
());
variables
.
put
(
"beanFactory"
,
SpringUtil
.
getBeanFactory
());
variables
.
put
(
"args"
,
args
);
return
variables
;
}
protected
String
formatCacheKey
(
String
cacheKey
)
{
return
"rateLimit:"
+
keyPrefix
+
":"
+
cacheKey
;
}
private
Map
<
String
,
Object
>
prepareVariables
(
RateLimiter
rateLimiter
,
JoinPoint
joinPoint
,
MethodSignature
signature
)
{
Map
<
String
,
Object
>
variables
=
createEvaluationVariables
(
signature
,
joinPoint
.
getArgs
());
Map
<
String
,
Object
>
variables
=
getMethodArgsMap
(
signature
.
getMethod
()
,
joinPoint
.
getArgs
());
Class
<?
extends
RateLimitCacheKeyVariablesContributor
>
contributorClass
=
rateLimiter
.
contributor
();
if
(
contributorClass
==
null
||
contributorClass
==
NoOpRateLimitCacheKeyVariablesContributor
.
class
)
{
return
variables
;
...
...
@@ -113,7 +98,7 @@ public class RateLimitAspect {
contributorMap
.
put
(
contributorClass
,
contributor
);
}
Map
<
String
,
Object
>
contributeVariables
=
contributor
.
contribute
(
rateLimiter
,
joinPoint
,
signature
);
if
(
!
CollectionUtils
.
is
Empty
(
contributeVariables
))
{
if
(
MapUtils
.
isNot
Empty
(
contributeVariables
))
{
variables
.
putAll
(
contributeVariables
);
}
return
variables
;
...
...
commons/web-common/src/main/java/com/schbrain/common/web/support/concurrent/RateLimiter.java
View file @
77232905
package
com.schbrain.common.web.support.concurrent
;
import
org.aspectj.lang.reflect.MethodSignature
;
import
java.lang.annotation.*
;
import
java.util.concurrent.TimeUnit
;
...
...
@@ -30,9 +28,7 @@ public @interface RateLimiter {
int
permits
()
default
3
;
/**
* 缓存的 key,使用 spel 进行解析
* <p>
* 可用的变量 {@link RateLimitAspect#createEvaluationVariables(MethodSignature, Object[])}
* 缓存的 key,使用 spring el 进行解析
*/
String
cacheKey
();
...
...
commons/web-common/src/main/java/com/schbrain/common/web/utils/ServletUtils.java
View file @
77232905
package
com.schbrain.common.web.utils
;
import
cn.hutool.extra.servlet.ServletUtil
;
import
com.schbrain.common.exception.BaseException
;
import
org.springframework.web.context.request.RequestContextHolder
;
import
org.springframework.web.context.request.ServletRequestAttributes
;
...
...
@@ -12,7 +13,7 @@ import javax.servlet.http.HttpServletResponse;
* @author liaozan
* @since 2022/1/6
*/
public
class
ServletUtils
{
public
class
ServletUtils
extends
ServletUtil
{
public
static
HttpServletRequest
getRequest
()
{
ServletRequestAttributes
requestAttributes
=
getRequestAttributes
();
...
...
pom.xml
View file @
77232905
starters/apollo-spring-boot-starter/src/main/java/com/schbrain/framework/autoconfigure/apollo/ApolloConfigurationInitializerEnvironmentPostProcessor.java
View file @
77232905
...
...
@@ -5,12 +5,12 @@ import com.schbrain.common.util.ApplicationName;
import
com.schbrain.common.util.EnvUtils
;
import
com.schbrain.framework.support.spring.LoggerAwareEnvironmentPostProcessor
;
import
com.schbrain.framework.support.spring.defaults.DefaultPropertiesEnvironmentPostProcessor
;
import
org.apache.commons.lang3.StringUtils
;
import
org.springframework.boot.ConfigurableBootstrapContext
;
import
org.springframework.boot.SpringApplication
;
import
org.springframework.boot.logging.DeferredLogFactory
;
import
org.springframework.core.Ordered
;
import
org.springframework.core.env.ConfigurableEnvironment
;
import
org.springframework.util.StringUtils
;
import
java.util.LinkedHashMap
;
import
java.util.Map
;
...
...
@@ -109,21 +109,21 @@ public class ApolloConfigurationInitializerEnvironmentPostProcessor extends Logg
// {env}.meta
String
searchKey
=
fallbackKey
;
String
apolloUrl
=
environment
.
getProperty
(
searchKey
);
if
(
StringUtils
.
hasText
(
apolloUrl
))
{
if
(
StringUtils
.
isNotBlank
(
apolloUrl
))
{
return
apolloUrl
;
}
// apollo.meta.{env}
searchKey
=
APOLLO_META_KEY
+
"."
+
env
;
apolloUrl
=
environment
.
getProperty
(
searchKey
);
if
(
StringUtils
.
hasText
(
apolloUrl
))
{
if
(
StringUtils
.
isNotBlank
(
apolloUrl
))
{
return
apolloUrl
;
}
// apollo.meta
searchKey
=
APOLLO_META_KEY
;
apolloUrl
=
environment
.
getProperty
(
searchKey
);
if
(
StringUtils
.
hasText
(
apolloUrl
))
{
if
(
StringUtils
.
isNotBlank
(
apolloUrl
))
{
return
apolloUrl
;
}
...
...
starters/cache-spring-boot-starter/src/main/java/com/schbrain/framework/autoconfigure/cache/provider/redis/RedisCacheConfiguration.java
View file @
77232905
package
com.schbrain.framework.autoconfigure.cache.provider.redis
;
import
com.schbrain.framework.autoconfigure.cache.provider.CacheProvider
;
import
org.springframework.beans.factory.ObjectProvider
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnBean
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnClass
;
...
...
@@ -23,7 +22,7 @@ public class RedisCacheConfiguration {
@Bean
@ConditionalOnBean
(
RedisConnectionFactory
.
class
)
@ConditionalOnMissingBean
(
RedisCacheProvider
.
class
)
public
CacheProvider
redisCacheProvider
(
RedisConnectionFactory
redisConnectionFactory
,
ObjectProvider
<
StringRedisTemplate
>
redisTemplate
)
{
public
Redis
CacheProvider
redisCacheProvider
(
RedisConnectionFactory
redisConnectionFactory
,
ObjectProvider
<
StringRedisTemplate
>
redisTemplate
)
{
StringRedisTemplate
stringRedisTemplate
=
redisTemplate
.
getIfAvailable
(()
->
new
StringRedisTemplate
(
redisConnectionFactory
));
return
new
RedisCacheProvider
(
stringRedisTemplate
);
}
...
...
starters/dubbo-spring-boot-starter/pom.xml
View file @
77232905
...
...
@@ -74,10 +74,6 @@
<groupId>
org.apache.dubbo
</groupId>
<artifactId>
dubbo-serialization-hessian2
</artifactId>
</dependency>
<dependency>
<groupId>
org.apache.dubbo
</groupId>
<artifactId>
dubbo-serialization-fastjson2
</artifactId>
</dependency>
<dependency>
<groupId>
org.apache.dubbo
</groupId>
<artifactId>
dubbo-metadata-report-zookeeper
</artifactId>
...
...
starters/dubbo-spring-boot-starter/src/main/java/com/schbrain/framework/autoconfigure/dubbo/filter/DubboExceptionFilter.java
View file @
77232905
...
...
@@ -3,7 +3,6 @@ package com.schbrain.framework.autoconfigure.dubbo.filter;
import
cn.hutool.core.exceptions.ExceptionUtil
;
import
com.schbrain.common.exception.BaseException
;
import
com.schbrain.common.exception.ParamInvalidException
;
import
com.schbrain.common.util.support.ValidationMessageBuilder
;
import
lombok.extern.slf4j.Slf4j
;
import
org.apache.dubbo.common.constants.CommonConstants
;
import
org.apache.dubbo.common.extension.Activate
;
...
...
@@ -14,6 +13,8 @@ import org.apache.dubbo.rpc.service.GenericService;
import
javax.validation.ConstraintViolationException
;
import
java.util.Arrays
;
import
static
com
.
schbrain
.
common
.
util
.
support
.
ValidationMessageBuilder
.
buildConstraintViolationErrorMsg
;
/**
* @author liaozan
* @since 2022/1/19
...
...
@@ -47,7 +48,7 @@ public class DubboExceptionFilter extends ExceptionFilter {
protected
ParamInvalidException
createParamInvalidException
(
Invocation
invocation
,
ConstraintViolationException
cause
)
{
String
serviceName
=
invocation
.
getInvoker
().
getInterface
().
getSimpleName
();
String
methodName
=
invocation
.
getMethodName
();
String
errorMsg
=
ValidationMessageBuilder
.
buildConstraintViolationErrorMsg
(
cause
.
getConstraintViolations
());
String
errorMsg
=
buildConstraintViolationErrorMsg
(
cause
.
getConstraintViolations
());
return
new
ParamInvalidException
(
String
.
format
(
"%s.%s %s"
,
serviceName
,
methodName
,
errorMsg
));
}
...
...
starters/elasticsearch-spring-boot-starter/pom.xml
View file @
77232905
starters/logger-spring-boot-starter/src/main/java/com/schbrain/framework/autoconfigure/logger/LoggerConfigurationInitializer.java
View file @
77232905
...
...
@@ -20,11 +20,11 @@ import net.logstash.logback.appender.LogstashTcpSocketAppender;
import
net.logstash.logback.encoder.LogstashEncoder
;
import
net.logstash.logback.fieldnames.ShortenedFieldNames
;
import
org.apache.commons.collections4.IteratorUtils
;
import
org.apache.commons.lang3.StringUtils
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.boot.cloud.CloudPlatform
;
import
org.springframework.core.env.ConfigurableEnvironment
;
import
org.springframework.util.CollectionUtils
;
import
org.springframework.util.StringUtils
;
import
java.nio.file.Paths
;
import
java.util.List
;
...
...
@@ -86,7 +86,7 @@ public class LoggerConfigurationInitializer {
}
if
(
properties
.
isEnableJsonLogWriteToLogstash
()
||
EnvUtils
.
runningOnCloudPlatform
(
environment
))
{
if
(
!
StringUtils
.
hasText
(
properties
.
getLogstashAddress
()))
{
if
(
StringUtils
.
isBlank
(
properties
.
getLogstashAddress
()))
{
log
.
warn
(
"logstash address is unset, will NOT write log to logstash"
);
return
;
}
...
...
starters/logger-spring-boot-starter/src/main/java/com/schbrain/framework/autoconfigure/logger/apollo/DynamicLoggerConfiguration.java
View file @
77232905
...
...
@@ -2,11 +2,10 @@ package com.schbrain.framework.autoconfigure.logger.apollo;
import
com.ctrip.framework.apollo.Config
;
import
com.ctrip.framework.apollo.ConfigService
;
import
com.schbrain.framework.autoconfigure.logger.apollo.listener.LoggingLevelChangeListener
;
import
com.schbrain.framework.autoconfigure.logger.properties.LoggerProperties
;
import
lombok.extern.slf4j.Slf4j
;
import
org.apache.commons.lang3.StringUtils
;
import
org.springframework.boot.logging.LoggingSystem
;
import
org.springframework.util.StringUtils
;
/**
* 动态日志配置
...
...
@@ -23,7 +22,7 @@ public class DynamicLoggerConfiguration {
private
void
listenToLoggingLevelChange
(
LoggingSystem
loggingSystem
,
LoggerProperties
loggerProperties
)
{
String
loggerNamespace
=
loggerProperties
.
getNamespace
();
if
(
!
StringUtils
.
hasText
(
loggerNamespace
))
{
if
(
StringUtils
.
isBlank
(
loggerNamespace
))
{
log
.
debug
(
"logger level reload is disabled"
);
return
;
}
...
...
starters/logger-spring-boot-starter/src/main/java/com/schbrain/framework/autoconfigure/logger/apollo/
listener/
LoggingLevelChangeListener.java
→
starters/logger-spring-boot-starter/src/main/java/com/schbrain/framework/autoconfigure/logger/apollo/LoggingLevelChangeListener.java
View file @
77232905
package
com.schbrain.framework.autoconfigure.logger.apollo
.listener
;
package
com.schbrain.framework.autoconfigure.logger.apollo
;
import
com.ctrip.framework.apollo.ConfigChangeListener
;
import
com.ctrip.framework.apollo.enums.PropertyChangeType
;
...
...
starters/logger-spring-boot-starter/src/main/java/com/schbrain/framework/autoconfigure/logger/listener/LoggerConfigLoadedEventListener.java
View file @
77232905
...
...
@@ -12,12 +12,12 @@ import com.schbrain.framework.autoconfigure.apollo.event.ConfigLoadedEvent;
import
com.schbrain.framework.autoconfigure.apollo.event.listener.GenericConfigLoadedEventListener
;
import
com.schbrain.framework.autoconfigure.logger.LoggerConfigurationInitializer
;
import
com.schbrain.framework.autoconfigure.logger.properties.LoggerProperties
;
import
org.apache.commons.lang3.StringUtils
;
import
org.springframework.boot.context.logging.LoggingApplicationListener
;
import
org.springframework.boot.logging.LogFile
;
import
org.springframework.boot.logging.LoggingSystem
;
import
org.springframework.context.ConfigurableApplicationContext
;
import
org.springframework.core.env.ConfigurableEnvironment
;
import
org.springframework.util.StringUtils
;
import
java.io.IOException
;
import
java.nio.file.Files
;
...
...
@@ -71,7 +71,7 @@ public class LoggerConfigLoadedEventListener extends GenericConfigLoadedEventLis
}
ConfigFile
loggingConfiguration
=
ConfigService
.
getConfigFile
(
logConfigNamespace
,
ConfigFileFormat
.
XML
);
String
content
=
loggingConfiguration
.
getContent
();
if
(
!
StringUtils
.
hasText
(
content
))
{
if
(
StringUtils
.
isBlank
(
content
))
{
log
.
warn
(
"empty logging configuration, reinitialize loggingSystem is disabled"
);
return
;
}
...
...
starters/oss-spring-boot-starter/src/main/java/com/schbrain/framework/autoconfigure/oss/util/OssUtils.java
View file @
77232905
...
...
@@ -22,7 +22,7 @@ import com.schbrain.framework.autoconfigure.oss.exception.OssException;
import
com.schbrain.framework.autoconfigure.oss.properties.OssProperties
;
import
com.schbrain.framework.autoconfigure.oss.properties.OssProperties.StsProperties
;
import
lombok.extern.slf4j.Slf4j
;
import
org.
springframework.util
.StringUtils
;
import
org.
apache.commons.lang3
.StringUtils
;
import
java.io.File
;
import
java.io.InputStream
;
...
...
@@ -210,7 +210,7 @@ public class OssUtils {
}
public
static
String
replaceWithDomain
(
String
domain
,
String
ossUrl
)
{
if
(
!
StringUtils
.
hasText
(
domain
))
{
if
(
StringUtils
.
isBlank
(
domain
))
{
return
ossUrl
;
}
domain
=
URLUtil
.
normalize
(
domain
);
...
...
@@ -268,7 +268,7 @@ public class OssUtils {
ValidateUtils
.
notEmpty
(
bucket
,
"bucket can not be empty"
);
ValidateUtils
.
notEmpty
(
objectKeys
,
"objectKeys can not be empty"
);
String
notExistKeys
=
objectKeys
.
stream
().
filter
(
key
->
!
exist
(
bucket
,
key
)).
collect
(
Collectors
.
joining
(
","
));
if
(
StringUtils
.
hasText
(
notExistKeys
))
{
if
(
StringUtils
.
isNotBlank
(
notExistKeys
))
{
String
errorMsg
=
StrFormatter
.
format
(
"objectKeys:[{}] not exist"
,
notExistKeys
);
return
DeleteResult
.
fail
(
bucket
,
objectKeys
,
errorMsg
);
}
...
...
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