Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
M
matrix
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
CI / CD
CI / CD
Pipelines
Schedules
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
mall
arch
matrix
Commits
913c9dc5
Commit
913c9dc5
authored
Oct 21, 2019
by
李秋伟
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'dev' into 'master'
Dev See merge request mall/arch/matrix!23
parents
2f91c2a8
fb55803a
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
87 additions
and
23 deletions
+87
-23
pom.xml
common-util/pom.xml
+4
-0
WebUtil.java
common-util/src/main/java/com/secoo/mall/common/util/web/WebUtil.java
+1
-1
MybatisConfig.java
mybatis-starter/src/main/java/com/secoo/mall/mybatis/config/MybatisConfig.java
+5
-0
ProtocolExceptionHandler.java
protocol-starter/src/main/java/com/secoo/mall/common/handler/ProtocolExceptionHandler.java
+28
-15
AbsExceptionProcessor.java
protocol-starter/src/main/java/com/secoo/mall/common/processor/AbsExceptionProcessor.java
+16
-0
ExceptionProcessor.java
protocol-starter/src/main/java/com/secoo/mall/common/processor/ExceptionProcessor.java
+17
-0
ResponseExceptionFilter.java
protocol-starter/src/main/java/com/secoo/mall/dubbo/filter/ResponseExceptionFilter.java
+9
-5
ApiIgnoreJson.java
protocol-starter/src/main/java/com/secoo/mall/web/annotation/ApiIgnoreJson.java
+5
-0
org.apache.dubbo.rpc.Filter
protocol-starter/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.rpc.Filter
+2
-2
No files found.
common-util/pom.xml
View file @
913c9dc5
...
@@ -63,6 +63,10 @@
...
@@ -63,6 +63,10 @@
<scope>
provided
</scope>
<scope>
provided
</scope>
<optional>
true
</optional>
<optional>
true
</optional>
</dependency>
</dependency>
<dependency>
<groupId>
org.projectlombok
</groupId>
<artifactId>
lombok
</artifactId>
</dependency>
</dependencies>
</dependencies>
...
...
common-util/src/main/java/com/secoo/mall/common/util/web/WebUtil.java
View file @
913c9dc5
...
@@ -41,7 +41,7 @@ public class WebUtil {
...
@@ -41,7 +41,7 @@ public class WebUtil {
}
}
public
static
<
T
>
void
setAttribute
(
String
name
,
T
obj
)
{
public
static
<
T
>
void
setAttribute
(
String
name
,
T
obj
)
{
getRequest
().
setAttribute
(
sessionUser
,
obj
);
getRequest
().
setAttribute
(
name
,
obj
);
}
}
public
static
<
T
>
void
setSessionUser
(
T
obj
)
{
public
static
<
T
>
void
setSessionUser
(
T
obj
)
{
...
...
mybatis-starter/src/main/java/com/secoo/mall/mybatis/config/MybatisConfig.java
View file @
913c9dc5
package
com
.
secoo
.
mall
.
mybatis
.
config
;
package
com
.
secoo
.
mall
.
mybatis
.
config
;
import
com.baomidou.mybatisplus.annotation.IdType
;
import
com.baomidou.mybatisplus.annotation.IdType
;
import
com.baomidou.mybatisplus.autoconfigure.MybatisPlusProperties
;
import
com.baomidou.mybatisplus.core.MybatisConfiguration
;
import
com.baomidou.mybatisplus.core.MybatisConfiguration
;
import
com.baomidou.mybatisplus.core.config.GlobalConfig
;
import
com.baomidou.mybatisplus.core.config.GlobalConfig
;
import
com.baomidou.mybatisplus.extension.plugins.PaginationInterceptor
;
import
com.baomidou.mybatisplus.extension.plugins.PaginationInterceptor
;
...
@@ -17,6 +18,7 @@ import org.springframework.context.annotation.Bean;
...
@@ -17,6 +18,7 @@ import org.springframework.context.annotation.Bean;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.core.io.support.PathMatchingResourcePatternResolver
;
import
org.springframework.core.io.support.PathMatchingResourcePatternResolver
;
import
javax.annotation.Resource
;
import
javax.sql.DataSource
;
import
javax.sql.DataSource
;
import
java.util.List
;
import
java.util.List
;
import
java.util.stream.Collectors
;
import
java.util.stream.Collectors
;
...
@@ -29,6 +31,9 @@ public class MybatisConfig {
...
@@ -29,6 +31,9 @@ public class MybatisConfig {
@Value
(
"${spring.profiles.active}"
)
@Value
(
"${spring.profiles.active}"
)
private
String
profile
;
private
String
profile
;
@Resource
private
MybatisPlusProperties
mybatisPlusProperties
;
@Bean
(
"mybatisSqlSession"
)
@Bean
(
"mybatisSqlSession"
)
public
SqlSessionFactory
sqlSessionFactory
(
DataSource
dataSource
,
GlobalConfig
globalConfig
)
throws
Exception
{
public
SqlSessionFactory
sqlSessionFactory
(
DataSource
dataSource
,
GlobalConfig
globalConfig
)
throws
Exception
{
MybatisSqlSessionFactoryBean
sqlSessionFactory
=
new
MybatisSqlSessionFactoryBean
();
MybatisSqlSessionFactoryBean
sqlSessionFactory
=
new
MybatisSqlSessionFactoryBean
();
...
...
protocol-starter/src/main/java/com/secoo/mall/common/handler/ProtocolExceptionHandler.java
View file @
913c9dc5
...
@@ -4,8 +4,10 @@ import com.secoo.mall.common.core.errorcode.CommonErrorCode;
...
@@ -4,8 +4,10 @@ import com.secoo.mall.common.core.errorcode.CommonErrorCode;
import
com.secoo.mall.common.core.exception.BusinessException
;
import
com.secoo.mall.common.core.exception.BusinessException
;
import
com.secoo.mall.common.core.exception.ParameterException
;
import
com.secoo.mall.common.core.exception.ParameterException
;
import
com.secoo.mall.common.core.exception.SystemInternalException
;
import
com.secoo.mall.common.core.exception.SystemInternalException
;
import
com.secoo.mall.common.processor.ExceptionProcessor
;
import
com.secoo.mall.common.util.log.LoggerUtil
;
import
com.secoo.mall.common.util.log.LoggerUtil
;
import
com.secoo.mall.common.util.response.ResponseUtil
;
import
com.secoo.mall.common.util.response.ResponseUtil
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.context.MessageSource
;
import
org.springframework.context.MessageSource
;
import
org.springframework.context.i18n.LocaleContextHolder
;
import
org.springframework.context.i18n.LocaleContextHolder
;
import
org.springframework.web.bind.annotation.ExceptionHandler
;
import
org.springframework.web.bind.annotation.ExceptionHandler
;
...
@@ -17,23 +19,34 @@ public class ProtocolExceptionHandler {
...
@@ -17,23 +19,34 @@ public class ProtocolExceptionHandler {
@Resource
@Resource
private
MessageSource
messageSource
;
private
MessageSource
messageSource
;
@ExceptionHandler
(
BusinessException
.
class
)
@Autowired
(
required
=
false
)
public
Object
businessExcepstionHandler
(
BusinessException
e
)
{
private
ExceptionProcessor
exceptionProcessor
;
LoggerUtil
.
warn
(
"businessException info:"
,
e
);
return
ResponseUtil
.
getFailResponse
(
e
.
getCode
(),
getMsg
(
e
));
}
@ExceptionHandler
(
ParameterException
.
class
)
public
Object
parameterExceptionHandler
(
ParameterException
e
)
{
String
msg
=
getMsg
(
e
);
LoggerUtil
.
info
(
msg
);
return
ResponseUtil
.
getFailResponse
(
e
.
getCode
(),
msg
);
}
@ExceptionHandler
({
SystemInternalException
.
class
,
Exception
.
class
})
@ExceptionHandler
({
Exception
.
class
})
public
Object
exceptionHandler
(
Exception
e
)
{
public
Object
exceptionHandler
(
Exception
e
)
{
LoggerUtil
.
error
(
e
);
try
{
return
ResponseUtil
.
getFailResponse
(
CommonErrorCode
.
SYSTEM_INTERNAL_EXCEPTION
.
getCode
(),
CommonErrorCode
.
SYSTEM_INTERNAL_EXCEPTION
.
getMsg
());
if
(
exceptionProcessor
==
null
)
{
throw
e
;
}
exceptionProcessor
.
process
(
e
);
}
catch
(
ParameterException
ex
)
{
String
msg
=
getMsg
(
ex
);
LoggerUtil
.
info
(
msg
);
return
ResponseUtil
.
getFailResponse
(
ex
.
getCode
(),
msg
);
}
catch
(
SystemInternalException
ex
)
{
LoggerUtil
.
error
(
e
);
return
ResponseUtil
.
getFailResponse
(
CommonErrorCode
.
SYSTEM_INTERNAL_EXCEPTION
.
getCode
(),
CommonErrorCode
.
SYSTEM_INTERNAL_EXCEPTION
.
getMsg
());
}
catch
(
BusinessException
ex
)
{
LoggerUtil
.
warn
(
"businessException info:"
,
ex
);
return
ResponseUtil
.
getFailResponse
(
ex
.
getCode
(),
getMsg
(
ex
));
}
catch
(
Exception
ex
)
{
LoggerUtil
.
error
(
ex
);
return
ResponseUtil
.
getFailResponse
(
CommonErrorCode
.
SYSTEM_INTERNAL_EXCEPTION
.
getCode
(),
CommonErrorCode
.
SYSTEM_INTERNAL_EXCEPTION
.
getMsg
());
}
return
null
;
}
}
...
...
protocol-starter/src/main/java/com/secoo/mall/common/processor/AbsExceptionProcessor.java
0 → 100644
View file @
913c9dc5
package
com
.
secoo
.
mall
.
common
.
processor
;
import
lombok.extern.slf4j.Slf4j
;
@Slf4j
public
abstract
class
AbsExceptionProcessor
implements
ExceptionProcessor
{
public
void
process
(
Exception
e
)
throws
Exception
{
log
.
warn
(
"warn:"
,
e
);
convertException
(
e
);
throw
e
;
}
protected
abstract
void
convertException
(
Exception
e
);
}
protocol-starter/src/main/java/com/secoo/mall/common/processor/ExceptionProcessor.java
0 → 100644
View file @
913c9dc5
package
com
.
secoo
.
mall
.
common
.
processor
;
import
com.secoo.mall.common.core.errorcode.ErrorCode
;
import
com.secoo.mall.common.core.exception.BusinessException
;
import
com.secoo.mall.common.util.spring.SpringUtil
;
import
java.util.Map
;
public
interface
ExceptionProcessor
{
/**
* 处理异常
* @param e
* @return
*/
void
process
(
Exception
e
)
throws
Exception
;
}
protocol-starter/src/main/java/com/secoo/mall/dubbo/filter/
Default
ExceptionFilter.java
→
protocol-starter/src/main/java/com/secoo/mall/dubbo/filter/
Response
ExceptionFilter.java
View file @
913c9dc5
...
@@ -16,15 +16,19 @@ import org.springframework.web.method.annotation.ExceptionHandlerMethodResolver;
...
@@ -16,15 +16,19 @@ import org.springframework.web.method.annotation.ExceptionHandlerMethodResolver;
import
java.lang.reflect.Method
;
import
java.lang.reflect.Method
;
/**
* 统一拦截异常。
* 不向消费端抛出异常,而是形成response结构
*/
@Activate
(
@Activate
(
group
=
{
CommonConstants
.
PROVIDER
}
,
order
=
1000
group
=
{
CommonConstants
.
PROVIDER
}
)
)
public
class
Default
ExceptionFilter
extends
ExceptionFilter
implements
Filter
{
public
class
Response
ExceptionFilter
extends
ExceptionFilter
implements
Filter
{
private
Logger
log
=
LoggerFactory
.
getLogger
(
Default
ExceptionFilter
.
class
);
private
Logger
log
=
LoggerFactory
.
getLogger
(
Response
ExceptionFilter
.
class
);
public
Default
ExceptionFilter
()
{
public
Response
ExceptionFilter
()
{
super
.
listener
=
new
Default
ExceptionFilter
.
ExceptionListener
();
super
.
listener
=
new
Response
ExceptionFilter
.
ExceptionListener
();
}
}
...
...
protocol-starter/src/main/java/com/secoo/mall/web/annotation/ApiIgnoreJson.java
View file @
913c9dc5
package
com
.
secoo
.
mall
.
web
.
annotation
;
package
com
.
secoo
.
mall
.
web
.
annotation
;
import
java.lang.annotation.*
;
@Target
(
ElementType
.
METHOD
)
@Retention
(
RetentionPolicy
.
RUNTIME
)
@Documented
public
@interface
ApiIgnoreJson
{
public
@interface
ApiIgnoreJson
{
}
}
protocol-starter/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.rpc.Filter
View file @
913c9dc5
exception=com.secoo.mall.dubbo.filter.DefaultExceptionFilter
exception=com.secoo.mall.dubbo.filter.ResponseExceptionFilter
\ No newline at end of file
\ No newline at end of file
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