use of org.springframework.cloud.netflix.ribbon.support.RibbonRequestCustomizer in project spring-cloud-netflix by spring-cloud.
the class RibbonLoadBalancingHttpClientTests method testDoubleEncodingWithRetry.
@Test
public void testDoubleEncodingWithRetry() throws Exception {
int retriesNextServer = 0;
int retriesSameServer = 0;
boolean retryable = true;
boolean retryOnAllOps = true;
String serviceName = "foo";
String host = serviceName;
int port = 80;
HttpMethod method = HttpMethod.GET;
final URI uri = new URI("https://" + host + ":" + port + "/a%20b");
RibbonCommandContext context = new RibbonCommandContext(serviceName, method.toString(), uri.toString(), true, new LinkedMultiValueMap<String, String>(), new LinkedMultiValueMap<String, String>(), new ByteArrayInputStream(new String("bar").getBytes()), new ArrayList<RibbonRequestCustomizer>());
RibbonApacheHttpRequest request = new RibbonApacheHttpRequest(context);
CloseableHttpClient delegate = mock(CloseableHttpClient.class);
final CloseableHttpResponse response = mock(CloseableHttpResponse.class);
StatusLine statusLine = mock(StatusLine.class);
doReturn(200).when(statusLine).getStatusCode();
doReturn(statusLine).when(response).getStatusLine();
doReturn(response).when(delegate).execute(any(HttpUriRequest.class));
ILoadBalancer lb = mock(ILoadBalancer.class);
RetryableRibbonLoadBalancingHttpClient client = setupClientForRetry(retriesNextServer, retriesSameServer, retryable, retryOnAllOps, serviceName, host, port, delegate, lb, "", null, true);
client.execute(request, null);
verify(response, times(0)).close();
verify(delegate, times(1)).execute(argThat(new ArgumentMatcher<HttpUriRequest>() {
@Override
public boolean matches(HttpUriRequest argument) {
if (argument instanceof HttpUriRequest) {
HttpUriRequest arg = (HttpUriRequest) argument;
return arg.getURI().equals(uri);
}
return false;
}
}));
}
Aggregations