Search in sources :

Example 6 with RibbonRequestCustomizer

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;
        }
    }));
}
Also used : HttpUriRequest(org.apache.http.client.methods.HttpUriRequest) CloseableHttpClient(org.apache.http.impl.client.CloseableHttpClient) RibbonCommandContext(org.springframework.cloud.netflix.ribbon.support.RibbonCommandContext) RibbonRequestCustomizer(org.springframework.cloud.netflix.ribbon.support.RibbonRequestCustomizer) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) URI(java.net.URI) StatusLine(org.apache.http.StatusLine) ByteArrayInputStream(java.io.ByteArrayInputStream) ILoadBalancer(com.netflix.loadbalancer.ILoadBalancer) ArgumentMatcher(org.mockito.ArgumentMatcher) CloseableHttpResponse(org.apache.http.client.methods.CloseableHttpResponse) HttpMethod(org.springframework.http.HttpMethod) Test(org.junit.Test)

Aggregations

RibbonCommandContext (org.springframework.cloud.netflix.ribbon.support.RibbonCommandContext)6 RibbonRequestCustomizer (org.springframework.cloud.netflix.ribbon.support.RibbonRequestCustomizer)6 URI (java.net.URI)4 LinkedMultiValueMap (org.springframework.util.LinkedMultiValueMap)4 ByteArrayInputStream (java.io.ByteArrayInputStream)3 HttpUriRequest (org.apache.http.client.methods.HttpUriRequest)3 Test (org.junit.Test)3 Request (okhttp3.Request)2 StatusLine (org.apache.http.StatusLine)2 CloseableHttpResponse (org.apache.http.client.methods.CloseableHttpResponse)2 CloseableHttpClient (org.apache.http.impl.client.CloseableHttpClient)2 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)2 ArgumentMatcher (org.mockito.ArgumentMatcher)2 HttpMethod (org.springframework.http.HttpMethod)2 DefaultClientConfigImpl (com.netflix.client.config.DefaultClientConfigImpl)1 HttpRequest (com.netflix.client.http.HttpRequest)1 ILoadBalancer (com.netflix.loadbalancer.ILoadBalancer)1 InputStream (java.io.InputStream)1 RequestBody (okhttp3.RequestBody)1 Buffer (okio.Buffer)1