Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
J
jeecg-boot
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
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
chenjunxiong
jeecg-boot
Commits
4da1948c
Commit
4da1948c
authored
Sep 14, 2021
by
zhangdaiscott
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
路由网关禁用Demo配置后,系统仍可以通过网关路由到Demo服务。issues/I49457
parent
55ebea88
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
42 additions
and
17 deletions
+42
-17
jeecg-boot/jeecg-boot-module-system/src/main/java/org/jeecg/modules/system/service/impl/SysGatewayRouteServiceImpl.java
+1
-3
jeecg-boot/jeecg-cloud-module/jeecg-cloud-gateway/src/main/java/org/jeecg/loader/DynamicRouteLoader.java
+12
-6
jeecg-boot/jeecg-cloud-module/jeecg-cloud-gateway/src/main/java/org/jeecg/loader/DynamicRouteService.java
+7
-8
jeecg-boot/jeecg-cloud-module/jeecg-cloud-gateway/src/main/java/org/jeecg/loader/MyRouteDefinition.java
+22
-0
No files found.
jeecg-boot/jeecg-boot-module-system/src/main/java/org/jeecg/modules/system/service/impl/SysGatewayRouteServiceImpl.java
View file @
4da1948c
...
@@ -17,9 +17,7 @@ import org.springframework.data.redis.core.RedisTemplate;
...
@@ -17,9 +17,7 @@ import org.springframework.data.redis.core.RedisTemplate;
import
org.springframework.stereotype.Service
;
import
org.springframework.stereotype.Service
;
import
org.springframework.transaction.annotation.Transactional
;
import
org.springframework.transaction.annotation.Transactional
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.List
;
import
java.util.Map
;
/**
/**
* @Description: gateway路由管理
* @Description: gateway路由管理
...
@@ -37,7 +35,7 @@ public class SysGatewayRouteServiceImpl extends ServiceImpl<SysGatewayRouteMappe
...
@@ -37,7 +35,7 @@ public class SysGatewayRouteServiceImpl extends ServiceImpl<SysGatewayRouteMappe
@Override
@Override
public
void
addRoute2Redis
(
String
key
)
{
public
void
addRoute2Redis
(
String
key
)
{
List
<
SysGatewayRoute
>
ls
=
this
.
list
(
new
LambdaQueryWrapper
<
SysGatewayRoute
>()
.
eq
(
SysGatewayRoute:
:
getStatus
,
1
)
);
List
<
SysGatewayRoute
>
ls
=
this
.
list
(
new
LambdaQueryWrapper
<
SysGatewayRoute
>());
redisTemplate
.
opsForValue
().
set
(
key
,
JSON
.
toJSONString
(
ls
));
redisTemplate
.
opsForValue
().
set
(
key
,
JSON
.
toJSONString
(
ls
));
}
}
...
...
jeecg-boot/jeecg-cloud-module/jeecg-cloud-gateway/src/main/java/org/jeecg/loader/DynamicRouteLoader.java
View file @
4da1948c
...
@@ -128,7 +128,7 @@ public class DynamicRouteLoader implements ApplicationEventPublisherAware {
...
@@ -128,7 +128,7 @@ public class DynamicRouteLoader implements ApplicationEventPublisherAware {
* @return
* @return
*/
*/
private
void
loadRoutesByRedis
()
{
private
void
loadRoutesByRedis
()
{
List
<
RouteDefinition
>
routes
=
Lists
.
newArrayList
();
List
<
My
RouteDefinition
>
routes
=
Lists
.
newArrayList
();
configService
=
createConfigService
();
configService
=
createConfigService
();
if
(
configService
==
null
)
{
if
(
configService
==
null
)
{
log
.
warn
(
"initConfigService fail"
);
log
.
warn
(
"initConfigService fail"
);
...
@@ -143,9 +143,14 @@ public class DynamicRouteLoader implements ApplicationEventPublisherAware {
...
@@ -143,9 +143,14 @@ public class DynamicRouteLoader implements ApplicationEventPublisherAware {
e
.
printStackTrace
();
e
.
printStackTrace
();
}
}
}
}
for
(
RouteDefinition
definition
:
routes
)
{
for
(
My
RouteDefinition
definition
:
routes
)
{
log
.
info
(
"update route : {}"
,
definition
.
toString
());
log
.
info
(
"update route : {}"
,
definition
.
toString
());
dynamicRouteService
.
add
(
definition
);
Integer
status
=
definition
.
getStatus
();
if
(
status
.
equals
(
0
)){
dynamicRouteService
.
delete
(
definition
.
getId
());
}
else
{
dynamicRouteService
.
add
(
definition
);
}
}
}
this
.
publisher
.
publishEvent
(
new
RefreshRoutesEvent
(
this
));
this
.
publisher
.
publishEvent
(
new
RefreshRoutesEvent
(
this
));
}
}
...
@@ -161,12 +166,13 @@ public class DynamicRouteLoader implements ApplicationEventPublisherAware {
...
@@ -161,12 +166,13 @@ public class DynamicRouteLoader implements ApplicationEventPublisherAware {
* @return
* @return
*/
*/
public
static
List
<
RouteDefinition
>
getRoutesByJson
(
JSONArray
array
)
throws
URISyntaxException
{
public
static
List
<
My
RouteDefinition
>
getRoutesByJson
(
JSONArray
array
)
throws
URISyntaxException
{
List
<
RouteDefinition
>
ls
=
new
ArrayList
<>();
List
<
My
RouteDefinition
>
ls
=
new
ArrayList
<>();
for
(
int
i
=
0
;
i
<
array
.
size
();
i
++)
{
for
(
int
i
=
0
;
i
<
array
.
size
();
i
++)
{
JSONObject
obj
=
array
.
getJSONObject
(
i
);
JSONObject
obj
=
array
.
getJSONObject
(
i
);
RouteDefinition
route
=
new
RouteDefinition
();
MyRouteDefinition
route
=
new
My
RouteDefinition
();
route
.
setId
(
obj
.
getString
(
"routerId"
));
route
.
setId
(
obj
.
getString
(
"routerId"
));
route
.
setStatus
(
obj
.
getInteger
(
"status"
));
Object
uri
=
obj
.
get
(
"uri"
);
Object
uri
=
obj
.
get
(
"uri"
);
if
(
uri
==
null
)
{
if
(
uri
==
null
)
{
route
.
setUri
(
new
URI
(
"lb://"
+
obj
.
getString
(
"name"
)));
route
.
setUri
(
new
URI
(
"lb://"
+
obj
.
getString
(
"name"
)));
...
...
jeecg-boot/jeecg-cloud-module/jeecg-cloud-gateway/src/main/java/org/jeecg/loader/DynamicRouteService.java
View file @
4da1948c
...
@@ -47,14 +47,13 @@ public class DynamicRouteService implements ApplicationEventPublisherAware {
...
@@ -47,14 +47,13 @@ public class DynamicRouteService implements ApplicationEventPublisherAware {
* @param id
* @param id
* @return
* @return
*/
*/
public
synchronized
Mono
<
ResponseEntity
<
Object
>>
delete
(
String
id
)
{
public
synchronized
void
delete
(
String
id
)
{
return
this
.
repository
.
delete
(
Mono
.
just
(
id
)).
then
(
Mono
.
defer
(()
->
{
try
{
return
Mono
.
just
(
ResponseEntity
.
ok
().
build
());
repository
.
delete
(
Mono
.
just
(
id
)).
subscribe
();
})).
onErrorResume
((
t
)
->
{
this
.
publisher
.
publishEvent
(
new
RefreshRoutesEvent
(
this
));
return
t
instanceof
NotFoundException
;
}
catch
(
Exception
e
){
},
(
t
)
->
{
e
.
printStackTrace
();
return
Mono
.
just
(
ResponseEntity
.
notFound
().
build
());
}
});
}
}
/**
/**
...
...
jeecg-boot/jeecg-cloud-module/jeecg-cloud-gateway/src/main/java/org/jeecg/loader/MyRouteDefinition.java
0 → 100644
View file @
4da1948c
package
org
.
jeecg
.
loader
;
import
org.springframework.cloud.gateway.route.RouteDefinition
;
/**
* 自定义RouteDefinition
* @author zyf
*/
public
class
MyRouteDefinition
extends
RouteDefinition
{
/**
* 路由状态
*/
private
Integer
status
;
public
Integer
getStatus
()
{
return
status
;
}
public
void
setStatus
(
Integer
status
)
{
this
.
status
=
status
;
}
}
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