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
e20534a9
Commit
e20534a9
authored
Jul 28, 2018
by
Nepxion
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
提交Gateway扩展代码
parent
6a29d036
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
138 additions
and
2 deletions
+138
-2
discovery-plugin-strategy-extension-gateway/pom.xml
+6
-0
discovery-plugin-strategy-extension-gateway/src/main/java/com/nepxion/discovery/plugin/strategy/extension/gateway/configuration/GatewayStrategyAutoConfiguration.java
+30
-0
discovery-plugin-strategy-extension-gateway/src/main/java/com/nepxion/discovery/plugin/strategy/extension/gateway/context/GatewayStrategyContext.java
+59
-0
discovery-plugin-strategy-extension-gateway/src/main/java/com/nepxion/discovery/plugin/strategy/extension/gateway/filter/GatewayStrategyFilter.java
+40
-0
discovery-plugin-strategy-extension-gateway/src/main/resources/META-INF/spring.factories
+3
-2
No files found.
discovery-plugin-strategy-extension-gateway/pom.xml
View file @
e20534a9
...
@@ -19,5 +19,10 @@
...
@@ -19,5 +19,10 @@
<groupId>
${project.groupId}
</groupId>
<groupId>
${project.groupId}
</groupId>
<artifactId>
discovery-plugin-strategy
</artifactId>
<artifactId>
discovery-plugin-strategy
</artifactId>
</dependency>
</dependency>
<dependency>
<groupId>
org.springframework.cloud
</groupId>
<artifactId>
spring-cloud-starter-gateway
</artifactId>
</dependency>
</dependencies>
</dependencies>
</project>
</project>
\ No newline at end of file
discovery-plugin-strategy-extension-gateway/src/main/java/com/nepxion/discovery/plugin/strategy/extension/gateway/configuration/GatewayStrategyAutoConfiguration.java
0 → 100644
View file @
e20534a9
package
com
.
nepxion
.
discovery
.
plugin
.
strategy
.
extension
.
gateway
.
configuration
;
/**
* <p>Title: Nepxion Discovery</p>
* <p>Description: Nepxion Discovery</p>
* <p>Copyright: Copyright (c) 2017-2050</p>
* <p>Company: Nepxion</p>
* @author Haojun Ren
* @version 1.0
*/
import
org.springframework.boot.autoconfigure.AutoConfigureBefore
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnProperty
;
import
org.springframework.cloud.netflix.ribbon.RibbonClientConfiguration
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
com.nepxion.discovery.plugin.strategy.constant.StrategyConstant
;
import
com.nepxion.discovery.plugin.strategy.extension.gateway.filter.GatewayStrategyFilter
;
@Configuration
@AutoConfigureBefore
(
RibbonClientConfiguration
.
class
)
@ConditionalOnProperty
(
value
=
StrategyConstant
.
SPRING_APPLICATION_STRATEGY_CONTROL_ENABLED
,
matchIfMissing
=
true
)
public
class
GatewayStrategyAutoConfiguration
{
@Bean
public
GatewayStrategyFilter
gatewayStrategyFilter
()
{
return
new
GatewayStrategyFilter
();
}
}
\ No newline at end of file
discovery-plugin-strategy-extension-gateway/src/main/java/com/nepxion/discovery/plugin/strategy/extension/gateway/context/GatewayStrategyContext.java
0 → 100644
View file @
e20534a9
package
com
.
nepxion
.
discovery
.
plugin
.
strategy
.
extension
.
gateway
.
context
;
/**
* <p>Title: Nepxion Discovery</p>
* <p>Description: Nepxion Discovery</p>
* <p>Copyright: Copyright (c) 2017-2050</p>
* <p>Company: Nepxion</p>
* @author Haojun Ren
* @version 1.0
*/
import
org.apache.commons.lang3.builder.EqualsBuilder
;
import
org.apache.commons.lang3.builder.HashCodeBuilder
;
import
org.apache.commons.lang3.builder.ToStringBuilder
;
import
org.apache.commons.lang3.builder.ToStringStyle
;
import
org.springframework.web.server.ServerWebExchange
;
public
class
GatewayStrategyContext
{
private
static
final
ThreadLocal
<
GatewayStrategyContext
>
THREAD_LOCAL
=
new
InheritableThreadLocal
<
GatewayStrategyContext
>()
{
@Override
protected
GatewayStrategyContext
initialValue
()
{
return
new
GatewayStrategyContext
();
}
};
public
static
GatewayStrategyContext
getCurrentContext
()
{
return
THREAD_LOCAL
.
get
();
}
public
static
void
clearCurrentContext
()
{
THREAD_LOCAL
.
remove
();
}
private
ServerWebExchange
exchange
;
public
ServerWebExchange
getExchange
()
{
return
exchange
;
}
public
void
setExchange
(
ServerWebExchange
exchange
)
{
this
.
exchange
=
exchange
;
}
@Override
public
int
hashCode
()
{
return
HashCodeBuilder
.
reflectionHashCode
(
this
);
}
@Override
public
boolean
equals
(
Object
object
)
{
return
EqualsBuilder
.
reflectionEquals
(
this
,
object
);
}
@Override
public
String
toString
()
{
return
ToStringBuilder
.
reflectionToString
(
this
,
ToStringStyle
.
MULTI_LINE_STYLE
);
}
}
\ No newline at end of file
discovery-plugin-strategy-extension-gateway/src/main/java/com/nepxion/discovery/plugin/strategy/extension/gateway/filter/GatewayStrategyFilter.java
0 → 100644
View file @
e20534a9
package
com
.
nepxion
.
discovery
.
plugin
.
strategy
.
extension
.
gateway
.
filter
;
/**
* <p>Title: Nepxion Discovery</p>
* <p>Description: Nepxion Discovery</p>
* <p>Copyright: Copyright (c) 2017-2050</p>
* <p>Company: Nepxion</p>
* @author Haojun Ren
* @version 1.0
*/
import
reactor.core.publisher.Mono
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.cloud.gateway.filter.GatewayFilterChain
;
import
org.springframework.cloud.gateway.filter.GlobalFilter
;
import
org.springframework.core.Ordered
;
import
org.springframework.web.server.ServerWebExchange
;
import
com.nepxion.discovery.plugin.strategy.extension.gateway.context.GatewayStrategyContext
;
public
class
GatewayStrategyFilter
implements
GlobalFilter
,
Ordered
{
private
static
final
Logger
LOG
=
LoggerFactory
.
getLogger
(
GatewayStrategyFilter
.
class
);
@Override
public
Mono
<
Void
>
filter
(
ServerWebExchange
exchange
,
GatewayFilterChain
chain
)
{
LOG
.
debug
(
"Gateway strategy context is set with {}"
,
exchange
);
GatewayStrategyContext
.
getCurrentContext
().
setExchange
(
exchange
);
return
chain
.
filter
(
exchange
);
}
@Override
public
int
getOrder
()
{
return
-
400
;
}
}
\ No newline at end of file
discovery-plugin-strategy-extension-gateway/src/main/resources/META-INF/spring.factories
View file @
e20534a9
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
com.nepxion.discovery.plugin.strategy.configuration.StrategyAutoConfiguration
com.nepxion.discovery.plugin.strategy.configuration.StrategyAutoConfiguration,\
\ No newline at end of file
com.nepxion.discovery.plugin.strategy.extension.gateway.configuration.GatewayStrategyAutoConfiguration
\ 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