Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
S
spring-cloud-netflix
Project
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
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
openSource
spring-cloud-netflix
Commits
bfb6ca6d
Commit
bfb6ca6d
authored
Dec 05, 2014
by
Dave Syer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Ditch SpringFilter in favour of proper dependency injection
parent
b7db6586
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
24 additions
and
38 deletions
+24
-38
SpringFilter.java
.../org/springframework/cloud/netflix/zuul/SpringFilter.java
+0
-31
ZuulConfiguration.java
...springframework/cloud/netflix/zuul/ZuulConfiguration.java
+9
-1
RibbonRoutingFilter.java
...cloud/netflix/zuul/filters/route/RibbonRoutingFilter.java
+15
-6
No files found.
spring-cloud-netflix-core/src/main/java/org/springframework/cloud/netflix/zuul/SpringFilter.java
deleted
100644 → 0
View file @
b7db6586
package
org
.
springframework
.
cloud
.
netflix
.
zuul
;
import
com.netflix.zuul.ZuulFilter
;
import
org.springframework.web.context.WebApplicationContext
;
import
org.springframework.web.context.request.RequestAttributes
;
import
org.springframework.web.context.request.RequestContextHolder
;
import
org.springframework.web.context.request.ServletRequestAttributes
;
import
org.springframework.web.context.support.WebApplicationContextUtils
;
import
javax.servlet.http.HttpServletRequest
;
/**
* User: spencergibb
* Date: 5/1/14
* Time: 10:59 PM
*/
public
abstract
class
SpringFilter
extends
ZuulFilter
{
protected
<
T
>
T
getBean
(
Class
<
T
>
beanClass
)
{
//FIXME: hack because zuul uses servlet 2.5?
RequestAttributes
requestAttr
=
RequestContextHolder
.
currentRequestAttributes
();
if
(!(
requestAttr
instanceof
ServletRequestAttributes
))
{
throw
new
IllegalStateException
(
"Current request is not a servlet request"
);
}
ServletRequestAttributes
attributes
=
(
ServletRequestAttributes
)
requestAttr
;
HttpServletRequest
request
=
attributes
.
getRequest
();
WebApplicationContext
context
=
WebApplicationContextUtils
.
getRequiredWebApplicationContext
(
request
.
getServletContext
());
return
context
.
getBean
(
beanClass
);
}
}
spring-cloud-netflix-core/src/main/java/org/springframework/cloud/netflix/zuul/ZuulConfiguration.java
View file @
bfb6ca6d
...
...
@@ -9,6 +9,8 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression;
import
org.springframework.boot.context.properties.EnableConfigurationProperties
;
import
org.springframework.cloud.client.discovery.DiscoveryClient
;
import
org.springframework.cloud.context.config.annotation.RefreshScope
;
import
org.springframework.cloud.netflix.ribbon.RibbonClientPreprocessor
;
import
org.springframework.cloud.netflix.ribbon.SpringClientFactory
;
import
org.springframework.cloud.netflix.zuul.filters.post.SendErrorFilter
;
import
org.springframework.cloud.netflix.zuul.filters.post.SendResponseFilter
;
import
org.springframework.cloud.netflix.zuul.filters.pre.DebugFilter
;
...
...
@@ -35,6 +37,12 @@ public class ZuulConfiguration {
private
TraceRepository
traces
;
@Autowired
private
RibbonClientPreprocessor
preprocessor
;
@Autowired
private
SpringClientFactory
clientFactory
;
@Autowired
private
DiscoveryClient
discovery
;
@Autowired
...
...
@@ -93,7 +101,7 @@ public class ZuulConfiguration {
// route filters
@Bean
public
RibbonRoutingFilter
ribbonRoutingFilter
()
{
RibbonRoutingFilter
filter
=
new
RibbonRoutingFilter
();
RibbonRoutingFilter
filter
=
new
RibbonRoutingFilter
(
preprocessor
,
clientFactory
);
if
(
traces
!=
null
)
{
filter
.
setTraces
(
traces
);
}
...
...
spring-cloud-netflix-core/src/main/java/org/springframework/cloud/netflix/zuul/filters/route/RibbonRoutingFilter.java
View file @
bfb6ca6d
...
...
@@ -17,9 +17,8 @@ import org.apache.commons.io.IOUtils;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.boot.actuate.trace.TraceRepository
;
import
org.springframework.cloud.netflix.ribbon.SpringClientFactory
;
import
org.springframework.cloud.netflix.ribbon.RibbonClientPreprocessor
;
import
org.springframework.cloud.netflix.
zuul.SpringFilter
;
import
org.springframework.cloud.netflix.
ribbon.SpringClientFactory
;
import
org.springframework.util.StringUtils
;
import
com.netflix.client.ClientException
;
...
...
@@ -27,12 +26,13 @@ import com.netflix.client.http.HttpRequest.Verb;
import
com.netflix.client.http.HttpResponse
;
import
com.netflix.hystrix.exception.HystrixRuntimeException
;
import
com.netflix.niws.client.http.RestClient
;
import
com.netflix.zuul.ZuulFilter
;
import
com.netflix.zuul.context.RequestContext
;
import
com.netflix.zuul.exception.ZuulException
;
import
com.netflix.zuul.util.HTTPRequestUtils
;
import
com.sun.jersey.core.util.MultivaluedMapImpl
;
public
class
RibbonRoutingFilter
extends
Spring
Filter
{
public
class
RibbonRoutingFilter
extends
Zuul
Filter
{
private
static
final
Logger
LOG
=
LoggerFactory
.
getLogger
(
RibbonRoutingFilter
.
class
);
...
...
@@ -40,6 +40,16 @@ public class RibbonRoutingFilter extends SpringFilter {
private
TraceRepository
traces
;
private
RibbonClientPreprocessor
preprocessor
;
private
SpringClientFactory
clientFactory
;
public
RibbonRoutingFilter
(
RibbonClientPreprocessor
preprocessor
,
SpringClientFactory
clientFactory
)
{
this
.
preprocessor
=
preprocessor
;
this
.
clientFactory
=
clientFactory
;
}
public
void
setTraces
(
TraceRepository
traces
)
{
this
.
traces
=
traces
;
}
...
...
@@ -71,10 +81,9 @@ public class RibbonRoutingFilter extends SpringFilter {
String
serviceId
=
(
String
)
context
.
get
(
"serviceId"
);
getBean
(
RibbonClientPreprocessor
.
class
)
.
preprocess
(
serviceId
);
preprocessor
.
preprocess
(
serviceId
);
//TODO: update to ribbon-rxnetty when available
RestClient
restClient
=
getBean
(
SpringClientFactory
.
class
).
namedClient
(
serviceId
,
RestClient
.
class
);
RestClient
restClient
=
clientFactory
.
namedClient
(
serviceId
,
RestClient
.
class
);
String
uri
=
request
.
getRequestURI
();
if
(
context
.
get
(
"requestURI"
)
!=
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