Commit d3385f8c by Ryan Baxter

Merge remote-tracking branch 'origin/1.4.x'

parents 6bfb7c6d d51112e6
...@@ -16,7 +16,6 @@ ...@@ -16,7 +16,6 @@
package org.springframework.cloud.netflix.ribbon.apache; package org.springframework.cloud.netflix.ribbon.apache;
import java.io.IOException; import java.io.IOException;
import java.net.URI;
import org.apache.commons.lang.BooleanUtils; import org.apache.commons.lang.BooleanUtils;
import org.apache.http.HttpResponse; import org.apache.http.HttpResponse;
import org.apache.http.client.config.RequestConfig; import org.apache.http.client.config.RequestConfig;
...@@ -42,6 +41,7 @@ import org.springframework.retry.policy.NeverRetryPolicy; ...@@ -42,6 +41,7 @@ import org.springframework.retry.policy.NeverRetryPolicy;
import org.springframework.retry.support.RetryTemplate; import org.springframework.retry.support.RetryTemplate;
import org.springframework.cloud.netflix.ribbon.RibbonLoadBalancerClient; import org.springframework.cloud.netflix.ribbon.RibbonLoadBalancerClient;
import org.springframework.cloud.netflix.ribbon.ServerIntrospector; import org.springframework.cloud.netflix.ribbon.ServerIntrospector;
import org.springframework.web.util.UriComponentsBuilder;
import com.netflix.client.RequestSpecificRetryHandler; import com.netflix.client.RequestSpecificRetryHandler;
import com.netflix.client.RetryHandler; import com.netflix.client.RetryHandler;
import com.netflix.client.config.IClientConfig; import com.netflix.client.config.IClientConfig;
...@@ -112,31 +112,32 @@ public class RetryableRibbonLoadBalancingHttpClient extends RibbonLoadBalancingH ...@@ -112,31 +112,32 @@ public class RetryableRibbonLoadBalancingHttpClient extends RibbonLoadBalancingH
final RequestConfig requestConfig = builder.build(); final RequestConfig requestConfig = builder.build();
final LoadBalancedRetryPolicy retryPolicy = loadBalancedRetryPolicyFactory.create(this.getClientName(), this); final LoadBalancedRetryPolicy retryPolicy = loadBalancedRetryPolicyFactory.create(this.getClientName(), this);
RetryCallback retryCallback = context -> { RetryCallback retryCallback = context -> {
//on retries the policy will choose the server and set it in the context //on retries the policy will choose the server and set it in the context
//extract the server and update the request being made //extract the server and update the request being made
RibbonApacheHttpRequest newRequest = request; RibbonApacheHttpRequest newRequest = request;
if(context instanceof LoadBalancedRetryContext) { if(context instanceof LoadBalancedRetryContext) {
ServiceInstance service = ((LoadBalancedRetryContext)context).getServiceInstance(); ServiceInstance service = ((LoadBalancedRetryContext)context).getServiceInstance();
if(service != null) { if(service != null) {
//Reconstruct the request URI using the host and port set in the retry context //Reconstruct the request URI using the host and port set in the retry context
newRequest = newRequest.withNewUri(new URI(service.getUri().getScheme(), newRequest = newRequest.withNewUri(UriComponentsBuilder.newInstance().host(service.getHost())
newRequest.getURI().getUserInfo(), service.getHost(), service.getPort(), .scheme(service.getUri().getScheme()).userInfo(newRequest.getURI().getUserInfo())
newRequest.getURI().getPath(), newRequest.getURI().getQuery(), .port(service.getPort()).path(newRequest.getURI().getPath())
newRequest.getURI().getFragment())); .query(newRequest.getURI().getQuery()).fragment(newRequest.getURI().getFragment())
} .build().encode().toUri());
} }
newRequest = getSecureRequest(request, configOverride); }
HttpUriRequest httpUriRequest = newRequest.toRequest(requestConfig); newRequest = getSecureRequest(newRequest, configOverride);
final HttpResponse httpResponse = RetryableRibbonLoadBalancingHttpClient.this.delegate.execute(httpUriRequest); HttpUriRequest httpUriRequest = newRequest.toRequest(requestConfig);
if(retryPolicy.retryableStatusCode(httpResponse.getStatusLine().getStatusCode())) { final HttpResponse httpResponse = RetryableRibbonLoadBalancingHttpClient.this.delegate.execute(httpUriRequest);
if(CloseableHttpResponse.class.isInstance(httpResponse)) { if(retryPolicy.retryableStatusCode(httpResponse.getStatusLine().getStatusCode())) {
((CloseableHttpResponse)httpResponse).close(); if(CloseableHttpResponse.class.isInstance(httpResponse)) {
} ((CloseableHttpResponse)httpResponse).close();
throw new RetryableStatusCodeException(RetryableRibbonLoadBalancingHttpClient.this.clientName, }
httpResponse.getStatusLine().getStatusCode()); throw new RetryableStatusCodeException(RetryableRibbonLoadBalancingHttpClient.this.clientName,
} httpResponse.getStatusLine().getStatusCode());
return new RibbonApacheHttpResponse(httpResponse, httpUriRequest.getURI()); }
}; return new RibbonApacheHttpResponse(httpResponse, httpUriRequest.getURI());
};
return this.executeWithRetry(request, retryPolicy, retryCallback); return this.executeWithRetry(request, retryPolicy, retryCallback);
} }
......
...@@ -430,7 +430,7 @@ public class RibbonLoadBalancingHttpClientTests { ...@@ -430,7 +430,7 @@ public class RibbonLoadBalancingHttpClientTests {
String host = serviceName; String host = serviceName;
int port = 80; int port = 80;
HttpMethod method = HttpMethod.GET; HttpMethod method = HttpMethod.GET;
final URI uri = new URI("https://" + host + ":" + port + "/a%2Bb"); final URI uri = new URI("https://" + host + ":" + port + "/a%20b");
RibbonCommandContext context = new RibbonCommandContext(serviceName, method.toString(), uri.toString(), true, RibbonCommandContext context = new RibbonCommandContext(serviceName, method.toString(), uri.toString(), true,
new LinkedMultiValueMap<String, String>(), new LinkedMultiValueMap<String, String>(), new LinkedMultiValueMap<String, String>(), new LinkedMultiValueMap<String, String>(),
new ByteArrayInputStream(new String("bar").getBytes()), new ByteArrayInputStream(new String("bar").getBytes()),
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment