From 03caa1b8cee8eeee22a2e516d07c962ade75419f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Lagraulet?= Date: Thu, 11 Aug 2016 09:41:15 +0200 Subject: [PATCH] Remove deprecated and unused constructors for RibbonCommandContext and RestClientRibbonCommand --- .../route/RestClientRibbonCommand.java | 10 ------ .../filters/route/RibbonCommandContext.java | 13 ------- .../apache/RibbonApacheHttpRequestTests.java | 6 ++-- .../okhttp/OkHttpRibbonRequestTests.java | 34 ++++++++++++------- .../route/RestClientRibbonCommandTests.java | 7 ++-- 5 files changed, 30 insertions(+), 40 deletions(-) diff --git a/spring-cloud-netflix-core/src/main/java/org/springframework/cloud/netflix/zuul/filters/route/RestClientRibbonCommand.java b/spring-cloud-netflix-core/src/main/java/org/springframework/cloud/netflix/zuul/filters/route/RestClientRibbonCommand.java index 5c1c7ff6..39c850a4 100644 --- a/spring-cloud-netflix-core/src/main/java/org/springframework/cloud/netflix/zuul/filters/route/RestClientRibbonCommand.java +++ b/spring-cloud-netflix-core/src/main/java/org/springframework/cloud/netflix/zuul/filters/route/RestClientRibbonCommand.java @@ -39,16 +39,6 @@ import com.netflix.niws.client.http.RestClient; @SuppressWarnings("deprecation") public class RestClientRibbonCommand extends AbstractRibbonCommand { - @SuppressWarnings("unused") - @Deprecated - public RestClientRibbonCommand(String commandKey, RestClient restClient, HttpRequest.Verb verb, String uri, - Boolean retryable, MultiValueMap headers, - MultiValueMap params, InputStream requestEntity, - ZuulProperties zuulProperties) { - this(commandKey, restClient, - new RibbonCommandContext(commandKey, verb.verb(), uri, retryable, headers, params, requestEntity), zuulProperties); - } - public RestClientRibbonCommand(String commandKey, RestClient client, RibbonCommandContext context, ZuulProperties zuulProperties) { super(commandKey, client, context, zuulProperties); } diff --git a/spring-cloud-netflix-core/src/main/java/org/springframework/cloud/netflix/zuul/filters/route/RibbonCommandContext.java b/spring-cloud-netflix-core/src/main/java/org/springframework/cloud/netflix/zuul/filters/route/RibbonCommandContext.java index eaed3cbb..a558c5fd 100644 --- a/spring-cloud-netflix-core/src/main/java/org/springframework/cloud/netflix/zuul/filters/route/RibbonCommandContext.java +++ b/spring-cloud-netflix-core/src/main/java/org/springframework/cloud/netflix/zuul/filters/route/RibbonCommandContext.java @@ -19,13 +19,11 @@ package org.springframework.cloud.netflix.zuul.filters.route; import java.io.InputStream; import java.net.URI; import java.net.URISyntaxException; -import java.util.ArrayList; import java.util.List; import org.springframework.cloud.netflix.ribbon.support.RibbonRequestCustomizer; import org.springframework.util.MultiValueMap; import org.springframework.util.ReflectionUtils; -import org.springframework.util.StringUtils; import lombok.AllArgsConstructor; import lombok.Data; @@ -55,17 +53,6 @@ public class RibbonCommandContext { private final List requestCustomizers; private Long contentLength; - public RibbonCommandContext(String serviceId, String method, String uri, - Boolean retryable, MultiValueMap headers, - MultiValueMap params, InputStream requestEntity) { - this(serviceId, method, uri, retryable, headers, params, requestEntity, - new ArrayList(), - headers.containsKey("Content-Length") && StringUtils - .hasText(headers.getFirst("Content-Length").toString()) - ? new Long(headers.getFirst("Content-Length").toString()) - : null); - } - public URI uri() { try { return new URI(this.uri); diff --git a/spring-cloud-netflix-core/src/test/java/org/springframework/cloud/netflix/ribbon/apache/RibbonApacheHttpRequestTests.java b/spring-cloud-netflix-core/src/test/java/org/springframework/cloud/netflix/ribbon/apache/RibbonApacheHttpRequestTests.java index c6972539..6a5f23fd 100644 --- a/spring-cloud-netflix-core/src/test/java/org/springframework/cloud/netflix/ribbon/apache/RibbonApacheHttpRequestTests.java +++ b/spring-cloud-netflix-core/src/test/java/org/springframework/cloud/netflix/ribbon/apache/RibbonApacheHttpRequestTests.java @@ -29,6 +29,7 @@ import java.io.ByteArrayInputStream; import java.io.IOException; import java.net.URI; import java.nio.charset.Charset; +import java.util.ArrayList; import java.util.Collections; import org.apache.http.HttpEntity; @@ -56,8 +57,9 @@ public class RibbonApacheHttpRequestTests { headers.add(HttpEncoding.CONTENT_LENGTH, "5192"); LinkedMultiValueMap params = new LinkedMultiValueMap<>(); params.add("myparam", "myparamval"); - RibbonApacheHttpRequest httpRequest = new RibbonApacheHttpRequest(new RibbonCommandContext("example", "GET", uri, false, - headers, params, null)); + RibbonApacheHttpRequest httpRequest = + new RibbonApacheHttpRequest( + new RibbonCommandContext("example", "GET", uri, false, headers, params, null, new ArrayList())); HttpUriRequest request = httpRequest.toRequest(RequestConfig.custom().build()); diff --git a/spring-cloud-netflix-core/src/test/java/org/springframework/cloud/netflix/ribbon/okhttp/OkHttpRibbonRequestTests.java b/spring-cloud-netflix-core/src/test/java/org/springframework/cloud/netflix/ribbon/okhttp/OkHttpRibbonRequestTests.java index 765ad2e3..d35ea62d 100644 --- a/spring-cloud-netflix-core/src/test/java/org/springframework/cloud/netflix/ribbon/okhttp/OkHttpRibbonRequestTests.java +++ b/spring-cloud-netflix-core/src/test/java/org/springframework/cloud/netflix/ribbon/okhttp/OkHttpRibbonRequestTests.java @@ -26,6 +26,7 @@ import static org.junit.Assert.assertThat; import java.io.ByteArrayInputStream; import java.io.IOException; +import java.util.ArrayList; import java.util.Collections; import org.junit.Test; @@ -48,35 +49,41 @@ public class OkHttpRibbonRequestTests { String uri = "http://example.com"; LinkedMultiValueMap headers = new LinkedMultiValueMap<>(); headers.add("my-header", "my-value"); - headers.add(HttpEncoding.CONTENT_LENGTH, "5192"); + // headers.add(HttpEncoding.CONTENT_LENGTH, "5192"); LinkedMultiValueMap params = new LinkedMultiValueMap<>(); params.add("myparam", "myparamval"); - RibbonCommandContext context = new RibbonCommandContext("example", "GET", uri, false, headers, params, null); + RibbonCommandContext context = new RibbonCommandContext("example", "GET", uri, + false, headers, params, null, new ArrayList()); OkHttpRibbonRequest httpRequest = new OkHttpRibbonRequest(context); Request request = httpRequest.toRequest(); assertThat("body is not null", request.body(), is(nullValue())); assertThat("uri is wrong", request.url().toString(), startsWith(uri)); - assertThat("my-header is wrong", request.header("my-header"), is(equalTo("my-value"))); - assertThat("Content-Length is wrong", request.header(HttpEncoding.CONTENT_LENGTH), is(equalTo("5192"))); - assertThat("myparam is missing", request.url().queryParameter("myparam"), is(equalTo("myparamval"))); + assertThat("my-header is wrong", request.header("my-header"), + is(equalTo("my-value"))); + assertThat("myparam is missing", request.url().queryParameter("myparam"), + is(equalTo("myparamval"))); } @Test - // this situation happens, see https://github.com/spring-cloud/spring-cloud-netflix/issues/1042#issuecomment-227723877 + // this situation happens, see + // https://github.com/spring-cloud/spring-cloud-netflix/issues/1042#issuecomment-227723877 public void testEmptyEntityGet() throws Exception { String entityValue = ""; - testEntity(entityValue, new ByteArrayInputStream(entityValue.getBytes()), false, "GET"); + testEntity(entityValue, new ByteArrayInputStream(entityValue.getBytes()), false, + "GET"); } @Test public void testNonEmptyEntityPost() throws Exception { String entityValue = "abcd"; - testEntity(entityValue, new ByteArrayInputStream(entityValue.getBytes()), true, "POST"); + testEntity(entityValue, new ByteArrayInputStream(entityValue.getBytes()), true, + "POST"); } - void testEntity(String entityValue, ByteArrayInputStream requestEntity, boolean addContentLengthHeader, String method) throws IOException { + void testEntity(String entityValue, ByteArrayInputStream requestEntity, + boolean addContentLengthHeader, String method) throws IOException { String lengthString = String.valueOf(entityValue.length()); Long length = null; String uri = "http://example.com"; @@ -97,8 +104,9 @@ public class OkHttpRibbonRequestTests { builder.addHeader("from-customizer", "foo"); } }; - RibbonCommandContext context = new RibbonCommandContext("example", method, uri, false, - headers, new LinkedMultiValueMap(), requestEntity, Collections.singletonList(requestCustomizer)); + RibbonCommandContext context = new RibbonCommandContext("example", method, uri, + false, headers, new LinkedMultiValueMap(), requestEntity, + Collections.singletonList(requestCustomizer)); context.setContentLength(length); OkHttpRibbonRequest httpRequest = new OkHttpRibbonRequest(context); @@ -115,7 +123,8 @@ public class OkHttpRibbonRequestTests { if (!method.equalsIgnoreCase("get")) { assertThat("body is null", request.body(), is(notNullValue())); RequestBody body = request.body(); - assertThat("contentLength is wrong", body.contentLength(), is(equalTo((long) entityValue.length()))); + assertThat("contentLength is wrong", body.contentLength(), + is(equalTo((long) entityValue.length()))); Buffer content = new Buffer(); body.writeTo(content); String string = content.readByteString().utf8(); @@ -123,4 +132,3 @@ public class OkHttpRibbonRequestTests { } } } - diff --git a/spring-cloud-netflix-core/src/test/java/org/springframework/cloud/netflix/zuul/filters/route/RestClientRibbonCommandTests.java b/spring-cloud-netflix-core/src/test/java/org/springframework/cloud/netflix/zuul/filters/route/RestClientRibbonCommandTests.java index 244c5d5b..5b4671d4 100644 --- a/spring-cloud-netflix-core/src/test/java/org/springframework/cloud/netflix/zuul/filters/route/RestClientRibbonCommandTests.java +++ b/spring-cloud-netflix-core/src/test/java/org/springframework/cloud/netflix/zuul/filters/route/RestClientRibbonCommandTests.java @@ -27,6 +27,7 @@ import java.io.ByteArrayInputStream; import java.io.InputStream; import java.net.URI; import java.nio.charset.Charset; +import java.util.ArrayList; import java.util.Collections; import org.junit.Before; @@ -57,8 +58,10 @@ public class RestClientRibbonCommandTests { headers.add("my-header", "my-value"); LinkedMultiValueMap params = new LinkedMultiValueMap<>(); params.add("myparam", "myparamval"); - RestClientRibbonCommand command = new RestClientRibbonCommand("cmd", null, new RibbonCommandContext("example", "GET", uri, false, - headers, params, null), zuulProperties); + RestClientRibbonCommand command = + new RestClientRibbonCommand("cmd", null, + new RibbonCommandContext("example", "GET", uri, false, headers, params, null,new ArrayList()), + zuulProperties); HttpRequest request = command.createRequest();