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
47747f32
Commit
47747f32
authored
Feb 09, 2016
by
Spencer Gibb
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Polish and extensibility
parent
834dfe22
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
36 additions
and
28 deletions
+36
-28
RibbonRoutingFilter.java
...cloud/netflix/zuul/filters/route/RibbonRoutingFilter.java
+36
-28
No files found.
spring-cloud-netflix-core/src/main/java/org/springframework/cloud/netflix/zuul/filters/route/RibbonRoutingFilter.java
View file @
47747f32
...
...
@@ -24,6 +24,7 @@ import javax.servlet.http.HttpServletRequest;
import
javax.servlet.http.HttpServletResponse
;
import
org.springframework.cloud.netflix.zuul.filters.ProxyRequestHelper
;
import
org.springframework.http.HttpStatus
;
import
org.springframework.http.client.ClientHttpResponse
;
import
org.springframework.util.MultiValueMap
;
...
...
@@ -38,8 +39,8 @@ import lombok.extern.apachecommons.CommonsLog;
@CommonsLog
public
class
RibbonRoutingFilter
extends
ZuulFilter
{
pr
ivate
ProxyRequestHelper
helper
;
pr
ivate
RibbonCommandFactory
<?>
ribbonCommandFactory
;
pr
otected
ProxyRequestHelper
helper
;
pr
otected
RibbonCommandFactory
<?>
ribbonCommandFactory
;
public
RibbonRoutingFilter
(
ProxyRequestHelper
helper
,
RibbonCommandFactory
<?>
ribbonCommandFactory
)
{
...
...
@@ -90,7 +91,7 @@ public class RibbonRoutingFilter extends ZuulFilter {
return
null
;
}
pr
ivate
RibbonCommandContext
buildCommandContext
(
RequestContext
context
)
{
pr
otected
RibbonCommandContext
buildCommandContext
(
RequestContext
context
)
{
HttpServletRequest
request
=
context
.
getRequest
();
MultiValueMap
<
String
,
String
>
headers
=
this
.
helper
...
...
@@ -115,7 +116,7 @@ public class RibbonRoutingFilter extends ZuulFilter {
requestEntity
);
}
pr
ivate
ClientHttpResponse
forward
(
RibbonCommandContext
context
)
throws
Exception
{
pr
otected
ClientHttpResponse
forward
(
RibbonCommandContext
context
)
throws
Exception
{
Map
<
String
,
Object
>
info
=
this
.
helper
.
debug
(
context
.
getVerb
(),
context
.
getUri
(),
context
.
getHeaders
(),
context
.
getParams
(),
context
.
getRequestEntity
());
...
...
@@ -127,36 +128,43 @@ public class RibbonRoutingFilter extends ZuulFilter {
return
response
;
}
catch
(
HystrixRuntimeException
ex
)
{
info
.
put
(
"status"
,
"500"
);
ClientException
clientException
=
findClientException
(
ex
);
if
(
clientException
!=
null
)
{
int
statusCode
=
500
;
if
(
clientException
.
getErrorType
()
==
ClientException
.
ErrorType
.
SERVER_THROTTLED
)
{
statusCode
=
503
;
}
throw
new
ZuulException
(
clientException
,
"Forwarding error"
,
statusCode
,
clientException
.
getErrorType
().
toString
());
}
throw
new
ZuulException
(
ex
,
"Forwarding error"
,
500
,
ex
.
getFailureType
().
toString
());
return
handleException
(
info
,
ex
);
}
}
protected
ClientException
findClientException
(
HystrixRuntimeException
ex
)
{
if
(
ex
.
getCause
()
!=
null
&&
ex
.
getCause
()
instanceof
ClientException
)
{
return
(
ClientException
)
ex
.
getCause
();
protected
ClientHttpResponse
handleException
(
Map
<
String
,
Object
>
info
,
HystrixRuntimeException
ex
)
throws
ZuulException
{
int
statusCode
=
HttpStatus
.
INTERNAL_SERVER_ERROR
.
value
();
Throwable
cause
=
ex
;
String
message
=
ex
.
getFailureType
().
toString
();
ClientException
clientException
=
findClientException
(
ex
);
if
(
clientException
==
null
)
{
clientException
=
findClientException
(
ex
.
getFallbackException
());
}
if
(
ex
.
getFallbackException
()
!=
null
&&
ex
.
getFallbackException
().
getCause
()
!=
null
&&
ex
.
getFallbackException
().
getCause
()
instanceof
ClientException
)
{
return
(
ClientException
)
ex
.
getFallbackException
().
getCause
();
if
(
clientException
!=
null
)
{
if
(
clientException
.
getErrorType
()
==
ClientException
.
ErrorType
.
SERVER_THROTTLED
)
{
statusCode
=
HttpStatus
.
SERVICE_UNAVAILABLE
.
value
();
}
cause
=
clientException
;
message
=
clientException
.
getErrorType
().
toString
();
}
return
null
;
info
.
put
(
"status"
,
String
.
valueOf
(
statusCode
));
throw
new
ZuulException
(
cause
,
"Forwarding error"
,
statusCode
,
message
);
}
protected
ClientException
findClientException
(
Throwable
t
)
{
if
(
t
==
null
)
{
return
null
;
}
if
(
t
instanceof
ClientException
)
{
return
(
ClientException
)
t
;
}
return
findClientException
(
t
.
getCause
());
}
pr
ivate
InputStream
getRequestBody
(
HttpServletRequest
request
)
{
pr
otected
InputStream
getRequestBody
(
HttpServletRequest
request
)
{
InputStream
requestEntity
=
null
;
// ApacheHttpClient4Handler does not support body in delete requests
if
(
request
.
getMethod
().
equals
(
"DELETE"
))
{
...
...
@@ -175,7 +183,7 @@ public class RibbonRoutingFilter extends ZuulFilter {
return
requestEntity
;
}
pr
ivate
String
getVerb
(
HttpServletRequest
request
)
{
pr
otected
String
getVerb
(
HttpServletRequest
request
)
{
String
method
=
request
.
getMethod
();
if
(
method
==
null
)
{
return
"GET"
;
...
...
@@ -183,7 +191,7 @@ public class RibbonRoutingFilter extends ZuulFilter {
return
method
;
}
pr
ivate
void
setResponse
(
ClientHttpResponse
resp
)
pr
otected
void
setResponse
(
ClientHttpResponse
resp
)
throws
ClientException
,
IOException
{
this
.
helper
.
setResponse
(
resp
.
getStatusCode
().
value
(),
resp
.
getBody
()
==
null
?
null
:
resp
.
getBody
(),
resp
.
getHeaders
());
...
...
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