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
8fbba2b0
Commit
8fbba2b0
authored
Aug 06, 2014
by
Spencer Gibb
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
@EnableZuulProxy initial implementation
parent
a2e8245e
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
24 changed files
with
708 additions
and
27 deletions
+708
-27
pom.xml
spring-platform-netflix-core/pom.xml
+10
-0
EurekaInstanceConfigBean.java
...ork/platform/netflix/eureka/EurekaInstanceConfigBean.java
+1
-1
FeignConfigurer.java
...ringframework/platform/netflix/feign/FeignConfigurer.java
+2
-2
EnableZuulProxy.java
...pringframework/platform/netflix/zuul/EnableZuulProxy.java
+15
-0
FilterIntializer.java
...ringframework/platform/netflix/zuul/FilterIntializer.java
+72
-0
RibbonCommand.java
.../springframework/platform/netflix/zuul/RibbonCommand.java
+1
-1
Routes.java
...ava/org/springframework/platform/netflix/zuul/Routes.java
+14
-3
SpringFilter.java
...g/springframework/platform/netflix/zuul/SpringFilter.java
+1
-1
ZuulProxyConfiguration.java
...amework/platform/netflix/zuul/ZuulProxyConfiguration.java
+94
-0
ZuulProxyProperties.java
...gframework/platform/netflix/zuul/ZuulProxyProperties.java
+13
-0
SendResponseFilter.java
...latform/netflix/zuul/filters/post/SendResponseFilter.java
+182
-0
StatsFilter.java
...ework/platform/netflix/zuul/filters/post/StatsFilter.java
+50
-0
DebugFilter.java
...mework/platform/netflix/zuul/filters/pre/DebugFilter.java
+48
-0
DebugRequestFilter.java
...platform/netflix/zuul/filters/pre/DebugRequestFilter.java
+62
-0
PreDecorationFilter.java
...latform/netflix/zuul/filters/pre/PreDecorationFilter.java
+76
-0
RibbonRoutingFilter.java
...tform/netflix/zuul/filters/route/RibbonRoutingFilter.java
+0
-0
SimpleHostRoutingFilter.java
...m/netflix/zuul/filters/route/SimpleHostRoutingFilter.java
+0
-0
Application.java
...ngframework/platform/netflix/zuul/sample/Application.java
+34
-0
ApplicationTests.java
...mework/platform/netflix/zuul/sample/ApplicationTests.java
+18
-0
application.yml
...-platform-netflix-core/src/test/resources/application.yml
+8
-6
Application.java
...ain/java/io/spring/platform/netflix/zuul/Application.java
+1
-0
FilterIntializer.java
...ava/io/spring/platform/netflix/zuul/FilterIntializer.java
+1
-8
PreDecorationFilter.groovy
...src/main/resources/filters/pre/PreDecorationFilter.groovy
+2
-2
RibbonRequest.groovy
...uul/src/main/resources/filters/route/RibbonRequest.groovy
+3
-3
No files found.
spring-platform-netflix-core/pom.xml
View file @
8fbba2b0
...
@@ -81,6 +81,16 @@
...
@@ -81,6 +81,16 @@
<artifactId>
ribbon-eureka
</artifactId>
<artifactId>
ribbon-eureka
</artifactId>
<optional>
true
</optional>
<optional>
true
</optional>
</dependency>
</dependency>
<dependency>
<groupId>
com.netflix.ribbon
</groupId>
<artifactId>
ribbon-httpclient
</artifactId>
<optional>
true
</optional>
</dependency>
<dependency>
<groupId>
com.netflix.zuul
</groupId>
<artifactId>
zuul-core
</artifactId>
<optional>
true
</optional>
</dependency>
<dependency>
<dependency>
<groupId>
org.projectlombok
</groupId>
<groupId>
org.projectlombok
</groupId>
<artifactId>
lombok
</artifactId>
<artifactId>
lombok
</artifactId>
...
...
spring-platform-netflix-core/src/main/java/org/springframework/platform/netflix/eureka/EurekaInstanceConfigBean.java
View file @
8fbba2b0
...
@@ -66,7 +66,7 @@ public class EurekaInstanceConfigBean implements EurekaInstanceConfig {
...
@@ -66,7 +66,7 @@ public class EurekaInstanceConfigBean implements EurekaInstanceConfig {
private
int
leaseExpirationDurationInSeconds
=
90
;
private
int
leaseExpirationDurationInSeconds
=
90
;
@Value
(
"${spring.application.name:unknown}
.mydomain.net"
)
@Value
(
"${spring.application.name:unknown}
"
)
//TODO: why is .mydomain.net here?
private
String
virtualHostName
;
private
String
virtualHostName
;
private
String
secureVirtualHostName
;
private
String
secureVirtualHostName
;
...
...
spring-platform-netflix-core/src/main/java/org/springframework/platform/netflix/feign/FeignConfigurer.java
View file @
8fbba2b0
...
@@ -50,11 +50,11 @@ public class FeignConfigurer {
...
@@ -50,11 +50,11 @@ public class FeignConfigurer {
protected
<
T
>
T
loadBalance
(
Feign
.
Builder
builder
,
Class
<
T
>
type
,
String
schemeName
)
{
protected
<
T
>
T
loadBalance
(
Feign
.
Builder
builder
,
Class
<
T
>
type
,
String
schemeName
)
{
String
name
=
URI
.
create
(
schemeName
).
getHost
();
String
name
=
URI
.
create
(
schemeName
).
getHost
();
setServiceListClass
(
name
);
setServiceListClass
AndVIP
(
name
);
return
builder
.
target
(
LoadBalancingTarget
.
create
(
type
,
schemeName
));
return
builder
.
target
(
LoadBalancingTarget
.
create
(
type
,
schemeName
));
}
}
public
static
void
setServiceListClass
(
String
serviceId
)
{
public
static
void
setServiceListClass
AndVIP
(
String
serviceId
)
{
setProp
(
serviceId
,
"NIWSServerListClassName"
,
DiscoveryEnabledNIWSServerList
.
class
.
getName
());
setProp
(
serviceId
,
"NIWSServerListClassName"
,
DiscoveryEnabledNIWSServerList
.
class
.
getName
());
setProp
(
serviceId
,
"DeploymentContextBasedVipAddresses"
,
serviceId
);
//FIXME: what should this be?
setProp
(
serviceId
,
"DeploymentContextBasedVipAddresses"
,
serviceId
);
//FIXME: what should this be?
}
}
...
...
spring-platform-netflix-core/src/main/java/org/springframework/platform/netflix/zuul/EnableZuulProxy.java
0 → 100644
View file @
8fbba2b0
package
org
.
springframework
.
platform
.
netflix
.
zuul
;
import
java.lang.annotation.*
;
import
org.springframework.context.annotation.Import
;
/**
* @author Spencer Gibb
*/
@Target
(
ElementType
.
TYPE
)
@Retention
(
RetentionPolicy
.
RUNTIME
)
@Documented
@Import
(
ZuulProxyConfiguration
.
class
)
public
@interface
EnableZuulProxy
{
}
spring-platform-netflix-core/src/main/java/org/springframework/platform/netflix/zuul/FilterIntializer.java
0 → 100644
View file @
8fbba2b0
package
org
.
springframework
.
platform
.
netflix
.
zuul
;
import
com.netflix.zuul.FilterFileManager
;
import
com.netflix.zuul.FilterLoader
;
import
com.netflix.zuul.ZuulFilter
;
import
com.netflix.zuul.filters.FilterRegistry
;
import
com.netflix.zuul.groovy.GroovyCompiler
;
import
com.netflix.zuul.groovy.GroovyFileFilter
;
import
com.netflix.zuul.monitoring.MonitoringHelper
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
javax.servlet.ServletContextEvent
;
import
javax.servlet.ServletContextListener
;
import
java.util.List
;
import
java.util.Map
;
/**
* User: spencergibb
* Date: 4/24/14
* Time: 9:23 PM
* TODO: .sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS)
*/
public
class
FilterIntializer
implements
ServletContextListener
{
private
static
final
Logger
LOGGER
=
LoggerFactory
.
getLogger
(
FilterIntializer
.
class
);
@Autowired
private
Map
<
String
,
ZuulFilter
>
filters
;
@Override
public
void
contextInitialized
(
ServletContextEvent
sce
)
{
LOGGER
.
info
(
"Starting filter initialzer context listener"
);
//FIXME: mocks monitoring infrastructure as we don't need it for this simple app
MonitoringHelper
.
initMocks
();
FilterRegistry
registry
=
FilterRegistry
.
instance
();
for
(
Map
.
Entry
<
String
,
ZuulFilter
>
entry
:
filters
.
entrySet
())
{
registry
.
put
(
entry
.
getKey
(),
entry
.
getValue
());
}
}
@Override
public
void
contextDestroyed
(
ServletContextEvent
sce
)
{
LOGGER
.
info
(
"Stopping filter initializer context listener"
);
}
/*private void initGroovyFilterManager() {
//TODO: support groovy filters loaded from filesystem in proxy
FilterLoader.getInstance().setCompiler(new GroovyCompiler());
final String scriptRoot = props.getFilterRoot();
LOGGER.info("Using file system script: " + scriptRoot);
try {
FilterFileManager.setFilenameFilter(new GroovyFileFilter());
FilterFileManager.init(5,
scriptRoot + "/pre",
scriptRoot + "/route",
scriptRoot + "/post"
);
}
catch (Exception e) {
throw new RuntimeException(e);
}
}*/
}
spring-platform-netflix-
zuul/src/main/java/io/spring
/platform/netflix/zuul/RibbonCommand.java
→
spring-platform-netflix-
core/src/main/java/org/springframework
/platform/netflix/zuul/RibbonCommand.java
View file @
8fbba2b0
package
io
.
spring
.
platform
.
netflix
.
zuul
;
package
org
.
springframework
.
platform
.
netflix
.
zuul
;
import
com.netflix.client.http.HttpRequest
;
import
com.netflix.client.http.HttpRequest
;
import
com.netflix.client.http.HttpResponse
;
import
com.netflix.client.http.HttpResponse
;
...
...
spring-platform-netflix-
zuul/src/main/java/io/spring
/platform/netflix/zuul/Routes.java
→
spring-platform-netflix-
core/src/main/java/org/springframework
/platform/netflix/zuul/Routes.java
View file @
8fbba2b0
package
io
.
spring
.
platform
.
netflix
.
zuul
;
package
org
.
springframework
.
platform
.
netflix
.
zuul
;
import
org.slf4j.Logger
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.slf4j.LoggerFactory
;
...
@@ -22,9 +22,20 @@ public class Routes {
...
@@ -22,9 +22,20 @@ public class Routes {
@Autowired
@Autowired
ConfigurableEnvironment
env
;
ConfigurableEnvironment
env
;
private
final
Field
propertySourcesField
;
private
Field
propertySourcesField
;
private
String
keyPrefix
;
public
Routes
()
{
public
Routes
()
{
keyPrefix
=
"zuul.route."
;
initField
();
}
public
Routes
(
String
keyPrefix
)
{
this
.
keyPrefix
=
keyPrefix
;
initField
();
}
private
void
initField
()
{
propertySourcesField
=
ReflectionUtils
.
findField
(
CompositePropertySource
.
class
,
"propertySources"
);
propertySourcesField
=
ReflectionUtils
.
findField
(
CompositePropertySource
.
class
,
"propertySources"
);
propertySourcesField
.
setAccessible
(
true
);
propertySourcesField
.
setAccessible
(
true
);
}
}
...
@@ -63,7 +74,7 @@ public class Routes {
...
@@ -63,7 +74,7 @@ public class Routes {
//EnumerablePropertySource enumerable = (EnumerablePropertySource) propertySource;
//EnumerablePropertySource enumerable = (EnumerablePropertySource) propertySource;
MutablePropertySources
propertySources
=
new
MutablePropertySources
();
MutablePropertySources
propertySources
=
new
MutablePropertySources
();
propertySources
.
addLast
(
propertySource
);
propertySources
.
addLast
(
propertySource
);
Map
<
String
,
Object
>
routeEntries
=
PropertySourceUtils
.
getSubProperties
(
propertySources
,
"zuul.route."
);
Map
<
String
,
Object
>
routeEntries
=
PropertySourceUtils
.
getSubProperties
(
propertySources
,
keyPrefix
);
for
(
Map
.
Entry
<
String
,
Object
>
entry
:
routeEntries
.
entrySet
())
{
for
(
Map
.
Entry
<
String
,
Object
>
entry
:
routeEntries
.
entrySet
())
{
String
serviceId
=
entry
.
getKey
();
String
serviceId
=
entry
.
getKey
();
String
route
=
entry
.
getValue
().
toString
();
String
route
=
entry
.
getValue
().
toString
();
...
...
spring-platform-netflix-
zuul/src/main/java/io/spring
/platform/netflix/zuul/SpringFilter.java
→
spring-platform-netflix-
core/src/main/java/org/springframework
/platform/netflix/zuul/SpringFilter.java
View file @
8fbba2b0
package
io
.
spring
.
platform
.
netflix
.
zuul
;
package
org
.
springframework
.
platform
.
netflix
.
zuul
;
import
com.netflix.zuul.ZuulFilter
;
import
com.netflix.zuul.ZuulFilter
;
import
org.springframework.web.context.WebApplicationContext
;
import
org.springframework.web.context.WebApplicationContext
;
...
...
spring-platform-netflix-core/src/main/java/org/springframework/platform/netflix/zuul/ZuulProxyConfiguration.java
0 → 100644
View file @
8fbba2b0
package
org
.
springframework
.
platform
.
netflix
.
zuul
;
import
com.netflix.zuul.context.ContextLifecycleFilter
;
import
com.netflix.zuul.http.ZuulServlet
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnClass
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnExpression
;
import
org.springframework.boot.context.embedded.FilterRegistrationBean
;
import
org.springframework.boot.context.embedded.ServletRegistrationBean
;
import
org.springframework.boot.context.properties.EnableConfigurationProperties
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.platform.netflix.zuul.filters.post.SendResponseFilter
;
import
org.springframework.platform.netflix.zuul.filters.post.StatsFilter
;
import
org.springframework.platform.netflix.zuul.filters.pre.DebugFilter
;
import
org.springframework.platform.netflix.zuul.filters.pre.DebugRequestFilter
;
import
org.springframework.platform.netflix.zuul.filters.pre.PreDecorationFilter
;
import
org.springframework.platform.netflix.zuul.filters.route.RibbonRoutingFilter
;
import
java.util.ArrayList
;
import
java.util.Collection
;
/**
* @author Spencer Gibb
*/
@Configuration
@EnableConfigurationProperties
(
ZuulProxyProperties
.
class
)
@ConditionalOnClass
(
ZuulServlet
.
class
)
@ConditionalOnExpression
(
"${zuul.proxy.enabled:true}"
)
public
class
ZuulProxyConfiguration
{
@Autowired
private
ZuulProxyProperties
props
;
@Bean
public
FilterRegistrationBean
contextLifecycleFilter
()
{
Collection
<
String
>
urlPatterns
=
new
ArrayList
<>();
urlPatterns
.
add
(
props
.
getMapping
()+
"/*"
);
FilterRegistrationBean
filterRegistrationBean
=
new
FilterRegistrationBean
(
new
ContextLifecycleFilter
());
filterRegistrationBean
.
setUrlPatterns
(
urlPatterns
);
return
filterRegistrationBean
;
}
@Bean
public
ServletRegistrationBean
zuulServlet
()
{
return
new
ServletRegistrationBean
(
new
ZuulServlet
(),
props
.
getMapping
()+
"/*"
);
}
@Bean
Routes
routes
()
{
return
new
Routes
(
"zuul.proxy.route."
);
}
@Bean
FilterIntializer
filterIntializer
()
{
return
new
FilterIntializer
();
}
// pre filters
@Bean
public
DebugFilter
debugFilter
()
{
return
new
DebugFilter
();
}
@Bean
public
DebugRequestFilter
debugRequestFilter
()
{
return
new
DebugRequestFilter
();
}
@Bean
public
PreDecorationFilter
preDecorationFilter
()
{
return
new
PreDecorationFilter
();
}
// route filters
@Bean
public
RibbonRoutingFilter
ribbonRoutingFilter
()
{
return
new
RibbonRoutingFilter
();
}
// post filters
@Bean
public
SendResponseFilter
sendResponseFilter
()
{
return
new
SendResponseFilter
();
}
@Bean
public
StatsFilter
statsFilter
()
{
return
new
StatsFilter
();
}
}
spring-platform-netflix-core/src/main/java/org/springframework/platform/netflix/zuul/ZuulProxyProperties.java
0 → 100644
View file @
8fbba2b0
package
org
.
springframework
.
platform
.
netflix
.
zuul
;
import
lombok.Data
;
import
org.springframework.boot.context.properties.ConfigurationProperties
;
/**
* Created by sgibb on 8/5/14.
*/
@Data
@ConfigurationProperties
(
"zuul.proxy"
)
public
class
ZuulProxyProperties
{
private
String
mapping
=
"/proxy"
;
}
spring-platform-netflix-core/src/main/java/org/springframework/platform/netflix/zuul/filters/post/SendResponseFilter.java
0 → 100644
View file @
8fbba2b0
package
org
.
springframework
.
platform
.
netflix
.
zuul
.
filters
.
post
;
import
com.google.common.base.Throwables
;
import
com.netflix.config.DynamicBooleanProperty
;
import
com.netflix.config.DynamicIntProperty
;
import
com.netflix.config.DynamicPropertyFactory
;
import
com.netflix.util.Pair
;
import
com.netflix.zuul.ZuulFilter
;
import
com.netflix.zuul.constants.ZuulConstants
;
import
com.netflix.zuul.constants.ZuulHeaders
;
import
com.netflix.zuul.context.Debug
;
import
com.netflix.zuul.context.RequestContext
;
import
javax.servlet.http.HttpServletResponse
;
import
java.io.ByteArrayInputStream
;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.io.OutputStream
;
import
java.util.List
;
import
java.util.zip.GZIPInputStream
;
public
class
SendResponseFilter
extends
ZuulFilter
{
static
DynamicBooleanProperty
INCLUDE_DEBUG_HEADER
=
DynamicPropertyFactory
.
getInstance
().
getBooleanProperty
(
ZuulConstants
.
ZUUL_INCLUDE_DEBUG_HEADER
,
false
);
static
DynamicIntProperty
INITIAL_STREAM_BUFFER_SIZE
=
DynamicPropertyFactory
.
getInstance
().
getIntProperty
(
ZuulConstants
.
ZUUL_INITIAL_STREAM_BUFFER_SIZE
,
1024
);
static
DynamicBooleanProperty
SET_CONTENT_LENGTH
=
DynamicPropertyFactory
.
getInstance
().
getBooleanProperty
(
ZuulConstants
.
ZUUL_SET_CONTENT_LENGTH
,
false
);
@Override
public
String
filterType
()
{
return
"post"
;
}
@Override
public
int
filterOrder
()
{
return
1000
;
}
public
boolean
shouldFilter
()
{
return
!
RequestContext
.
getCurrentContext
().
getZuulResponseHeaders
().
isEmpty
()
||
RequestContext
.
getCurrentContext
().
getResponseDataStream
()
!=
null
||
RequestContext
.
getCurrentContext
().
getResponseBody
()
!=
null
;
}
public
Object
run
()
{
try
{
addResponseHeaders
();
writeResponse
();
}
catch
(
Exception
e
)
{
Throwables
.
propagate
(
e
);
}
return
null
;
}
void
writeResponse
()
throws
Exception
{
RequestContext
context
=
RequestContext
.
getCurrentContext
();
// there is no body to send
if
(
context
.
getResponseBody
()
==
null
&&
context
.
getResponseDataStream
()
==
null
)
return
;
HttpServletResponse
servletResponse
=
context
.
getResponse
();
servletResponse
.
setCharacterEncoding
(
"UTF-8"
);
OutputStream
outStream
=
servletResponse
.
getOutputStream
();
InputStream
is
=
null
;
try
{
if
(
RequestContext
.
getCurrentContext
().
getResponseBody
()
!=
null
)
{
String
body
=
RequestContext
.
getCurrentContext
().
getResponseBody
();
writeResponse
(
new
ByteArrayInputStream
(
body
.
getBytes
()),
outStream
);
return
;
}
boolean
isGzipRequested
=
false
;
final
String
requestEncoding
=
context
.
getRequest
().
getHeader
(
ZuulHeaders
.
ACCEPT_ENCODING
);
if
(
requestEncoding
!=
null
&&
requestEncoding
.
equals
(
"gzip"
))
isGzipRequested
=
true
;
is
=
context
.
getResponseDataStream
();
InputStream
inputStream
=
is
;
if
(
is
!=
null
)
{
if
(
context
.
sendZuulResponse
())
{
// if origin response is gzipped, and client has not requested gzip, decompress stream
// before sending to client
// else, stream gzip directly to client
if
(
context
.
getResponseGZipped
()
&&
!
isGzipRequested
)
try
{
inputStream
=
new
GZIPInputStream
(
is
);
}
catch
(
java
.
util
.
zip
.
ZipException
e
)
{
System
.
out
.
println
(
"gzip expected but not received assuming unencoded response"
+
RequestContext
.
getCurrentContext
().
getRequest
().
getRequestURL
().
toString
());
inputStream
=
is
;
}
else
if
(
context
.
getResponseGZipped
()
&&
isGzipRequested
)
servletResponse
.
setHeader
(
ZuulHeaders
.
CONTENT_ENCODING
,
"gzip"
);
writeResponse
(
inputStream
,
outStream
);
}
}
}
finally
{
try
{
if
(
is
!=
null
)
is
.
close
();
outStream
.
flush
();
outStream
.
close
();
}
catch
(
IOException
e
)
{
}
}
}
private
void
writeResponse
(
InputStream
zin
,
OutputStream
out
)
throws
Exception
{
byte
[]
bytes
=
new
byte
[
INITIAL_STREAM_BUFFER_SIZE
.
get
()];
int
bytesRead
=
-
1
;
while
((
bytesRead
=
zin
.
read
(
bytes
))
!=
-
1
)
{
// if (Debug.debugRequest() && !Debug.debugRequestHeadersOnly()) {
// Debug.addRequestDebug("OUTBOUND: < " + new String(bytes, 0, bytesRead));
// }
try
{
out
.
write
(
bytes
,
0
,
bytesRead
);
out
.
flush
();
}
catch
(
IOException
e
)
{
//ignore
e
.
printStackTrace
();
}
// doubles buffer size if previous read filled it
if
(
bytesRead
==
bytes
.
length
)
{
bytes
=
new
byte
[
bytes
.
length
*
2
];
}
}
}
private
void
addResponseHeaders
()
{
RequestContext
context
=
RequestContext
.
getCurrentContext
();
HttpServletResponse
servletResponse
=
context
.
getResponse
();
List
<
Pair
<
String
,
String
>>
zuulResponseHeaders
=
context
.
getZuulResponseHeaders
();
String
debugHeader
=
""
;
List
<
String
>
rd
=
(
List
<
String
>)
RequestContext
.
getCurrentContext
().
get
(
"routingDebug"
);
for
(
String
it
:
rd
)
{
debugHeader
+=
"[[["
+
it
+
"]]]"
;
}
/*
rd = (List<String>) RequestContext.getCurrentContext().get("requestDebug");
rd?.each {
debugHeader += "[[[REQUEST_DEBUG::${it}]]]";
}
*/
if
(
INCLUDE_DEBUG_HEADER
.
get
())
servletResponse
.
addHeader
(
"X-Zuul-Debug-Header"
,
debugHeader
);
if
(
Debug
.
debugRequest
()
&&
zuulResponseHeaders
!=
null
)
{
for
(
Pair
<
String
,
String
>
it
:
zuulResponseHeaders
)
{
servletResponse
.
addHeader
(
it
.
first
(),
it
.
second
());
Debug
.
addRequestDebug
(
"OUTBOUND: < "
+
it
.
first
()
+
":"
+
it
.
second
());
}
}
else
if
(
zuulResponseHeaders
!=
null
)
{
for
(
Pair
<
String
,
String
>
it
:
zuulResponseHeaders
)
{
servletResponse
.
addHeader
(
it
.
first
(),
it
.
second
());
}
}
RequestContext
ctx
=
RequestContext
.
getCurrentContext
();
Integer
contentLength
=
ctx
.
getOriginContentLength
();
// only inserts Content-Length if origin provides it and origin response is not gzipped
if
(
SET_CONTENT_LENGTH
.
get
())
{
if
(
contentLength
!=
null
&&
!
ctx
.
getResponseGZipped
())
servletResponse
.
setContentLength
(
contentLength
);
}
}
}
\ No newline at end of file
spring-platform-netflix-core/src/main/java/org/springframework/platform/netflix/zuul/filters/post/StatsFilter.java
0 → 100644
View file @
8fbba2b0
package
org
.
springframework
.
platform
.
netflix
.
zuul
.
filters
.
post
;
import
com.netflix.zuul.ZuulFilter
;
import
com.netflix.zuul.context.RequestContext
;
import
java.util.List
;
public
class
StatsFilter
extends
ZuulFilter
{
@Override
public
String
filterType
()
{
return
"post"
;
}
@Override
public
int
filterOrder
()
{
return
2000
;
}
@Override
public
boolean
shouldFilter
()
{
return
true
;
}
@Override
public
Object
run
()
{
dumpRoutingDebug
();
dumpRequestDebug
();
return
null
;
}
public
void
dumpRequestDebug
()
{
List
<
String
>
rd
=
(
List
<
String
>)
RequestContext
.
getCurrentContext
().
get
(
"requestDebug"
);
if
(
rd
!=
null
)
{
for
(
String
it
:
rd
)
{
System
.
out
.
println
(
"REQUEST_DEBUG::"
+
it
);
}
}
}
public
void
dumpRoutingDebug
()
{
List
<
String
>
rd
=
(
List
<
String
>)
RequestContext
.
getCurrentContext
().
get
(
"routingDebug"
);
if
(
rd
!=
null
)
{
for
(
String
it
:
rd
)
{
System
.
out
.
println
(
"ZUUL_DEBUG::"
+
it
);
}
}
}
}
spring-platform-netflix-core/src/main/java/org/springframework/platform/netflix/zuul/filters/pre/DebugFilter.java
0 → 100644
View file @
8fbba2b0
package
org
.
springframework
.
platform
.
netflix
.
zuul
.
filters
.
pre
;
import
com.netflix.config.DynamicBooleanProperty
;
import
com.netflix.config.DynamicPropertyFactory
;
import
com.netflix.config.DynamicStringProperty
;
import
com.netflix.zuul.ZuulFilter
;
import
com.netflix.zuul.constants.ZuulConstants
;
import
com.netflix.zuul.context.RequestContext
;
import
javax.servlet.http.HttpServletRequest
;
public
class
DebugFilter
extends
ZuulFilter
{
static
final
DynamicBooleanProperty
routingDebug
=
DynamicPropertyFactory
.
getInstance
()
.
getBooleanProperty
(
ZuulConstants
.
ZUUL_DEBUG_REQUEST
,
true
);
static
final
DynamicStringProperty
debugParameter
=
DynamicPropertyFactory
.
getInstance
()
.
getStringProperty
(
ZuulConstants
.
ZUUL_DEBUG_PARAMETER
,
"d"
);
@Override
public
String
filterType
()
{
return
"pre"
;
}
@Override
public
int
filterOrder
()
{
return
1
;
}
public
boolean
shouldFilter
()
{
HttpServletRequest
request
=
RequestContext
.
getCurrentContext
().
getRequest
();
if
(
"true"
.
equals
(
request
.
getParameter
(
debugParameter
.
get
())))
return
true
;
return
routingDebug
.
get
();
}
public
Object
run
()
{
RequestContext
ctx
=
RequestContext
.
getCurrentContext
();
ctx
.
setDebugRouting
(
true
);
ctx
.
setDebugRequest
(
true
);
return
null
;
}
}
spring-platform-netflix-core/src/main/java/org/springframework/platform/netflix/zuul/filters/pre/DebugRequestFilter.java
0 → 100644
View file @
8fbba2b0
package
org
.
springframework
.
platform
.
netflix
.
zuul
.
filters
.
pre
;
import
com.netflix.zuul.ZuulFilter
;
import
com.netflix.zuul.context.Debug
;
import
com.netflix.zuul.context.RequestContext
;
import
org.apache.commons.io.IOUtils
;
import
javax.servlet.http.HttpServletRequest
;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.util.Enumeration
;
public
class
DebugRequestFilter
extends
ZuulFilter
{
@Override
public
String
filterType
()
{
return
"pre"
;
}
@Override
public
int
filterOrder
()
{
return
10000
;
}
@Override
public
boolean
shouldFilter
()
{
return
Debug
.
debugRequest
();
}
@Override
public
Object
run
()
{
HttpServletRequest
req
=
RequestContext
.
getCurrentContext
().
getRequest
();
Debug
.
addRequestDebug
(
"REQUEST:: "
+
req
.
getScheme
()
+
" "
+
req
.
getRemoteAddr
()
+
":"
+
req
.
getRemotePort
());
Debug
.
addRequestDebug
(
"REQUEST:: > "
+
req
.
getMethod
()
+
" "
+
req
.
getRequestURI
()
+
" "
+
req
.
getProtocol
());
Enumeration
<
String
>
headerIt
=
req
.
getHeaderNames
();
while
(
headerIt
.
hasMoreElements
())
{
String
name
=
headerIt
.
nextElement
();
String
value
=
req
.
getHeader
(
name
);
Debug
.
addRequestDebug
(
"REQUEST:: > "
+
name
+
":"
+
value
);
}
final
RequestContext
ctx
=
RequestContext
.
getCurrentContext
();
if
(!
ctx
.
isChunkedRequestBody
())
{
try
{
InputStream
inp
=
ctx
.
getRequest
().
getInputStream
();
if
(
inp
!=
null
)
{
String
body
=
IOUtils
.
toString
(
inp
);
Debug
.
addRequestDebug
(
"REQUEST:: > "
+
body
);
}
}
catch
(
IOException
e
)
{
throw
new
RuntimeException
(
e
);
}
}
return
null
;
}
}
spring-platform-netflix-core/src/main/java/org/springframework/platform/netflix/zuul/filters/pre/PreDecorationFilter.java
0 → 100644
View file @
8fbba2b0
package
org
.
springframework
.
platform
.
netflix
.
zuul
.
filters
.
pre
;
import
com.google.common.base.Optional
;
import
com.google.common.base.Predicate
;
import
com.google.common.collect.Iterables
;
import
com.netflix.zuul.ZuulFilter
;
import
com.netflix.zuul.context.RequestContext
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.platform.netflix.zuul.Routes
;
import
org.springframework.platform.netflix.zuul.ZuulProxyProperties
;
import
javax.annotation.Nullable
;
import
java.util.LinkedHashMap
;
public
class
PreDecorationFilter
extends
ZuulFilter
{
private
static
Logger
LOG
=
LoggerFactory
.
getLogger
(
PreDecorationFilter
.
class
);
@Autowired
private
Routes
routes
;
@Autowired
private
ZuulProxyProperties
properties
;
@Override
public
int
filterOrder
()
{
return
5
;
}
@Override
public
String
filterType
()
{
return
"pre"
;
}
@Override
public
boolean
shouldFilter
()
{
return
true
;
}
@Override
public
Object
run
()
{
RequestContext
ctx
=
RequestContext
.
getCurrentContext
();
String
requestURI
=
ctx
.
getRequest
().
getRequestURI
();
//remove proxy prefix TODO: only if embedded proxy
String
proxyMapping
=
properties
.
getMapping
();
final
String
uriPart
=
requestURI
.
replace
(
proxyMapping
,
""
);
//TODO: better strategy?
ctx
.
put
(
"requestURI"
,
uriPart
);
LinkedHashMap
<
String
,
String
>
routesMap
=
routes
.
getRoutes
();
Optional
<
String
>
route
=
Iterables
.
tryFind
(
routesMap
.
keySet
(),
new
Predicate
<
String
>()
{
@Override
public
boolean
apply
(
@Nullable
String
path
)
{
return
uriPart
.
startsWith
(
path
);
}
});
if
(
route
.
isPresent
())
{
String
serviceId
=
routesMap
.
get
(
route
.
get
());
if
(
serviceId
!=
null
)
{
// set serviceId for use in filters.route.RibbonRequest
ctx
.
set
(
"serviceId"
,
serviceId
);
ctx
.
setRouteHost
(
null
);
ctx
.
addOriginResponseHeader
(
"X-Zuul-ServiceId"
,
serviceId
);
}
}
else
{
LOG
.
warn
(
"No route found for uri: "
+
requestURI
);
//TODO: 404
}
return
null
;
}
}
spring-platform-netflix-core/src/main/java/org/springframework/platform/netflix/zuul/filters/route/RibbonRoutingFilter.java
0 → 100644
View file @
8fbba2b0
This diff is collapsed.
Click to expand it.
spring-platform-netflix-core/src/main/java/org/springframework/platform/netflix/zuul/filters/route/SimpleHostRoutingFilter.java
0 → 100644
View file @
8fbba2b0
This diff is collapsed.
Click to expand it.
spring-platform-netflix-core/src/test/java/org/springframework/platform/netflix/zuul/sample/Application.java
0 → 100644
View file @
8fbba2b0
package
org
.
springframework
.
platform
.
netflix
.
zuul
.
sample
;
import
org.springframework.boot.autoconfigure.EnableAutoConfiguration
;
import
org.springframework.boot.builder.SpringApplicationBuilder
;
import
org.springframework.context.annotation.ComponentScan
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.platform.netflix.eureka.EnableEurekaClient
;
import
org.springframework.platform.netflix.zuul.EnableZuulProxy
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RestController
;
@Configuration
@ComponentScan
@EnableAutoConfiguration
@RestController
@EnableZuulProxy
@EnableEurekaClient
public
class
Application
{
@RequestMapping
(
"/testing123"
)
public
String
testing123
()
{
return
"testing123"
;
}
@RequestMapping
(
"/"
)
public
String
home
()
{
return
"Hello world"
;
}
public
static
void
main
(
String
[]
args
)
{
new
SpringApplicationBuilder
(
Application
.
class
).
web
(
true
).
run
(
args
);
}
}
spring-platform-netflix-core/src/test/java/org/springframework/platform/netflix/zuul/sample/ApplicationTests.java
0 → 100644
View file @
8fbba2b0
package
org
.
springframework
.
platform
.
netflix
.
zuul
.
sample
;
import
org.junit.Test
;
import
org.junit.runner.RunWith
;
import
org.springframework.test.context.web.WebAppConfiguration
;
import
org.springframework.boot.test.SpringApplicationConfiguration
;
import
org.springframework.test.context.junit4.SpringJUnit4ClassRunner
;
@RunWith
(
SpringJUnit4ClassRunner
.
class
)
@SpringApplicationConfiguration
(
classes
=
Application
.
class
)
@WebAppConfiguration
public
class
ApplicationTests
{
@Test
public
void
contextLoads
()
{
}
}
spring-platform-netflix-core/src/test/resources/application.yml
View file @
8fbba2b0
server
:
server
:
port
:
9
000
port
:
9
999
spring
:
spring
:
application
:
application
:
name
:
client
name
:
test
client
eureka
:
eureka
:
server
:
server
:
enabled
:
false
enabled
:
false
client
:
serviceUrl
:
zuul
:
defaultZone
:
http://localhost:8080/v2/
proxy
:
default.defaultZone
:
http://localhost:8080/v2/
route
:
testclient
:
/testing123
stores
:
/stores
spring-platform-netflix-zuul/src/main/java/io/spring/platform/netflix/zuul/Application.java
View file @
8fbba2b0
...
@@ -8,6 +8,7 @@ import org.springframework.context.annotation.Bean;
...
@@ -8,6 +8,7 @@ import org.springframework.context.annotation.Bean;
import
org.springframework.context.annotation.ComponentScan
;
import
org.springframework.context.annotation.ComponentScan
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.platform.netflix.endpoint.HystrixStreamEndpoint
;
import
org.springframework.platform.netflix.endpoint.HystrixStreamEndpoint
;
import
org.springframework.platform.netflix.zuul.Routes
;
import
org.springframework.scheduling.annotation.EnableScheduling
;
import
org.springframework.scheduling.annotation.EnableScheduling
;
import
java.util.ArrayList
;
import
java.util.ArrayList
;
...
...
spring-platform-netflix-zuul/src/main/java/io/spring/platform/netflix/zuul/FilterIntializer.java
View file @
8fbba2b0
...
@@ -11,7 +11,6 @@ import org.springframework.beans.factory.annotation.Autowired;
...
@@ -11,7 +11,6 @@ import org.springframework.beans.factory.annotation.Autowired;
import
javax.servlet.ServletContextEvent
;
import
javax.servlet.ServletContextEvent
;
import
javax.servlet.ServletContextListener
;
import
javax.servlet.ServletContextListener
;
//import javax.servlet.http.HttpSessionEvent;
/**
/**
* User: spencergibb
* User: spencergibb
...
@@ -19,7 +18,7 @@ import javax.servlet.ServletContextListener;
...
@@ -19,7 +18,7 @@ import javax.servlet.ServletContextListener;
* Time: 9:23 PM
* Time: 9:23 PM
* TODO: .sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS)
* TODO: .sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS)
*/
*/
public
class
FilterIntializer
implements
ServletContextListener
/*, HttpSessionListener*/
{
public
class
FilterIntializer
implements
ServletContextListener
{
private
static
final
Logger
LOGGER
=
LoggerFactory
.
getLogger
(
FilterIntializer
.
class
);
private
static
final
Logger
LOGGER
=
LoggerFactory
.
getLogger
(
FilterIntializer
.
class
);
...
@@ -27,9 +26,6 @@ public class FilterIntializer implements ServletContextListener/*, HttpSessionLi
...
@@ -27,9 +26,6 @@ public class FilterIntializer implements ServletContextListener/*, HttpSessionLi
ZuulProperties
props
;
ZuulProperties
props
;
@Override
@Override
/*public void sessionCreated(HttpSessionEvent se) {
contextInitialized(null);
}*/
public
void
contextInitialized
(
ServletContextEvent
sce
)
{
public
void
contextInitialized
(
ServletContextEvent
sce
)
{
LOGGER
.
info
(
"Starting filter initialzer context listener"
);
LOGGER
.
info
(
"Starting filter initialzer context listener"
);
...
@@ -42,9 +38,6 @@ public class FilterIntializer implements ServletContextListener/*, HttpSessionLi
...
@@ -42,9 +38,6 @@ public class FilterIntializer implements ServletContextListener/*, HttpSessionLi
}
}
@Override
@Override
/*public void sessionDestroyed(HttpSessionEvent se) {
contextDestroyed(null);
}*/
public
void
contextDestroyed
(
ServletContextEvent
sce
)
{
public
void
contextDestroyed
(
ServletContextEvent
sce
)
{
LOGGER
.
info
(
"Stopping filter initializer context listener"
);
LOGGER
.
info
(
"Stopping filter initializer context listener"
);
}
}
...
...
spring-platform-netflix-zuul/src/main/resources/filters/pre/PreDecorationFilter.groovy
View file @
8fbba2b0
...
@@ -3,8 +3,8 @@ package filters.pre
...
@@ -3,8 +3,8 @@ package filters.pre
import
com.netflix.zuul.context.RequestContext
import
com.netflix.zuul.context.RequestContext
import
org.slf4j.Logger
import
org.slf4j.Logger
import
org.slf4j.LoggerFactory
import
org.slf4j.LoggerFactory
import
io.spring
.platform.netflix.zuul.Routes
import
org.springframework
.platform.netflix.zuul.Routes
import
io.spring
.platform.netflix.zuul.SpringFilter
import
org.springframework
.platform.netflix.zuul.SpringFilter
class
PreDecorationFilter
extends
SpringFilter
{
class
PreDecorationFilter
extends
SpringFilter
{
private
static
Logger
LOG
=
LoggerFactory
.
getLogger
(
PreDecorationFilter
.
class
);
private
static
Logger
LOG
=
LoggerFactory
.
getLogger
(
PreDecorationFilter
.
class
);
...
...
spring-platform-netflix-zuul/src/main/resources/filters/route/RibbonRequest.groovy
View file @
8fbba2b0
...
@@ -15,14 +15,14 @@ import com.netflix.zuul.util.HTTPRequestUtils
...
@@ -15,14 +15,14 @@ import com.netflix.zuul.util.HTTPRequestUtils
import
com.sun.jersey.core.util.MultivaluedMapImpl
import
com.sun.jersey.core.util.MultivaluedMapImpl
import
org.slf4j.Logger
import
org.slf4j.Logger
import
org.slf4j.LoggerFactory
import
org.slf4j.LoggerFactory
import
io.spring
.platform.netflix.zuul.RibbonCommand
import
org.springframework
.platform.netflix.zuul.RibbonCommand
import
javax.servlet.http.HttpServletRequest
import
javax.servlet.http.HttpServletRequest
import
javax.ws.rs.core.MultivaluedMap
import
javax.ws.rs.core.MultivaluedMap
import
java.util.zip.GZIPInputStream
import
java.util.zip.GZIPInputStream
import
static
HttpRequest
.
Verb
import
static
HttpRequest
.
Verb
import
static
org
.
springframework
.
platform
.
netflix
.
feign
.
FeignConfigurer
.
setServiceListClass
import
static
org
.
springframework
.
platform
.
netflix
.
feign
.
FeignConfigurer
.
setServiceListClass
AndVIP
class
RibbonRequest
extends
ZuulFilter
{
class
RibbonRequest
extends
ZuulFilter
{
...
@@ -57,7 +57,7 @@ class RibbonRequest extends ZuulFilter {
...
@@ -57,7 +57,7 @@ class RibbonRequest extends ZuulFilter {
def
serviceId
=
context
.
get
(
"serviceId"
)
def
serviceId
=
context
.
get
(
"serviceId"
)
//TODO: can this be set be default? or an implementation of an interface?
//TODO: can this be set be default? or an implementation of an interface?
setServiceListClass
(
serviceId
)
setServiceListClass
AndVIP
(
serviceId
)
IClient
restClient
=
ClientFactory
.
getNamedClient
(
serviceId
);
IClient
restClient
=
ClientFactory
.
getNamedClient
(
serviceId
);
...
...
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