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
d4e7f25e
Commit
d4e7f25e
authored
Jan 22, 2018
by
Ryan Baxter
Browse files
Options
Browse Files
Download
Plain Diff
Merge remote-tracking branch 'origin/1.4.x'
parents
e0ad44f2
ff68e0f6
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
101 additions
and
3 deletions
+101
-3
RibbonRoutingFilter.java
...cloud/netflix/zuul/filters/route/RibbonRoutingFilter.java
+2
-3
RibbonRoutingFilterTests.java
.../netflix/zuul/filters/route/RibbonRoutingFilterTests.java
+99
-0
No files found.
spring-cloud-netflix-zuul/src/main/java/org/springframework/cloud/netflix/zuul/filters/route/RibbonRoutingFilter.java
View file @
d4e7f25e
...
...
@@ -157,8 +157,7 @@ public class RibbonRoutingFilter extends ZuulFilter {
RibbonCommand
command
=
this
.
ribbonCommandFactory
.
create
(
context
);
try
{
ClientHttpResponse
response
=
command
.
execute
();
this
.
helper
.
appendDebug
(
info
,
response
.
getStatusCode
().
value
(),
response
.
getHeaders
());
this
.
helper
.
appendDebug
(
info
,
response
.
getRawStatusCode
(),
response
.
getHeaders
());
return
response
;
}
catch
(
HystrixRuntimeException
ex
)
{
...
...
@@ -226,7 +225,7 @@ public class RibbonRoutingFilter extends ZuulFilter {
protected
void
setResponse
(
ClientHttpResponse
resp
)
throws
ClientException
,
IOException
{
RequestContext
.
getCurrentContext
().
set
(
"zuulResponse"
,
resp
);
this
.
helper
.
setResponse
(
resp
.
get
StatusCode
().
valu
e
(),
this
.
helper
.
setResponse
(
resp
.
get
RawStatusCod
e
(),
resp
.
getBody
()
==
null
?
null
:
resp
.
getBody
(),
resp
.
getHeaders
());
}
...
...
spring-cloud-netflix-zuul/src/test/java/org/springframework/cloud/netflix/zuul/filters/route/RibbonRoutingFilterTests.java
View file @
d4e7f25e
...
...
@@ -17,6 +17,9 @@
package
org
.
springframework
.
cloud
.
netflix
.
zuul
.
filters
.
route
;
import
java.io.ByteArrayInputStream
;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.util.Collections
;
import
com.netflix.zuul.context.RequestContext
;
...
...
@@ -26,7 +29,14 @@ import org.junit.Test;
import
org.springframework.cloud.netflix.ribbon.support.RibbonCommandContext
;
import
org.springframework.cloud.netflix.ribbon.support.RibbonRequestCustomizer
;
import
org.springframework.cloud.netflix.zuul.filters.ProxyRequestHelper
;
import
org.springframework.http.HttpHeaders
;
import
org.springframework.http.HttpStatus
;
import
org.springframework.http.MediaType
;
import
org.springframework.http.client.ClientHttpResponse
;
import
org.springframework.mock.web.MockHttpServletRequest
;
import
org.springframework.mock.web.MockHttpServletResponse
;
import
javax.servlet.http.HttpServletResponse
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
import
static
org
.
mockito
.
Mockito
.
mock
;
...
...
@@ -36,6 +46,7 @@ import static org.springframework.cloud.netflix.zuul.filters.support.FilterConst
/**
* @author Spencer Gibb
* @author Yongsung Yoon
* @author Gang Li
*/
public
class
RibbonRoutingFilterTests
{
...
...
@@ -75,18 +86,106 @@ public class RibbonRoutingFilterTests {
assertThat
(
commandContext
.
getLoadBalancerKey
()).
isNull
();
}
@Test
public
void
testSetResponseWithNonHttpStatusCode
()
throws
Exception
{
ClientHttpResponse
response
=
this
.
createClientHttpResponseWithNonStatus
();
this
.
filter
.
setResponse
(
response
);
assertThat
(
517
).
isEqualTo
(
this
.
requestContext
.
get
(
"responseStatusCode"
));
}
@Test
public
void
testSetResponseWithHttpStatusCode
()
throws
Exception
{
ClientHttpResponse
response
=
this
.
createClientHttpResponse
();
this
.
filter
.
setResponse
(
response
);
assertThat
(
200
).
isEqualTo
(
this
.
requestContext
.
get
(
"responseStatusCode"
));
}
private
void
setUpRequestContext
()
{
requestContext
=
RequestContext
.
getCurrentContext
();
MockHttpServletRequest
mockRequest
=
new
MockHttpServletRequest
();
HttpServletResponse
httpServletResponse
=
new
MockHttpServletResponse
();
mockRequest
.
setMethod
(
"GET"
);
mockRequest
.
setRequestURI
(
"/foo/bar"
);
requestContext
.
setRequest
(
mockRequest
);
requestContext
.
setRequestQueryParams
(
Collections
.
EMPTY_MAP
);
requestContext
.
set
(
SERVICE_ID_KEY
,
"testServiceId"
);
requestContext
.
set
(
"response"
,
httpServletResponse
);
}
private
void
setupRibbonRoutingFilter
()
{
RibbonCommandFactory
factory
=
mock
(
RibbonCommandFactory
.
class
);
filter
=
new
RibbonRoutingFilter
(
new
ProxyRequestHelper
(),
factory
,
Collections
.<
RibbonRequestCustomizer
>
emptyList
());
}
private
ClientHttpResponse
createClientHttpResponseWithNonStatus
()
{
return
new
ClientHttpResponse
()
{
@Override
public
HttpStatus
getStatusCode
()
throws
IOException
{
return
null
;
}
@Override
public
int
getRawStatusCode
()
throws
IOException
{
return
517
;
}
@Override
public
String
getStatusText
()
throws
IOException
{
return
"Fail"
;
}
@Override
public
void
close
()
{
}
@Override
public
InputStream
getBody
()
throws
IOException
{
return
new
ByteArrayInputStream
(
"Fail"
.
getBytes
());
}
@Override
public
HttpHeaders
getHeaders
()
{
HttpHeaders
httpHeaders
=
new
HttpHeaders
();
httpHeaders
.
setContentType
(
MediaType
.
APPLICATION_JSON
);
return
httpHeaders
;
}
};
}
private
ClientHttpResponse
createClientHttpResponse
()
{
return
new
ClientHttpResponse
()
{
@Override
public
HttpStatus
getStatusCode
()
throws
IOException
{
return
HttpStatus
.
OK
;
}
@Override
public
int
getRawStatusCode
()
throws
IOException
{
return
200
;
}
@Override
public
String
getStatusText
()
throws
IOException
{
return
"OK"
;
}
@Override
public
void
close
()
{
}
@Override
public
InputStream
getBody
()
throws
IOException
{
return
new
ByteArrayInputStream
(
"OK"
.
getBytes
());
}
@Override
public
HttpHeaders
getHeaders
()
{
HttpHeaders
httpHeaders
=
new
HttpHeaders
();
httpHeaders
.
setContentType
(
MediaType
.
APPLICATION_JSON
);
return
httpHeaders
;
}
};
}
}
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