Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
A
afanti-open-api
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
JIRA
JIRA
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
java-ms
afanti-open-api
Commits
82fe890a
Commit
82fe890a
authored
Dec 19, 2024
by
王明生
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fixed: 解决http错误码太大问题,并后置休眠5秒逻辑
parent
ab760914
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
33 additions
and
18 deletions
+33
-18
AfantiOpenApiApplication.java
...com/afanticar/afantiopenapi/AfantiOpenApiApplication.java
+1
-1
CommonInterceptor.java
...com/afanticar/afantiopenapi/config/CommonInterceptor.java
+29
-9
WebMvcConfig.java
...java/com/afanticar/afantiopenapi/config/WebMvcConfig.java
+2
-2
BaseController.java
...om/afanticar/afantiopenapi/controller/BaseController.java
+1
-1
BaseService.java
...java/com/afanticar/afantiopenapi/service/BaseService.java
+0
-5
No files found.
src/main/java/com/afanticar/afantiopenapi/AfantiOpenApiApplication.java
View file @
82fe890a
...
@@ -21,7 +21,7 @@ import springfox.documentation.swagger2.annotations.EnableSwagger2;
...
@@ -21,7 +21,7 @@ import springfox.documentation.swagger2.annotations.EnableSwagger2;
public
class
AfantiOpenApiApplication
{
public
class
AfantiOpenApiApplication
{
public
static
void
main
(
String
[]
args
)
{
public
static
void
main
(
String
[]
args
)
{
System
.
setProperty
(
"mybatis - plus.configuration.log - impl"
,
"org.apache.ibatis.logging.stdout.StdOutImpl"
);
//
System.setProperty("mybatis - plus.configuration.log - impl", "org.apache.ibatis.logging.stdout.StdOutImpl");
SpringApplication
.
run
(
AfantiOpenApiApplication
.
class
,
args
);
SpringApplication
.
run
(
AfantiOpenApiApplication
.
class
,
args
);
}
}
...
...
src/main/java/com/afanticar/afantiopenapi/config/
Toke
nInterceptor.java
→
src/main/java/com/afanticar/afantiopenapi/config/
Commo
nInterceptor.java
View file @
82fe890a
...
@@ -5,26 +5,21 @@ import cn.hutool.core.util.StrUtil;
...
@@ -5,26 +5,21 @@ import cn.hutool.core.util.StrUtil;
import
com.afanticar.afantiopenapi.constant.Constant
;
import
com.afanticar.afantiopenapi.constant.Constant
;
import
com.afanticar.afantiopenapi.controller.BaseController
;
import
com.afanticar.afantiopenapi.controller.BaseController
;
import
com.afanticar.afantiopenapi.feign.AfantiCasFeign
;
import
com.afanticar.afantiopenapi.feign.AfantiCasFeign
;
import
com.afanticar.afantiopenapi.model.BaseResponse
;
import
com.afanticar.afantiopenapi.model.vo.TokenCheckVO
;
import
com.afanticar.afantiopenapi.model.vo.TokenCheckVO
;
import
com.afanticar.afantiopenapi.utils.JWTUtils
;
import
com.afanticar.afantiopenapi.utils.JWTUtils
;
import
com.alibaba.fastjson.JSONObject
;
import
com.alibaba.fastjson.JSONObject
;
import
feign.FeignException
;
import
feign.FeignException
;
import
lombok.Setter
;
import
lombok.extern.slf4j.Slf4j
;
import
lombok.extern.slf4j.Slf4j
;
import
org.
redisson.api.RBucket
;
import
org.
springframework.lang.Nullable
;
import
org.redisson.api.RLock
;
import
org.redisson.api.RedissonClient
;
import
org.redisson.api.RedissonClient
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.boot.context.properties.ConfigurationProperties
;
import
org.springframework.stereotype.Component
;
import
org.springframework.stereotype.Component
;
import
org.springframework.web.servlet.
HandlerInterceptor
;
import
org.springframework.web.servlet.
ModelAndView
;
import
org.springframework.web.servlet.handler.HandlerInterceptorAdapter
;
import
org.springframework.web.servlet.handler.HandlerInterceptorAdapter
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletResponse
;
import
javax.servlet.http.HttpServletResponse
;
import
java.util.Set
;
import
java.util.concurrent.TimeUnit
;
/**
/**
* @author chin
* @author chin
...
@@ -33,7 +28,7 @@ import java.util.concurrent.TimeUnit;
...
@@ -33,7 +28,7 @@ import java.util.concurrent.TimeUnit;
*/
*/
@Slf4j
@Slf4j
@Component
@Component
public
class
Toke
nInterceptor
extends
HandlerInterceptorAdapter
{
public
class
Commo
nInterceptor
extends
HandlerInterceptorAdapter
{
@Autowired
@Autowired
private
AfantiCasFeign
casFeign
;
private
AfantiCasFeign
casFeign
;
...
@@ -81,6 +76,31 @@ public class TokenInterceptor extends HandlerInterceptorAdapter {
...
@@ -81,6 +76,31 @@ public class TokenInterceptor extends HandlerInterceptorAdapter {
return
true
;
return
true
;
}
}
// @Override
// public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler,
// @Nullable Exception ex) throws Exception {
// if (response.getStatus() == 200) {
// try {
// Thread.sleep(5000);
// } catch (InterruptedException e) {
// throw new RuntimeException(e);
// }
// }
// }
@Override
public
void
postHandle
(
HttpServletRequest
request
,
HttpServletResponse
response
,
Object
handler
,
@Nullable
ModelAndView
modelAndView
)
throws
Exception
{
// 在当前请求的 Controller 方法调用之后,且在 DispatcherServlet 进行视图返回渲染之前被调用。
// 注意,只有当所属拦截器的 preHandle 方法返回值为 true 时,该拦截器的 postHandle 方法才会被调用.
try
{
Thread
.
sleep
(
5000
);
}
catch
(
InterruptedException
e
)
{
throw
new
RuntimeException
(
e
);
}
}
private
void
writeResponse
(
HttpServletResponse
response
,
String
msg
)
throws
Exception
{
private
void
writeResponse
(
HttpServletResponse
response
,
String
msg
)
throws
Exception
{
response
.
setCharacterEncoding
(
"UTF-8"
);
response
.
setCharacterEncoding
(
"UTF-8"
);
response
.
setStatus
(
HttpServletResponse
.
SC_UNAUTHORIZED
);
response
.
setStatus
(
HttpServletResponse
.
SC_UNAUTHORIZED
);
...
...
src/main/java/com/afanticar/afantiopenapi/config/WebMvcConfig.java
View file @
82fe890a
...
@@ -23,8 +23,8 @@ public class WebMvcConfig implements WebMvcConfigurer {
...
@@ -23,8 +23,8 @@ public class WebMvcConfig implements WebMvcConfigurer {
BydOpenController
bydOpenController
;
BydOpenController
bydOpenController
;
@Bean
@Bean
public
Toke
nInterceptor
getLoginInterceptor
(){
public
Commo
nInterceptor
getLoginInterceptor
(){
return
new
Toke
nInterceptor
();
return
new
Commo
nInterceptor
();
}
}
...
...
src/main/java/com/afanticar/afantiopenapi/controller/BaseController.java
View file @
82fe890a
...
@@ -123,7 +123,7 @@ public class BaseController extends HandlerInterceptorAdapter{
...
@@ -123,7 +123,7 @@ public class BaseController extends HandlerInterceptorAdapter{
@SneakyThrows
@SneakyThrows
public
static
void
setResponse
(
HttpServletResponse
response
,
Integer
errorCode
,
String
msg
)
{
public
static
void
setResponse
(
HttpServletResponse
response
,
Integer
errorCode
,
String
msg
)
{
response
.
setCharacterEncoding
(
"UTF-8"
);
response
.
setCharacterEncoding
(
"UTF-8"
);
response
.
setStatus
(
errorCode
);
response
.
setStatus
(
HttpServletResponse
.
SC_BAD_REQUEST
);
response
.
setContentType
(
"application/json"
);
response
.
setContentType
(
"application/json"
);
response
.
getWriter
().
append
(
JSONObject
.
toJSONString
(
BaseController
.
error
(
errorCode
.
toString
(),
msg
)));
response
.
getWriter
().
append
(
JSONObject
.
toJSONString
(
BaseController
.
error
(
errorCode
.
toString
(),
msg
)));
}
}
...
...
src/main/java/com/afanticar/afantiopenapi/service/BaseService.java
View file @
82fe890a
...
@@ -55,11 +55,6 @@ public class BaseService {
...
@@ -55,11 +55,6 @@ public class BaseService {
* @param limitPeriod 对应trySetRate中的rateInterval,即rate time interval
* @param limitPeriod 对应trySetRate中的rateInterval,即rate time interval
*/
*/
public
<
T
>
BaseResponse
<
T
>
pageApiLimit
(
String
dataType
,
Integer
limit
,
Integer
limitPeriod
)
{
public
<
T
>
BaseResponse
<
T
>
pageApiLimit
(
String
dataType
,
Integer
limit
,
Integer
limitPeriod
)
{
try
{
Thread
.
sleep
(
5000
);
}
catch
(
InterruptedException
e
)
{
throw
new
RuntimeException
(
e
);
}
String
header
=
"token"
;
String
header
=
"token"
;
String
fawKey
=
String
.
format
(
"%s:%s:limit"
,
dataType
,
header
);
String
fawKey
=
String
.
format
(
"%s:%s:limit"
,
dataType
,
header
);
RRateLimiter
rateLimiter
=
redissonClient
.
getRateLimiter
(
fawKey
);
RRateLimiter
rateLimiter
=
redissonClient
.
getRateLimiter
(
fawKey
);
...
...
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