Browse Source

Remove deprecated and unused constructors for RibbonCommandContext and RestClientRibbonCommand

pull/6/head
Stéphane Lagraulet 8 years ago
parent
commit
03caa1b8ce
  1. 10
      spring-cloud-netflix-core/src/main/java/org/springframework/cloud/netflix/zuul/filters/route/RestClientRibbonCommand.java
  2. 13
      spring-cloud-netflix-core/src/main/java/org/springframework/cloud/netflix/zuul/filters/route/RibbonCommandContext.java
  3. 6
      spring-cloud-netflix-core/src/test/java/org/springframework/cloud/netflix/ribbon/apache/RibbonApacheHttpRequestTests.java
  4. 34
      spring-cloud-netflix-core/src/test/java/org/springframework/cloud/netflix/ribbon/okhttp/OkHttpRibbonRequestTests.java
  5. 7
      spring-cloud-netflix-core/src/test/java/org/springframework/cloud/netflix/zuul/filters/route/RestClientRibbonCommandTests.java

10
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") @SuppressWarnings("deprecation")
public class RestClientRibbonCommand extends AbstractRibbonCommand<RestClient, HttpRequest, HttpResponse> { public class RestClientRibbonCommand extends AbstractRibbonCommand<RestClient, HttpRequest, HttpResponse> {
@SuppressWarnings("unused")
@Deprecated
public RestClientRibbonCommand(String commandKey, RestClient restClient, HttpRequest.Verb verb, String uri,
Boolean retryable, MultiValueMap<String, String> headers,
MultiValueMap<String, String> 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) { public RestClientRibbonCommand(String commandKey, RestClient client, RibbonCommandContext context, ZuulProperties zuulProperties) {
super(commandKey, client, context, zuulProperties); super(commandKey, client, context, zuulProperties);
} }

13
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.io.InputStream;
import java.net.URI; import java.net.URI;
import java.net.URISyntaxException; import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.List; import java.util.List;
import org.springframework.cloud.netflix.ribbon.support.RibbonRequestCustomizer; import org.springframework.cloud.netflix.ribbon.support.RibbonRequestCustomizer;
import org.springframework.util.MultiValueMap; import org.springframework.util.MultiValueMap;
import org.springframework.util.ReflectionUtils; import org.springframework.util.ReflectionUtils;
import org.springframework.util.StringUtils;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.Data; import lombok.Data;
@ -55,17 +53,6 @@ public class RibbonCommandContext {
private final List<RibbonRequestCustomizer> requestCustomizers; private final List<RibbonRequestCustomizer> requestCustomizers;
private Long contentLength; private Long contentLength;
public RibbonCommandContext(String serviceId, String method, String uri,
Boolean retryable, MultiValueMap<String, String> headers,
MultiValueMap<String, String> params, InputStream requestEntity) {
this(serviceId, method, uri, retryable, headers, params, requestEntity,
new ArrayList<RibbonRequestCustomizer>(),
headers.containsKey("Content-Length") && StringUtils
.hasText(headers.getFirst("Content-Length").toString())
? new Long(headers.getFirst("Content-Length").toString())
: null);
}
public URI uri() { public URI uri() {
try { try {
return new URI(this.uri); return new URI(this.uri);

6
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.io.IOException;
import java.net.URI; import java.net.URI;
import java.nio.charset.Charset; import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import org.apache.http.HttpEntity; import org.apache.http.HttpEntity;
@ -56,8 +57,9 @@ public class RibbonApacheHttpRequestTests {
headers.add(HttpEncoding.CONTENT_LENGTH, "5192"); headers.add(HttpEncoding.CONTENT_LENGTH, "5192");
LinkedMultiValueMap<String, String> params = new LinkedMultiValueMap<>(); LinkedMultiValueMap<String, String> params = new LinkedMultiValueMap<>();
params.add("myparam", "myparamval"); params.add("myparam", "myparamval");
RibbonApacheHttpRequest httpRequest = new RibbonApacheHttpRequest(new RibbonCommandContext("example", "GET", uri, false, RibbonApacheHttpRequest httpRequest =
headers, params, null)); new RibbonApacheHttpRequest(
new RibbonCommandContext("example", "GET", uri, false, headers, params, null, new ArrayList<RibbonRequestCustomizer>()));
HttpUriRequest request = httpRequest.toRequest(RequestConfig.custom().build()); HttpUriRequest request = httpRequest.toRequest(RequestConfig.custom().build());

34
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.ByteArrayInputStream;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import org.junit.Test; import org.junit.Test;
@ -48,35 +49,41 @@ public class OkHttpRibbonRequestTests {
String uri = "http://example.com"; String uri = "http://example.com";
LinkedMultiValueMap<String, String> headers = new LinkedMultiValueMap<>(); LinkedMultiValueMap<String, String> headers = new LinkedMultiValueMap<>();
headers.add("my-header", "my-value"); headers.add("my-header", "my-value");
headers.add(HttpEncoding.CONTENT_LENGTH, "5192"); // headers.add(HttpEncoding.CONTENT_LENGTH, "5192");
LinkedMultiValueMap<String, String> params = new LinkedMultiValueMap<>(); LinkedMultiValueMap<String, String> params = new LinkedMultiValueMap<>();
params.add("myparam", "myparamval"); 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<RibbonRequestCustomizer>());
OkHttpRibbonRequest httpRequest = new OkHttpRibbonRequest(context); OkHttpRibbonRequest httpRequest = new OkHttpRibbonRequest(context);
Request request = httpRequest.toRequest(); Request request = httpRequest.toRequest();
assertThat("body is not null", request.body(), is(nullValue())); assertThat("body is not null", request.body(), is(nullValue()));
assertThat("uri is wrong", request.url().toString(), startsWith(uri)); assertThat("uri is wrong", request.url().toString(), startsWith(uri));
assertThat("my-header is wrong", request.header("my-header"), is(equalTo("my-value"))); assertThat("my-header is wrong", request.header("my-header"),
assertThat("Content-Length is wrong", request.header(HttpEncoding.CONTENT_LENGTH), is(equalTo("5192"))); is(equalTo("my-value")));
assertThat("myparam is missing", request.url().queryParameter("myparam"), is(equalTo("myparamval"))); assertThat("myparam is missing", request.url().queryParameter("myparam"),
is(equalTo("myparamval")));
} }
@Test @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 { public void testEmptyEntityGet() throws Exception {
String entityValue = ""; String entityValue = "";
testEntity(entityValue, new ByteArrayInputStream(entityValue.getBytes()), false, "GET"); testEntity(entityValue, new ByteArrayInputStream(entityValue.getBytes()), false,
"GET");
} }
@Test @Test
public void testNonEmptyEntityPost() throws Exception { public void testNonEmptyEntityPost() throws Exception {
String entityValue = "abcd"; 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()); String lengthString = String.valueOf(entityValue.length());
Long length = null; Long length = null;
String uri = "http://example.com"; String uri = "http://example.com";
@ -97,8 +104,9 @@ public class OkHttpRibbonRequestTests {
builder.addHeader("from-customizer", "foo"); builder.addHeader("from-customizer", "foo");
} }
}; };
RibbonCommandContext context = new RibbonCommandContext("example", method, uri, false, RibbonCommandContext context = new RibbonCommandContext("example", method, uri,
headers, new LinkedMultiValueMap<String, String>(), requestEntity, Collections.singletonList(requestCustomizer)); false, headers, new LinkedMultiValueMap<String, String>(), requestEntity,
Collections.singletonList(requestCustomizer));
context.setContentLength(length); context.setContentLength(length);
OkHttpRibbonRequest httpRequest = new OkHttpRibbonRequest(context); OkHttpRibbonRequest httpRequest = new OkHttpRibbonRequest(context);
@ -115,7 +123,8 @@ public class OkHttpRibbonRequestTests {
if (!method.equalsIgnoreCase("get")) { if (!method.equalsIgnoreCase("get")) {
assertThat("body is null", request.body(), is(notNullValue())); assertThat("body is null", request.body(), is(notNullValue()));
RequestBody body = request.body(); 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(); Buffer content = new Buffer();
body.writeTo(content); body.writeTo(content);
String string = content.readByteString().utf8(); String string = content.readByteString().utf8();
@ -123,4 +132,3 @@ public class OkHttpRibbonRequestTests {
} }
} }
} }

7
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.io.InputStream;
import java.net.URI; import java.net.URI;
import java.nio.charset.Charset; import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import org.junit.Before; import org.junit.Before;
@ -57,8 +58,10 @@ public class RestClientRibbonCommandTests {
headers.add("my-header", "my-value"); headers.add("my-header", "my-value");
LinkedMultiValueMap<String, String> params = new LinkedMultiValueMap<>(); LinkedMultiValueMap<String, String> params = new LinkedMultiValueMap<>();
params.add("myparam", "myparamval"); params.add("myparam", "myparamval");
RestClientRibbonCommand command = new RestClientRibbonCommand("cmd", null, new RibbonCommandContext("example", "GET", uri, false, RestClientRibbonCommand command =
headers, params, null), zuulProperties); new RestClientRibbonCommand("cmd", null,
new RibbonCommandContext("example", "GET", uri, false, headers, params, null,new ArrayList<RibbonRequestCustomizer>()),
zuulProperties);
HttpRequest request = command.createRequest(); HttpRequest request = command.createRequest();

Loading…
Cancel
Save