Remove deprecated and unused constructors for RibbonCommandContext and RestClientRibbonCommand
This commit is contained in:
@@ -39,16 +39,6 @@ import com.netflix.niws.client.http.RestClient;
|
||||
@SuppressWarnings("deprecation")
|
||||
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) {
|
||||
super(commandKey, client, context, zuulProperties);
|
||||
}
|
||||
|
||||
@@ -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<RibbonRequestCustomizer> requestCustomizers;
|
||||
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() {
|
||||
try {
|
||||
return new URI(this.uri);
|
||||
|
||||
@@ -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<String, String> 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<RibbonRequestCustomizer>()));
|
||||
|
||||
HttpUriRequest request = httpRequest.toRequest(RequestConfig.custom().build());
|
||||
|
||||
|
||||
@@ -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<String, String> headers = new LinkedMultiValueMap<>();
|
||||
headers.add("my-header", "my-value");
|
||||
headers.add(HttpEncoding.CONTENT_LENGTH, "5192");
|
||||
// headers.add(HttpEncoding.CONTENT_LENGTH, "5192");
|
||||
LinkedMultiValueMap<String, String> 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<RibbonRequestCustomizer>());
|
||||
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<String, String>(), requestEntity, Collections.singletonList(requestCustomizer));
|
||||
RibbonCommandContext context = new RibbonCommandContext("example", method, uri,
|
||||
false, headers, new LinkedMultiValueMap<String, String>(), 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 {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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<String, String> 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<RibbonRequestCustomizer>()),
|
||||
zuulProperties);
|
||||
|
||||
HttpRequest request = command.createRequest();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user