Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
D
discovery
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
谢捷峰
discovery
Commits
dd1d1ff0
Commit
dd1d1ff0
authored
May 07, 2019
by
Nepxion
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix:Zuul Filter添加Header在MyDiscoveryEnabledStrategy里无法获取
parent
7d1c86ad
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
32 additions
and
6 deletions
+32
-6
discovery-plugin-strategy-starter-zuul/src/main/java/com/nepxion/discovery/plugin/strategy/zuul/adapter/DefaultDiscoveryEnabledAdapter.java
+20
-3
discovery-plugin-strategy-starter-zuul/src/main/java/com/nepxion/discovery/plugin/strategy/zuul/context/ZuulStrategyContextHolder.java
+7
-0
discovery-springcloud-example-gateway/src/main/java/com/nepxion/discovery/plugin/example/gateway/impl/MyGatewayFilter.java
+4
-2
discovery-springcloud-example-zuul/src/main/java/com/nepxion/discovery/plugin/example/zuul/impl/MyZuulFilter.java
+1
-1
No files found.
discovery-plugin-strategy-starter-zuul/src/main/java/com/nepxion/discovery/plugin/strategy/zuul/adapter/DefaultDiscoveryEnabledAdapter.java
View file @
dd1d1ff0
...
...
@@ -11,6 +11,7 @@ package com.nepxion.discovery.plugin.strategy.zuul.adapter;
import
javax.servlet.http.HttpServletRequest
;
import
org.apache.commons.lang3.StringUtils
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.beans.factory.annotation.Autowired
;
...
...
@@ -37,7 +38,12 @@ public class DefaultDiscoveryEnabledAdapter extends AbstractDiscoveryEnabledAdap
return
null
;
}
return
request
.
getHeader
(
DiscoveryConstant
.
N_D_VERSION
);
String
version
=
request
.
getHeader
(
DiscoveryConstant
.
N_D_VERSION
);
if
(
StringUtils
.
isEmpty
(
version
))
{
version
=
zuulStrategyContextHolder
.
getZuulRequestHeaders
().
get
(
DiscoveryConstant
.
N_D_VERSION
);
}
return
version
;
}
@Override
...
...
@@ -51,7 +57,12 @@ public class DefaultDiscoveryEnabledAdapter extends AbstractDiscoveryEnabledAdap
return
null
;
}
return
request
.
getHeader
(
DiscoveryConstant
.
N_D_REGION
);
String
region
=
request
.
getHeader
(
DiscoveryConstant
.
N_D_REGION
);
if
(
StringUtils
.
isEmpty
(
region
))
{
region
=
zuulStrategyContextHolder
.
getZuulRequestHeaders
().
get
(
DiscoveryConstant
.
N_D_REGION
);
}
return
region
;
}
@Override
...
...
@@ -65,6 +76,11 @@ public class DefaultDiscoveryEnabledAdapter extends AbstractDiscoveryEnabledAdap
return
null
;
}
return
request
.
getHeader
(
DiscoveryConstant
.
N_D_ADDRESS
);
String
address
=
request
.
getHeader
(
DiscoveryConstant
.
N_D_ADDRESS
);
if
(
StringUtils
.
isEmpty
(
address
))
{
address
=
zuulStrategyContextHolder
.
getZuulRequestHeaders
().
get
(
DiscoveryConstant
.
N_D_ADDRESS
);
}
return
address
;
}
}
\ No newline at end of file
discovery-plugin-strategy-starter-zuul/src/main/java/com/nepxion/discovery/plugin/strategy/zuul/context/ZuulStrategyContextHolder.java
View file @
dd1d1ff0
...
...
@@ -10,6 +10,8 @@ package com.nepxion.discovery.plugin.strategy.zuul.context;
* @version 1.0
*/
import
java.util.Map
;
import
javax.servlet.http.HttpServletRequest
;
import
com.netflix.zuul.context.RequestContext
;
...
...
@@ -23,4 +25,8 @@ public class ZuulStrategyContextHolder {
return
request
;
}
public
Map
<
String
,
String
>
getZuulRequestHeaders
()
{
return
RequestContext
.
getCurrentContext
().
getZuulRequestHeaders
();
}
}
\ No newline at end of file
discovery-springcloud-example-gateway/src/main/java/com/nepxion/discovery/plugin/example/gateway/impl/MyGatewayFilter.java
View file @
dd1d1ff0
...
...
@@ -20,7 +20,7 @@ import org.springframework.web.server.ServerWebExchange;
public
class
MyGatewayFilter
implements
GlobalFilter
,
Ordered
{
@Override
public
Mono
<
Void
>
filter
(
ServerWebExchange
exchange
,
GatewayFilterChain
chain
)
{
ServerHttpRequest
newRequest
=
exchange
.
getRequest
().
mutate
().
header
(
"version"
,
"{\"discovery-springcloud-example-a\":\"1.0\", \"discovery-springcloud-example-b\":\"1.0\", \"discovery-springcloud-example-c\":\"1.0;1.2\"}"
).
build
();
ServerHttpRequest
newRequest
=
exchange
.
getRequest
().
mutate
().
header
(
"
n-d-
version"
,
"{\"discovery-springcloud-example-a\":\"1.0\", \"discovery-springcloud-example-b\":\"1.0\", \"discovery-springcloud-example-c\":\"1.0;1.2\"}"
).
build
();
ServerWebExchange
newExchange
=
exchange
.
mutate
().
request
(
newRequest
).
build
();
return
chain
.
filter
(
newExchange
);
...
...
@@ -28,6 +28,7 @@ public class MyGatewayFilter implements GlobalFilter, Ordered {
@Override
public
int
getOrder
()
{
return
-
200
;
// Order必须小于-400
return
-
500
;
}
}
\ No newline at end of file
discovery-springcloud-example-zuul/src/main/java/com/nepxion/discovery/plugin/example/zuul/impl/MyZuulFilter.java
View file @
dd1d1ff0
...
...
@@ -31,7 +31,7 @@ public class MyZuulFilter extends ZuulFilter {
@Override
public
Object
run
()
{
RequestContext
context
=
RequestContext
.
getCurrentContext
();
context
.
addZuulRequestHeader
(
"version"
,
"{\"discovery-springcloud-example-a\":\"1.0\", \"discovery-springcloud-example-b\":\"1.0\", \"discovery-springcloud-example-c\":\"1.0;1.2\"}"
);
context
.
addZuulRequestHeader
(
"
n-d-
version"
,
"{\"discovery-springcloud-example-a\":\"1.0\", \"discovery-springcloud-example-b\":\"1.0\", \"discovery-springcloud-example-c\":\"1.0;1.2\"}"
);
return
null
;
}
...
...
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