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
d3385f8c
Commit
d3385f8c
authored
Jan 19, 2018
by
Ryan Baxter
Browse files
Options
Browse Files
Download
Plain Diff
Merge remote-tracking branch 'origin/1.4.x'
parents
6bfb7c6d
d51112e6
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
28 additions
and
27 deletions
+28
-27
RetryableRibbonLoadBalancingHttpClient.java
...ribbon/apache/RetryableRibbonLoadBalancingHttpClient.java
+27
-26
RibbonLoadBalancingHttpClientTests.java
...lix/ribbon/apache/RibbonLoadBalancingHttpClientTests.java
+1
-1
No files found.
spring-cloud-netflix-ribbon/src/main/java/org/springframework/cloud/netflix/ribbon/apache/RetryableRibbonLoadBalancingHttpClient.java
View file @
d3385f8c
...
...
@@ -16,7 +16,6 @@
package
org
.
springframework
.
cloud
.
netflix
.
ribbon
.
apache
;
import
java.io.IOException
;
import
java.net.URI
;
import
org.apache.commons.lang.BooleanUtils
;
import
org.apache.http.HttpResponse
;
import
org.apache.http.client.config.RequestConfig
;
...
...
@@ -42,6 +41,7 @@ import org.springframework.retry.policy.NeverRetryPolicy;
import
org.springframework.retry.support.RetryTemplate
;
import
org.springframework.cloud.netflix.ribbon.RibbonLoadBalancerClient
;
import
org.springframework.cloud.netflix.ribbon.ServerIntrospector
;
import
org.springframework.web.util.UriComponentsBuilder
;
import
com.netflix.client.RequestSpecificRetryHandler
;
import
com.netflix.client.RetryHandler
;
import
com.netflix.client.config.IClientConfig
;
...
...
@@ -112,31 +112,32 @@ public class RetryableRibbonLoadBalancingHttpClient extends RibbonLoadBalancingH
final
RequestConfig
requestConfig
=
builder
.
build
();
final
LoadBalancedRetryPolicy
retryPolicy
=
loadBalancedRetryPolicyFactory
.
create
(
this
.
getClientName
(),
this
);
RetryCallback
retryCallback
=
context
->
{
//on retries the policy will choose the server and set it in the context
//extract the server and update the request being made
RibbonApacheHttpRequest
newRequest
=
request
;
if
(
context
instanceof
LoadBalancedRetryContext
)
{
ServiceInstance
service
=
((
LoadBalancedRetryContext
)
context
).
getServiceInstance
();
if
(
service
!=
null
)
{
//Reconstruct the request URI using the host and port set in the retry context
newRequest
=
newRequest
.
withNewUri
(
new
URI
(
service
.
getUri
().
getScheme
(),
newRequest
.
getURI
().
getUserInfo
(),
service
.
getHost
(),
service
.
getPort
(),
newRequest
.
getURI
().
getPath
(),
newRequest
.
getURI
().
getQuery
(),
newRequest
.
getURI
().
getFragment
()));
}
}
newRequest
=
getSecureRequest
(
request
,
configOverride
);
HttpUriRequest
httpUriRequest
=
newRequest
.
toRequest
(
requestConfig
);
final
HttpResponse
httpResponse
=
RetryableRibbonLoadBalancingHttpClient
.
this
.
delegate
.
execute
(
httpUriRequest
);
if
(
retryPolicy
.
retryableStatusCode
(
httpResponse
.
getStatusLine
().
getStatusCode
()))
{
if
(
CloseableHttpResponse
.
class
.
isInstance
(
httpResponse
))
{
((
CloseableHttpResponse
)
httpResponse
).
close
();
}
throw
new
RetryableStatusCodeException
(
RetryableRibbonLoadBalancingHttpClient
.
this
.
clientName
,
httpResponse
.
getStatusLine
().
getStatusCode
());
}
return
new
RibbonApacheHttpResponse
(
httpResponse
,
httpUriRequest
.
getURI
());
};
//on retries the policy will choose the server and set it in the context
//extract the server and update the request being made
RibbonApacheHttpRequest
newRequest
=
request
;
if
(
context
instanceof
LoadBalancedRetryContext
)
{
ServiceInstance
service
=
((
LoadBalancedRetryContext
)
context
).
getServiceInstance
();
if
(
service
!=
null
)
{
//Reconstruct the request URI using the host and port set in the retry context
newRequest
=
newRequest
.
withNewUri
(
UriComponentsBuilder
.
newInstance
().
host
(
service
.
getHost
())
.
scheme
(
service
.
getUri
().
getScheme
()).
userInfo
(
newRequest
.
getURI
().
getUserInfo
())
.
port
(
service
.
getPort
()).
path
(
newRequest
.
getURI
().
getPath
())
.
query
(
newRequest
.
getURI
().
getQuery
()).
fragment
(
newRequest
.
getURI
().
getFragment
())
.
build
().
encode
().
toUri
());
}
}
newRequest
=
getSecureRequest
(
newRequest
,
configOverride
);
HttpUriRequest
httpUriRequest
=
newRequest
.
toRequest
(
requestConfig
);
final
HttpResponse
httpResponse
=
RetryableRibbonLoadBalancingHttpClient
.
this
.
delegate
.
execute
(
httpUriRequest
);
if
(
retryPolicy
.
retryableStatusCode
(
httpResponse
.
getStatusLine
().
getStatusCode
()))
{
if
(
CloseableHttpResponse
.
class
.
isInstance
(
httpResponse
))
{
((
CloseableHttpResponse
)
httpResponse
).
close
();
}
throw
new
RetryableStatusCodeException
(
RetryableRibbonLoadBalancingHttpClient
.
this
.
clientName
,
httpResponse
.
getStatusLine
().
getStatusCode
());
}
return
new
RibbonApacheHttpResponse
(
httpResponse
,
httpUriRequest
.
getURI
());
};
return
this
.
executeWithRetry
(
request
,
retryPolicy
,
retryCallback
);
}
...
...
spring-cloud-netflix-ribbon/src/test/java/org/springframework/cloud/netflix/ribbon/apache/RibbonLoadBalancingHttpClientTests.java
View file @
d3385f8c
...
...
@@ -430,7 +430,7 @@ public class RibbonLoadBalancingHttpClientTests {
String
host
=
serviceName
;
int
port
=
80
;
HttpMethod
method
=
HttpMethod
.
GET
;
final
URI
uri
=
new
URI
(
"https://"
+
host
+
":"
+
port
+
"/a%2
B
b"
);
final
URI
uri
=
new
URI
(
"https://"
+
host
+
":"
+
port
+
"/a%2
0
b"
);
RibbonCommandContext
context
=
new
RibbonCommandContext
(
serviceName
,
method
.
toString
(),
uri
.
toString
(),
true
,
new
LinkedMultiValueMap
<
String
,
String
>(),
new
LinkedMultiValueMap
<
String
,
String
>(),
new
ByteArrayInputStream
(
new
String
(
"bar"
).
getBytes
()),
...
...
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