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
b24a0524
Commit
b24a0524
authored
Jan 03, 2018
by
Ryan Baxter
Browse files
Options
Browse Files
Download
Plain Diff
Merge remote-tracking branch 'origin/1.4.x'
parents
fb0d53a7
a4c995a3
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
88 additions
and
7 deletions
+88
-7
EurekaClientAutoConfiguration.java
...k/cloud/netflix/eureka/EurekaClientAutoConfiguration.java
+4
-0
EurekaClientAutoConfigurationTests.java
...ud/netflix/eureka/EurekaClientAutoConfigurationTests.java
+19
-0
SendResponseFilter.java
...k/cloud/netflix/zuul/filters/post/SendResponseFilter.java
+16
-4
SimpleHostRoutingFilter.java
...d/netflix/zuul/filters/route/SimpleHostRoutingFilter.java
+1
-1
SendResponseFilterTests.java
...ud/netflix/zuul/filters/post/SendResponseFilterTests.java
+28
-2
SimpleHostRoutingFilterTests.java
...flix/zuul/filters/route/SimpleHostRoutingFilterTests.java
+20
-0
No files found.
spring-cloud-netflix-eureka-client/src/main/java/org/springframework/cloud/netflix/eureka/EurekaClientAutoConfiguration.java
View file @
b24a0524
...
...
@@ -137,6 +137,7 @@ public class EurekaClientAutoConfiguration {
ManagementMetadataProvider
managementMetadataProvider
)
{
String
hostname
=
getProperty
(
"eureka.instance.hostname"
);
boolean
preferIpAddress
=
Boolean
.
parseBoolean
(
getProperty
(
"eureka.instance.prefer-ip-address"
));
String
ipAddress
=
getProperty
(
"eureka.instance.ipAddress"
);
boolean
isSecurePortEnabled
=
Boolean
.
parseBoolean
(
getProperty
(
"eureka.instance.secure-port-enabled"
));
String
serverContextPath
=
env
.
getProperty
(
"server.context-path"
,
"/"
);
...
...
@@ -150,6 +151,9 @@ public class EurekaClientAutoConfiguration {
instance
.
setNonSecurePort
(
serverPort
);
instance
.
setInstanceId
(
getDefaultInstanceId
(
env
));
instance
.
setPreferIpAddress
(
preferIpAddress
);
if
(
StringUtils
.
hasText
(
ipAddress
))
{
instance
.
setIpAddress
(
ipAddress
);
}
if
(
isSecurePortEnabled
)
{
instance
.
setSecurePort
(
serverPort
);
...
...
spring-cloud-netflix-eureka-client/src/test/java/org/springframework/cloud/netflix/eureka/EurekaClientAutoConfigurationTests.java
View file @
b24a0524
...
...
@@ -300,6 +300,25 @@ public class EurekaClientAutoConfigurationTests {
assertEquals
(
"statusPageUrl is wrong"
,
"http://"
+
instance
.
getIpAddress
()
+
":9999/info"
,
instance
.
getStatusPageUrl
());
assertEquals
(
"healthCheckUrl is wrong"
,
"http://"
+
instance
.
getIpAddress
()
+
":9999/health"
,
instance
.
getHealthCheckUrl
());
}
@Test
public
void
statusPageAndHealthCheckUrlsShouldSetUserDefinedIpAddress
()
{
addEnvironment
(
this
.
context
,
"server.port=8989"
,
"management.port=9999"
,
"eureka.instance.hostname=foo"
,
"eureka.instance.ipAddress:192.168.13.90"
,
"eureka.instance.preferIpAddress:true"
);
setupContext
(
RefreshAutoConfiguration
.
class
);
EurekaInstanceConfigBean
instance
=
this
.
context
.
getBean
(
EurekaInstanceConfigBean
.
class
);
assertEquals
(
"statusPageUrl is wrong"
,
"http://192.168.13.90:9999/info"
,
instance
.
getStatusPageUrl
());
assertEquals
(
"healthCheckUrl is wrong"
,
"http://192.168.13.90:9999/health"
,
instance
.
getHealthCheckUrl
());
}
@Test
...
...
spring-cloud-netflix-zuul/src/main/java/org/springframework/cloud/netflix/zuul/filters/post/SendResponseFilter.java
View file @
b24a0524
...
...
@@ -179,12 +179,24 @@ public class SendResponseFilter extends ZuulFilter {
}
finally
{
/**
* Closing the wrapping InputStream itself has no effect on closing the underlying tcp connection since it's a wrapped stream. I guess for http
* keep-alive. When closing the wrapping stream it tries to reach the end of the current request, which is impossible for infinite http streams. So
* instead of closing the InputStream we close the HTTP response.
* We must ensure that the InputStream provided by our upstream pooling mechanism is ALWAYS closed
* even in the case of wrapped streams, which are supplied by pooled sources such as Apache's
* PoolingHttpClientConnectionManager. In that particular case, the underlying HTTP connection will
* be returned back to the connection pool iif either close() is explicitly called, a read
* error occurs, or the end of the underlying stream is reached. If, however a write error occurs, we will
* end up leaking a connection from the pool without an explicit close()
*
* @author Johannes Edmeier
*/
if
(
is
!=
null
)
{
try
{
is
.
close
();
}
catch
(
Exception
ex
)
{
log
.
warn
(
"Error while closing upstream input stream"
,
ex
);
}
}
try
{
Object
zuulResponse
=
RequestContext
.
getCurrentContext
()
.
get
(
"zuulResponse"
);
...
...
@@ -195,7 +207,7 @@ public class SendResponseFilter extends ZuulFilter {
// The container will close the stream for us
}
catch
(
IOException
ex
)
{
log
.
warn
(
"Error while sending response to client: "
+
ex
.
getMessage
());
log
.
warn
(
"Error while sending response to client: "
+
ex
.
getMessage
());
}
}
}
...
...
spring-cloud-netflix-zuul/src/main/java/org/springframework/cloud/netflix/zuul/filters/route/SimpleHostRoutingFilter.java
View file @
b24a0524
...
...
@@ -222,7 +222,7 @@ public class SimpleHostRoutingFilter extends ZuulFilter {
.
setCookieSpec
(
CookieSpecs
.
IGNORE_COOKIES
).
build
();
return
httpClientFactory
.
createBuilder
().
setDefaultRequestConfig
(
requestConfig
).
setConnectionManager
(
this
.
connectionManager
).
build
();
setConnectionManager
(
this
.
connectionManager
).
disableRedirectHandling
().
build
();
}
private
CloseableHttpResponse
forward
(
CloseableHttpClient
httpclient
,
String
verb
,
...
...
spring-cloud-netflix-zuul/src/test/java/org/springframework/cloud/netflix/zuul/filters/post/SendResponseFilterTests.java
View file @
b24a0524
...
...
@@ -19,6 +19,7 @@ package org.springframework.cloud.netflix.zuul.filters.post;
import
java.io.ByteArrayInputStream
;
import
java.io.Closeable
;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.lang.reflect.UndeclaredThrowableException
;
import
javax.servlet.ServletOutputStream
;
...
...
@@ -47,6 +48,7 @@ import static org.mockito.Matchers.anyInt;
import
static
org
.
mockito
.
Matchers
.
isA
;
import
static
org
.
mockito
.
Mockito
.
doThrow
;
import
static
org
.
mockito
.
Mockito
.
mock
;
import
static
org
.
mockito
.
Mockito
.
spy
;
import
static
org
.
mockito
.
Mockito
.
verify
;
import
static
org
.
mockito
.
Mockito
.
when
;
import
static
org
.
springframework
.
cloud
.
netflix
.
zuul
.
filters
.
support
.
FilterConstants
.
X_ZUUL_DEBUG_HEADER
;
...
...
@@ -116,13 +118,14 @@ public class SendResponseFilterTests {
}
@Test
public
void
closeResponseOutpu
s
StreamError
()
throws
Exception
{
public
void
closeResponseOutpu
t
StreamError
()
throws
Exception
{
HttpServletResponse
response
=
mock
(
HttpServletResponse
.
class
);
InputStream
mockStream
=
spy
(
new
ByteArrayInputStream
(
"Hello\n"
.
getBytes
(
"UTF-8"
)));
RequestContext
context
=
new
RequestContext
();
context
.
setRequest
(
new
MockHttpServletRequest
());
context
.
setResponse
(
response
);
context
.
setResponseDataStream
(
new
ByteArrayInputStream
(
"Hello\n"
.
getBytes
(
"UTF-8"
))
);
context
.
setResponseDataStream
(
mockStream
);
Closeable
zuulResponse
=
mock
(
Closeable
.
class
);
context
.
set
(
"zuulResponse"
,
zuulResponse
);
RequestContext
.
testSetCurrentContext
(
context
);
...
...
@@ -141,6 +144,29 @@ public class SendResponseFilterTests {
}
verify
(
zuulResponse
).
close
();
verify
(
mockStream
).
close
();
}
@Test
public
void
testCloseResponseDataStream
()
throws
Exception
{
HttpServletResponse
response
=
mock
(
HttpServletResponse
.
class
);
InputStream
mockStream
=
spy
(
new
ByteArrayInputStream
(
"Hello\n"
.
getBytes
(
"UTF-8"
)));
RequestContext
context
=
new
RequestContext
();
context
.
setRequest
(
new
MockHttpServletRequest
());
context
.
setResponse
(
response
);
context
.
setResponseDataStream
(
mockStream
);
Closeable
zuulResponse
=
mock
(
Closeable
.
class
);
context
.
set
(
"zuulResponse"
,
zuulResponse
);
RequestContext
.
testSetCurrentContext
(
context
);
when
(
response
.
getOutputStream
()).
thenReturn
(
mock
(
ServletOutputStream
.
class
));
SendResponseFilter
filter
=
new
SendResponseFilter
();
filter
.
run
();
verify
(
mockStream
).
close
();
}
private
void
runFilter
(
String
characterEncoding
,
String
content
,
boolean
streamContent
)
throws
Exception
{
...
...
spring-cloud-netflix-zuul/src/test/java/org/springframework/cloud/netflix/zuul/filters/route/SimpleHostRoutingFilterTests.java
View file @
b24a0524
...
...
@@ -212,6 +212,20 @@ public class SimpleHostRoutingFilterTests {
assertTrue
(
"Get 1"
.
equals
(
responseString
));
}
@Test
public
void
redirectTest
()
throws
Exception
{
setupContext
();
InputStreamEntity
inputStreamEntity
=
new
InputStreamEntity
(
new
ByteArrayInputStream
(
new
byte
[]{}));
HttpRequest
httpRequest
=
getFilter
().
buildHttpRequest
(
"GET"
,
"/app/redirect"
,
inputStreamEntity
,
new
LinkedMultiValueMap
<
String
,
String
>(),
new
LinkedMultiValueMap
<
String
,
String
>(),
new
MockHttpServletRequest
());
CloseableHttpResponse
response
=
getFilter
().
newClient
().
execute
(
new
HttpHost
(
"localhost"
,
this
.
port
),
httpRequest
);
assertEquals
(
302
,
response
.
getStatusLine
().
getStatusCode
());
String
responseString
=
copyToString
(
response
.
getEntity
().
getContent
(),
Charset
.
forName
(
"UTF-8"
));
assertTrue
(
response
.
getLastHeader
(
"Location"
).
getValue
().
contains
(
"/app/get/5"
));
}
@Test
public
void
zuulHostKeysUpdateHttpClient
()
{
setupContext
();
...
...
@@ -357,6 +371,12 @@ class SampleApplication {
public
String
getString
(
@PathVariable
String
id
,
HttpServletResponse
response
)
throws
IOException
{
return
"Get "
+
id
;
}
@RequestMapping
(
value
=
"/redirect"
,
method
=
RequestMethod
.
GET
)
public
String
redirect
(
HttpServletResponse
response
)
throws
IOException
{
response
.
sendRedirect
(
"/app/get/5"
);
return
null
;
}
}
class
GZIPCompression
{
...
...
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