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
02948657
Unverified
Commit
02948657
authored
Jun 16, 2016
by
Spencer Gibb
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Don't send 4xx errors to /error
fixes gh-1110
parent
cfb13ac5
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
23 additions
and
26 deletions
+23
-26
RibbonRoutingFilter.java
...cloud/netflix/zuul/filters/route/RibbonRoutingFilter.java
+0
-9
SimpleHostRoutingFilter.java
...d/netflix/zuul/filters/route/SimpleHostRoutingFilter.java
+0
-8
SampleZuulProxyApplicationTests.java
...k/cloud/netflix/zuul/SampleZuulProxyApplicationTests.java
+4
-2
ZuulProxyTestBase.java
...springframework/cloud/netflix/zuul/ZuulProxyTestBase.java
+19
-7
No files found.
spring-cloud-netflix-core/src/main/java/org/springframework/cloud/netflix/zuul/filters/route/RibbonRoutingFilter.java
View file @
02948657
...
...
@@ -78,7 +78,6 @@ public class RibbonRoutingFilter extends ZuulFilter {
RibbonCommandContext
commandContext
=
buildCommandContext
(
context
);
ClientHttpResponse
response
=
forward
(
commandContext
);
setResponse
(
response
);
setErrorCodeFor4xx
(
context
,
response
);
return
response
;
}
catch
(
ZuulException
ex
)
{
...
...
@@ -94,14 +93,6 @@ public class RibbonRoutingFilter extends ZuulFilter {
return
null
;
}
private
void
setErrorCodeFor4xx
(
RequestContext
context
,
ClientHttpResponse
response
)
throws
IOException
{
HttpStatus
httpStatus
=
response
.
getStatusCode
();
if
(
httpStatus
.
is4xxClientError
())
{
context
.
set
(
ERROR_STATUS_CODE
,
httpStatus
.
value
());
}
}
protected
RibbonCommandContext
buildCommandContext
(
RequestContext
context
)
{
HttpServletRequest
request
=
context
.
getRequest
();
...
...
spring-cloud-netflix-core/src/main/java/org/springframework/cloud/netflix/zuul/filters/route/SimpleHostRoutingFilter.java
View file @
02948657
...
...
@@ -175,7 +175,6 @@ public class SimpleHostRoutingFilter extends ZuulFilter {
HttpResponse
response
=
forward
(
this
.
httpClient
,
verb
,
uri
,
request
,
headers
,
params
,
requestEntity
);
setResponse
(
response
);
setErrorCodeFor4xx
(
context
,
response
);
}
catch
(
Exception
ex
)
{
context
.
set
(
ERROR_STATUS_CODE
,
...
...
@@ -185,13 +184,6 @@ public class SimpleHostRoutingFilter extends ZuulFilter {
return
null
;
}
private
void
setErrorCodeFor4xx
(
RequestContext
context
,
HttpResponse
response
)
{
HttpStatus
httpStatus
=
HttpStatus
.
valueOf
(
response
.
getStatusLine
().
getStatusCode
());
if
(
httpStatus
.
is4xxClientError
())
{
context
.
set
(
ERROR_STATUS_CODE
,
httpStatus
.
value
());
}
}
protected
PoolingHttpClientConnectionManager
newConnectionManager
()
{
try
{
final
SSLContext
sslContext
=
SSLContext
.
getInstance
(
"SSL"
);
...
...
spring-cloud-netflix-core/src/test/java/org/springframework/cloud/netflix/zuul/SampleZuulProxyApplicationTests.java
View file @
02948657
...
...
@@ -113,11 +113,13 @@ public class SampleZuulProxyApplicationTests extends ZuulProxyTestBase {
public
void
simpleHostRouteWithNonExistentUrl
()
{
this
.
routes
.
addRoute
(
"/self/**"
,
"http://localhost:"
+
this
.
port
+
"/"
);
this
.
endpoint
.
reset
();
String
uri
=
"/self/nonExistentUrl"
;
this
.
myErrorController
.
setUriToMatch
(
uri
);
ResponseEntity
<
String
>
result
=
new
TestRestTemplate
().
exchange
(
"http://localhost:"
+
this
.
port
+
"/self/nonExistentUrl"
,
HttpMethod
.
GET
,
"http://localhost:"
+
this
.
port
+
uri
,
HttpMethod
.
GET
,
new
HttpEntity
<>((
Void
)
null
),
String
.
class
);
assertEquals
(
HttpStatus
.
NOT_FOUND
,
result
.
getStatusCode
());
assert
Tru
e
(
this
.
myErrorController
.
wasControllerUsed
());
assert
Fals
e
(
this
.
myErrorController
.
wasControllerUsed
());
}
@Test
...
...
spring-cloud-netflix-core/src/test/java/org/springframework/cloud/netflix/zuul/ZuulProxyTestBase.java
View file @
02948657
...
...
@@ -43,7 +43,6 @@ import com.netflix.zuul.context.RequestContext;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
junit
.
Assert
.
assertFalse
;
import
static
org
.
junit
.
Assert
.
assertTrue
;
/**
* @author Spencer Gibb
...
...
@@ -155,8 +154,10 @@ public abstract class ZuulProxyTestBase {
@Test
public
void
ribbonRouteWithSpace
()
{
String
uri
=
"/simple/spa ce"
;
this
.
myErrorController
.
setUriToMatch
(
uri
);
ResponseEntity
<
String
>
result
=
new
TestRestTemplate
().
exchange
(
"http://localhost:"
+
this
.
port
+
"/simple/spa ce"
,
HttpMethod
.
GET
,
"http://localhost:"
+
this
.
port
+
uri
,
HttpMethod
.
GET
,
new
HttpEntity
<>((
Void
)
null
),
String
.
class
);
assertEquals
(
HttpStatus
.
OK
,
result
.
getStatusCode
());
assertEquals
(
"Hello space"
,
result
.
getBody
());
...
...
@@ -165,11 +166,13 @@ public abstract class ZuulProxyTestBase {
@Test
public
void
ribbonRouteWithNonExistentUri
()
{
String
uri
=
"/simple/nonExistent"
;
this
.
myErrorController
.
setUriToMatch
(
uri
);
ResponseEntity
<
String
>
result
=
new
TestRestTemplate
().
exchange
(
"http://localhost:"
+
this
.
port
+
"/simple/nonExistent"
,
HttpMethod
.
GET
,
"http://localhost:"
+
this
.
port
+
uri
,
HttpMethod
.
GET
,
new
HttpEntity
<>((
Void
)
null
),
String
.
class
);
assertEquals
(
HttpStatus
.
NOT_FOUND
,
result
.
getStatusCode
());
assert
Tru
e
(
myErrorController
.
wasControllerUsed
());
assert
Fals
e
(
myErrorController
.
wasControllerUsed
());
}
@Test
...
...
@@ -325,6 +328,7 @@ class AnotherRibbonClientConfiguration {
}
class
MyErrorController
extends
BasicErrorController
{
ThreadLocal
<
String
>
uriToMatch
=
new
ThreadLocal
<>();
AtomicBoolean
controllerUsed
=
new
AtomicBoolean
();
...
...
@@ -334,10 +338,19 @@ class MyErrorController extends BasicErrorController {
@Override
public
ResponseEntity
<
Map
<
String
,
Object
>>
error
(
HttpServletRequest
request
)
{
controllerUsed
.
set
(
true
);
String
errorUri
=
(
String
)
request
.
getAttribute
(
"javax.servlet.error.request_uri"
);
if
(
errorUri
!=
null
&&
errorUri
.
equals
(
this
.
uriToMatch
.
get
()))
{
controllerUsed
.
set
(
true
);
}
this
.
uriToMatch
.
remove
();
return
super
.
error
(
request
);
}
public
void
setUriToMatch
(
String
uri
)
{
this
.
uriToMatch
.
set
(
uri
);
}
public
boolean
wasControllerUsed
()
{
return
this
.
controllerUsed
.
get
();
}
...
...
@@ -345,4 +358,4 @@ class MyErrorController extends BasicErrorController {
public
void
clear
()
{
this
.
controllerUsed
.
set
(
false
);
}
}
\ 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