Revert "Adds zuul property to customize Hystrix ExecutionIsolationStrategy"

This reverts commit 21df6e43.
parent 58cf5284
......@@ -1060,8 +1060,6 @@ Zuul's rule engine allows rules and filters to be written in essentially any JVM
NOTE: The configuration property `zuul.max.host.connections` has been replaced by two new properties, `zuul.host.maxTotalConnections` and `zuul.host.maxPerRouteConnections` which default to 200 and 20 respectively.
NOTE: Default Hystrix isolation pattern (ExecutionIsolationStrategy) for all routes is SEMAPHORE. `zuul.ribbonIsolationStrategy` can be changed to THREAD if this isolation pattern is preferred.
[[netflix-zuul-reverse-proxy]]
=== Embedded Zuul Reverse Proxy
......
......@@ -108,6 +108,6 @@ public class RibbonHttpRequest extends AbstractClientHttpRequest {
}
private boolean isDynamic(String name) {
return "Content-Length".equalsIgnoreCase(name) || "Transfer-Encoding".equalsIgnoreCase(name);
return name.equalsIgnoreCase("Content-Length") || name.equalsIgnoreCase("Transfer-Encoding");
}
}
......@@ -86,24 +86,20 @@ public class ZuulProxyConfiguration extends ZuulConfiguration {
@Configuration
@ConditionalOnProperty(name = "zuul.ribbon.httpclient.enabled", matchIfMissing = true)
protected static class HttpClientRibbonConfiguration {
@Bean
@ConditionalOnMissingBean
public RibbonCommandFactory<?> ribbonCommandFactory(
SpringClientFactory clientFactory, ZuulProperties zuulProperties) {
return new HttpClientRibbonCommandFactory(clientFactory, zuulProperties);
public RibbonCommandFactory<?> ribbonCommandFactory(SpringClientFactory clientFactory) {
return new HttpClientRibbonCommandFactory(clientFactory);
}
}
@Configuration
@ConditionalOnProperty("zuul.ribbon.restclient.enabled")
protected static class RestClientRibbonConfiguration {
@Bean
@ConditionalOnMissingBean
public RibbonCommandFactory<?> ribbonCommandFactory(
SpringClientFactory clientFactory, ZuulProperties zuulProperties) {
return new RestClientRibbonCommandFactory(clientFactory, zuulProperties);
public RibbonCommandFactory<?> ribbonCommandFactory(SpringClientFactory clientFactory) {
return new RestClientRibbonCommandFactory(clientFactory);
}
}
......@@ -111,12 +107,10 @@ public class ZuulProxyConfiguration extends ZuulConfiguration {
@ConditionalOnProperty("zuul.ribbon.okhttp.enabled")
@ConditionalOnClass(name = "okhttp3.OkHttpClient")
protected static class OkHttpRibbonConfiguration {
@Bean
@ConditionalOnMissingBean
public RibbonCommandFactory<?> ribbonCommandFactory(
SpringClientFactory clientFactory, ZuulProperties zuulProperties) {
return new OkHttpRibbonCommandFactory(clientFactory, zuulProperties);
public RibbonCommandFactory<?> ribbonCommandFactory(SpringClientFactory clientFactory) {
return new OkHttpRibbonCommandFactory(clientFactory);
}
}
......@@ -124,16 +118,18 @@ public class ZuulProxyConfiguration extends ZuulConfiguration {
@Bean
public PreDecorationFilter preDecorationFilter(RouteLocator routeLocator,
ProxyRequestHelper proxyRequestHelper) {
return new PreDecorationFilter(routeLocator, this.server.getServletPrefix(),
this.zuulProperties, proxyRequestHelper);
return new PreDecorationFilter(routeLocator,
this.server.getServletPrefix(),
this.zuulProperties,
proxyRequestHelper);
}
// route filters
@Bean
public RibbonRoutingFilter ribbonRoutingFilter(ProxyRequestHelper helper,
RibbonCommandFactory<?> ribbonCommandFactory) {
RibbonRoutingFilter filter = new RibbonRoutingFilter(helper, ribbonCommandFactory,
this.requestCustomizers);
RibbonRoutingFilter filter = new RibbonRoutingFilter(helper,
ribbonCommandFactory, this.requestCustomizers);
return filter;
}
......
......@@ -31,14 +31,10 @@ import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.util.ClassUtils;
import org.springframework.util.StringUtils;
import com.netflix.hystrix.HystrixCommandProperties.ExecutionIsolationStrategy;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import static com.netflix.hystrix.HystrixCommandProperties.ExecutionIsolationStrategy.SEMAPHORE;
/**
* @author Spencer Gibb
* @author Dave Syer
......@@ -140,10 +136,6 @@ public class ZuulProperties {
*/
private boolean sslHostnameValidationEnabled =true;
private ExecutionIsolationStrategy ribbonIsolationStrategy = SEMAPHORE;
private HystrixSemaphore semaphore = new HystrixSemaphore();
public Set<String> getIgnoredHeaders() {
Set<String> ignoredHeaders = new LinkedHashSet<>(this.ignoredHeaders);
if (ClassUtils.isPresent(
......@@ -311,17 +303,6 @@ public class ZuulProperties {
*/
private int maxPerRouteConnections = 20;
}
@Data
@AllArgsConstructor
@NoArgsConstructor
public static class HystrixSemaphore {
/**
* The maximum number of total semaphores for Hystrix.
*/
private int maxSemaphores = 100;
}
public String getServletPattern() {
String path = this.servletPath;
......
......@@ -23,7 +23,6 @@ import java.io.InputStream;
import java.net.URI;
import java.util.List;
import org.springframework.cloud.netflix.zuul.filters.ZuulProperties;
import org.springframework.cloud.netflix.zuul.filters.route.support.AbstractRibbonCommand;
import org.springframework.util.MultiValueMap;
......@@ -34,13 +33,23 @@ import com.netflix.niws.client.http.RestClient;
/**
* Hystrix wrapper around Eureka Ribbon command
*
* see <a href="https://github.com/Netflix/zuul/blob/master/zuul-netflix/src/main/java/com/netflix/zuul/dependency/ribbon/hystrix/RibbonCommand.java">original</a>
* see original
* https://github.com/Netflix/zuul/blob/master/zuul-netflix/src/main/java/com/
* netflix/zuul/dependency/ribbon/hystrix/RibbonCommand.java
*/
@SuppressWarnings("deprecation")
public class RestClientRibbonCommand extends AbstractRibbonCommand<RestClient, HttpRequest, HttpResponse> {
public RestClientRibbonCommand(String commandKey, RestClient client, RibbonCommandContext context, ZuulProperties zuulProperties) {
super(commandKey, client, context, zuulProperties);
@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) {
this(commandKey, restClient, new RibbonCommandContext(commandKey, verb.verb(), uri, retryable, headers, params, requestEntity));
}
public RestClientRibbonCommand(String commandKey, RestClient client, RibbonCommandContext context) {
super(commandKey, client, context);
}
@Override
......
......@@ -17,32 +17,28 @@
package org.springframework.cloud.netflix.zuul.filters.route;
import com.netflix.client.http.HttpRequest;
import org.springframework.cloud.netflix.ribbon.SpringClientFactory;
import org.springframework.cloud.netflix.zuul.filters.ZuulProperties;
import com.netflix.client.http.HttpRequest;
import com.netflix.niws.client.http.RestClient;
import lombok.RequiredArgsConstructor;
/**
* @author Spencer Gibb
*/
@RequiredArgsConstructor
public class RestClientRibbonCommandFactory
implements RibbonCommandFactory<RestClientRibbonCommand> {
public class RestClientRibbonCommandFactory implements RibbonCommandFactory<RestClientRibbonCommand> {
private final SpringClientFactory clientFactory;
private final ZuulProperties zuulProperties;
public RestClientRibbonCommandFactory(SpringClientFactory clientFactory) {
this.clientFactory = clientFactory;
}
@Override
@SuppressWarnings("deprecation")
public RestClientRibbonCommand create(RibbonCommandContext context) {
RestClient restClient = this.clientFactory.getClient(context.getServiceId(),
RestClient.class);
return new RestClientRibbonCommand(context.getServiceId(), restClient, context,
this.zuulProperties);
return new RestClientRibbonCommand(context.getServiceId(), restClient, context);
}
public SpringClientFactory getClientFactory() {
......
......@@ -19,6 +19,7 @@ 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;
......@@ -53,11 +54,17 @@ 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>(), null);
}
public URI uri() {
try {
return new URI(this.uri);
}
catch (URISyntaxException e) {
} catch (URISyntaxException e) {
ReflectionUtils.rethrowRuntimeException(e);
}
return null;
......
......@@ -47,8 +47,8 @@ public class RibbonRoutingFilter extends ZuulFilter {
protected List<RibbonRequestCustomizer> requestCustomizers;
public RibbonRoutingFilter(ProxyRequestHelper helper,
RibbonCommandFactory<?> ribbonCommandFactory,
List<RibbonRequestCustomizer> requestCustomizers) {
RibbonCommandFactory<?> ribbonCommandFactory,
List<RibbonRequestCustomizer> requestCustomizers) {
this.helper = helper;
this.ribbonCommandFactory = ribbonCommandFactory;
this.requestCustomizers = requestCustomizers;
......@@ -120,13 +120,12 @@ public class RibbonRoutingFilter extends ZuulFilter {
uri = uri.replace("//", "/");
return new RibbonCommandContext(serviceId, verb, uri, retryable, headers, params,
requestEntity, this.requestCustomizers, request.getContentLengthLong());
requestEntity, this.requestCustomizers);
}
protected ClientHttpResponse forward(RibbonCommandContext context) throws Exception {
Map<String, Object> info = this.helper.debug(context.getMethod(),
context.getUri(), context.getHeaders(), context.getParams(),
context.getRequestEntity());
Map<String, Object> info = this.helper.debug(context.getMethod(), context.getUri(),
context.getHeaders(), context.getParams(), context.getRequestEntity());
RibbonCommand command = this.ribbonCommandFactory.create(context);
try {
......
......@@ -20,7 +20,6 @@ package org.springframework.cloud.netflix.zuul.filters.route.apache;
import org.springframework.cloud.netflix.ribbon.apache.RibbonApacheHttpRequest;
import org.springframework.cloud.netflix.ribbon.apache.RibbonApacheHttpResponse;
import org.springframework.cloud.netflix.ribbon.apache.RibbonLoadBalancingHttpClient;
import org.springframework.cloud.netflix.zuul.filters.ZuulProperties;
import org.springframework.cloud.netflix.zuul.filters.route.RibbonCommandContext;
import org.springframework.cloud.netflix.zuul.filters.route.support.AbstractRibbonCommand;
......@@ -30,10 +29,8 @@ import org.springframework.cloud.netflix.zuul.filters.route.support.AbstractRibb
public class HttpClientRibbonCommand extends AbstractRibbonCommand<RibbonLoadBalancingHttpClient, RibbonApacheHttpRequest, RibbonApacheHttpResponse> {
public HttpClientRibbonCommand(final String commandKey,
final RibbonLoadBalancingHttpClient client,
final RibbonCommandContext context,
final ZuulProperties zuulProperties) {
super(commandKey, client, context, zuulProperties);
final RibbonLoadBalancingHttpClient client, RibbonCommandContext context) {
super(commandKey, client, context);
}
@Override
......
......@@ -18,7 +18,6 @@ package org.springframework.cloud.netflix.zuul.filters.route.apache;
import org.springframework.cloud.netflix.ribbon.SpringClientFactory;
import org.springframework.cloud.netflix.ribbon.apache.RibbonLoadBalancingHttpClient;
import org.springframework.cloud.netflix.zuul.filters.ZuulProperties;
import org.springframework.cloud.netflix.zuul.filters.route.RibbonCommandContext;
import org.springframework.cloud.netflix.zuul.filters.route.RibbonCommandFactory;
......@@ -32,8 +31,6 @@ public class HttpClientRibbonCommandFactory implements
RibbonCommandFactory<HttpClientRibbonCommand> {
private final SpringClientFactory clientFactory;
private final ZuulProperties zuulProperties;
@Override
public HttpClientRibbonCommand create(final RibbonCommandContext context) {
......@@ -42,7 +39,7 @@ public class HttpClientRibbonCommandFactory implements
serviceId, RibbonLoadBalancingHttpClient.class);
client.setLoadBalancer(this.clientFactory.getLoadBalancer(serviceId));
return new HttpClientRibbonCommand(serviceId, client, context, zuulProperties);
return new HttpClientRibbonCommand(serviceId, client, context);
}
}
......@@ -20,7 +20,6 @@ package org.springframework.cloud.netflix.zuul.filters.route.okhttp;
import org.springframework.cloud.netflix.ribbon.okhttp.OkHttpLoadBalancingClient;
import org.springframework.cloud.netflix.ribbon.okhttp.OkHttpRibbonRequest;
import org.springframework.cloud.netflix.ribbon.okhttp.OkHttpRibbonResponse;
import org.springframework.cloud.netflix.zuul.filters.ZuulProperties;
import org.springframework.cloud.netflix.zuul.filters.route.RibbonCommandContext;
import org.springframework.cloud.netflix.zuul.filters.route.support.AbstractRibbonCommand;
......@@ -30,10 +29,8 @@ import org.springframework.cloud.netflix.zuul.filters.route.support.AbstractRibb
public class OkHttpRibbonCommand extends AbstractRibbonCommand<OkHttpLoadBalancingClient, OkHttpRibbonRequest, OkHttpRibbonResponse> {
public OkHttpRibbonCommand(final String commandKey,
final OkHttpLoadBalancingClient client,
final RibbonCommandContext context,
final ZuulProperties zuulProperties) {
super(commandKey, client, context, zuulProperties);
final OkHttpLoadBalancingClient client, RibbonCommandContext context) {
super(commandKey, client, context);
}
@Override
......
......@@ -18,7 +18,6 @@ package org.springframework.cloud.netflix.zuul.filters.route.okhttp;
import org.springframework.cloud.netflix.ribbon.SpringClientFactory;
import org.springframework.cloud.netflix.ribbon.okhttp.OkHttpLoadBalancingClient;
import org.springframework.cloud.netflix.zuul.filters.ZuulProperties;
import org.springframework.cloud.netflix.zuul.filters.route.RibbonCommandContext;
import org.springframework.cloud.netflix.zuul.filters.route.RibbonCommandFactory;
......@@ -32,8 +31,6 @@ public class OkHttpRibbonCommandFactory implements
RibbonCommandFactory<OkHttpRibbonCommand> {
private final SpringClientFactory clientFactory;
private final ZuulProperties zuulProperties;
@Override
public OkHttpRibbonCommand create(final RibbonCommandContext context) {
......@@ -42,7 +39,7 @@ public class OkHttpRibbonCommandFactory implements
serviceId, OkHttpLoadBalancingClient.class);
client.setLoadBalancer(this.clientFactory.getLoadBalancer(serviceId));
return new OkHttpRibbonCommand(serviceId, client, context, zuulProperties);
return new OkHttpRibbonCommand(serviceId, client, context);
}
}
......@@ -18,10 +18,10 @@
package org.springframework.cloud.netflix.zuul.filters.route.support;
import org.springframework.cloud.netflix.ribbon.RibbonHttpResponse;
import org.springframework.cloud.netflix.zuul.filters.ZuulProperties;
import org.springframework.cloud.netflix.zuul.filters.route.RibbonCommand;
import org.springframework.cloud.netflix.zuul.filters.route.RibbonCommandContext;
import org.springframework.http.client.ClientHttpResponse;
import org.springframework.util.StringUtils;
import com.netflix.client.AbstractLoadBalancerAwareClient;
import com.netflix.client.ClientRequest;
......@@ -32,48 +32,39 @@ import com.netflix.hystrix.HystrixCommand;
import com.netflix.hystrix.HystrixCommandGroupKey;
import com.netflix.hystrix.HystrixCommandKey;
import com.netflix.hystrix.HystrixCommandProperties;
import com.netflix.hystrix.HystrixCommandProperties.ExecutionIsolationStrategy;
import com.netflix.zuul.constants.ZuulConstants;
import com.netflix.zuul.context.RequestContext;
/**
* @author Spencer Gibb
*/
public abstract class AbstractRibbonCommand<LBC extends AbstractLoadBalancerAwareClient<RQ, RS>, RQ extends ClientRequest, RS extends HttpResponse>
extends HystrixCommand<ClientHttpResponse> implements RibbonCommand {
public abstract class AbstractRibbonCommand<LBC extends AbstractLoadBalancerAwareClient<RQ, RS>, RQ extends ClientRequest, RS extends HttpResponse> extends HystrixCommand<ClientHttpResponse> implements
RibbonCommand {
protected final LBC client;
protected RibbonCommandContext context;
public AbstractRibbonCommand(LBC client, RibbonCommandContext context,
ZuulProperties zuulProperties) {
this("default", client, context, zuulProperties);
public AbstractRibbonCommand(LBC client, RibbonCommandContext context) {
this("default", client, context);
}
public AbstractRibbonCommand(String commandKey, LBC client,
RibbonCommandContext context, ZuulProperties zuulProperties) {
super(getSetter(commandKey, zuulProperties));
public AbstractRibbonCommand(String commandKey, LBC client, RibbonCommandContext context) {
super(getSetter(commandKey));
this.client = client;
this.context = context;
}
protected static Setter getSetter(final String commandKey,
ZuulProperties zuulProperties) {
protected static Setter getSetter(final String commandKey) {
// we want to default to semaphore-isolation since this wraps
// 2 others commands that are already thread isolated
// @formatter:off
final HystrixCommandProperties.Setter setter = HystrixCommandProperties.Setter()
.withExecutionIsolationStrategy(zuulProperties.getRibbonIsolationStrategy());
if (zuulProperties.getRibbonIsolationStrategy() == ExecutionIsolationStrategy.SEMAPHORE){
final String name = ZuulConstants.ZUUL_EUREKA + commandKey + ".semaphore.maxSemaphores";
// we want to default to semaphore-isolation since this wraps
// 2 others commands that are already thread isolated
final DynamicIntProperty value = DynamicPropertyFactory.getInstance()
.getIntProperty(name, 100);
setter.withExecutionIsolationSemaphoreMaxConcurrentRequests(value.get());
} else {
// TODO Find out is some parameters can be set here
}
final String name = ZuulConstants.ZUUL_EUREKA + commandKey + ".semaphore.maxSemaphores";
final DynamicIntProperty value = DynamicPropertyFactory.getInstance()
.getIntProperty(name, 100);
final HystrixCommandProperties.Setter setter = HystrixCommandProperties .Setter()
.withExecutionIsolationStrategy(HystrixCommandProperties.ExecutionIsolationStrategy.SEMAPHORE)
.withExecutionIsolationSemaphoreMaxConcurrentRequests(value.get());
return Setter.withGroupKey(HystrixCommandGroupKey.Factory.asKey("RibbonCommand"))
.andCommandKey(HystrixCommandKey.Factory.asKey(commandKey + "RibbonCommand"))
.andCommandPropertiesDefaults(setter);
......@@ -83,6 +74,10 @@ public abstract class AbstractRibbonCommand<LBC extends AbstractLoadBalancerAwar
@Override
protected ClientHttpResponse run() throws Exception {
final RequestContext context = RequestContext.getCurrentContext();
long contentLength = context.getRequest().getContentLengthLong();
if (contentLength != -1) {
this.context.setContentLength(contentLength);
}
RQ request = createRequest();
RS response = this.client.executeWithLoadBalancer(request);
......
......@@ -29,7 +29,6 @@ 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;
......@@ -38,7 +37,6 @@ import org.apache.http.client.config.RequestConfig;
import org.apache.http.client.methods.HttpUriRequest;
import org.apache.http.client.methods.RequestBuilder;
import org.junit.Test;
import org.springframework.cloud.netflix.feign.encoding.HttpEncoding;
import org.springframework.cloud.netflix.ribbon.support.RibbonRequestCustomizer;
import org.springframework.cloud.netflix.zuul.filters.route.RibbonCommandContext;
import org.springframework.util.LinkedMultiValueMap;
......@@ -54,12 +52,10 @@ public class RibbonApacheHttpRequestTests {
String uri = "http://example.com";
LinkedMultiValueMap<String, String> headers = new LinkedMultiValueMap<>();
headers.add("my-header", "my-value");
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, new ArrayList<RibbonRequestCustomizer>()));
RibbonApacheHttpRequest httpRequest = new RibbonApacheHttpRequest(new RibbonCommandContext("example", "GET", uri, false,
headers, params, null));
HttpUriRequest request = httpRequest.toRequest(RequestConfig.custom().build());
......@@ -67,9 +63,7 @@ public class RibbonApacheHttpRequestTests {
assertThat("uri is wrong", request.getURI().toString(), startsWith(uri));
assertThat("my-header is missing", request.getFirstHeader("my-header"), is(notNullValue()));
assertThat("my-header is wrong", request.getFirstHeader("my-header").getValue(), is(equalTo("my-value")));
assertThat("Content-Length is wrong", request.getFirstHeader(HttpEncoding.CONTENT_LENGTH).getValue(), is(equalTo("5192")));
assertThat("myparam is missing", request.getURI().getQuery(), is(equalTo("myparam=myparamval")));
}
@Test
......
......@@ -26,11 +26,9 @@ 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;
import org.springframework.cloud.netflix.feign.encoding.HttpEncoding;
import org.springframework.cloud.netflix.ribbon.support.RibbonRequestCustomizer;
import org.springframework.cloud.netflix.zuul.filters.route.RibbonCommandContext;
import org.springframework.util.LinkedMultiValueMap;
......@@ -49,41 +47,33 @@ 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");
LinkedMultiValueMap<String, String> params = new LinkedMultiValueMap<>();
params.add("myparam", "myparamval");
RibbonCommandContext context = new RibbonCommandContext("example", "GET", uri,
false, headers, params, null, new ArrayList<RibbonRequestCustomizer>());
RibbonCommandContext context = new RibbonCommandContext("example", "GET", uri, false, headers, params, null);
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("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";
......@@ -104,9 +94,8 @@ 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);
......@@ -123,8 +112,7 @@ 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();
......@@ -132,3 +120,4 @@ public class OkHttpRibbonRequestTests {
}
}
}
......@@ -27,13 +27,10 @@ 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;
import org.junit.Test;
import org.springframework.cloud.netflix.ribbon.support.RibbonRequestCustomizer;
import org.springframework.cloud.netflix.zuul.filters.ZuulProperties;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.StreamUtils;
......@@ -44,13 +41,6 @@ import com.netflix.client.http.HttpRequest;
*/
public class RestClientRibbonCommandTests {
private ZuulProperties zuulProperties;
@Before
public void setUp() {
zuulProperties = new ZuulProperties();
}
@Test
public void testNullEntity() throws Exception {
String uri = "http://example.com";
......@@ -58,10 +48,8 @@ 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,new ArrayList<RibbonRequestCustomizer>()),
zuulProperties);
RestClientRibbonCommand command = new RestClientRibbonCommand("cmd", null, new RibbonCommandContext("example", "GET", uri, false,
headers, params, null));
HttpRequest request = command.createRequest();
......@@ -108,7 +96,7 @@ public class RestClientRibbonCommandTests {
uri.toString(), false, headers, new LinkedMultiValueMap<String, String>(),
requestEntity, Collections.singletonList(requestCustomizer));
context.setContentLength(length);
RestClientRibbonCommand command = new RestClientRibbonCommand("cmd", null, context, zuulProperties);
RestClientRibbonCommand command = new RestClientRibbonCommand("cmd", null, context);
HttpRequest request = command.createRequest();
......
......@@ -41,7 +41,6 @@ import org.springframework.cloud.netflix.ribbon.SpringClientFactory;
import org.springframework.cloud.netflix.ribbon.StaticServerList;
import org.springframework.cloud.netflix.ribbon.apache.RibbonLoadBalancingHttpClient;
import org.springframework.cloud.netflix.zuul.EnableZuulProxy;
import org.springframework.cloud.netflix.zuul.filters.ZuulProperties;
import org.springframework.cloud.netflix.zuul.filters.route.RibbonCommandFactory;
import org.springframework.cloud.netflix.zuul.filters.route.support.ZuulProxyTestBase;
import org.springframework.context.annotation.Bean;
......@@ -180,7 +179,7 @@ public class HttpClientRibbonCommandIntegrationTests extends ZuulProxyTestBase {
@Bean
public RibbonCommandFactory<?> ribbonCommandFactory(
final SpringClientFactory clientFactory) {
return new HttpClientRibbonCommandFactory(clientFactory, new ZuulProperties());
return new HttpClientRibbonCommandFactory(clientFactory);
}
@Bean
......
......@@ -32,7 +32,6 @@ import org.springframework.cloud.netflix.ribbon.RibbonClient;
import org.springframework.cloud.netflix.ribbon.RibbonClients;
import org.springframework.cloud.netflix.ribbon.SpringClientFactory;
import org.springframework.cloud.netflix.zuul.EnableZuulProxy;
import org.springframework.cloud.netflix.zuul.filters.ZuulProperties;
import org.springframework.cloud.netflix.zuul.filters.route.RibbonCommandFactory;
import org.springframework.cloud.netflix.zuul.filters.route.support.ZuulProxyTestBase;
import org.springframework.context.annotation.Bean;
......@@ -108,7 +107,7 @@ public class OkHttpRibbonCommandIntegrationTests extends ZuulProxyTestBase {
@Bean
public RibbonCommandFactory<?> ribbonCommandFactory(
final SpringClientFactory clientFactory) {
return new OkHttpRibbonCommandFactory(clientFactory, new ZuulProperties());
return new OkHttpRibbonCommandFactory(clientFactory);
}
@Bean
......
......@@ -330,7 +330,7 @@ public class RestClientRibbonCommandIntegrationTests extends ZuulProxyTestBase {
private SpringClientFactory clientFactory;
public MyRibbonCommandFactory(SpringClientFactory clientFactory) {
super(clientFactory, new ZuulProperties());
super(clientFactory);
this.clientFactory = clientFactory;
}
......@@ -356,7 +356,7 @@ public class RestClientRibbonCommandIntegrationTests extends ZuulProxyTestBase {
public MyCommand(int errorCode, String commandKey, RestClient restClient,
RibbonCommandContext context) {
super(commandKey, restClient, context, new ZuulProperties());
super(commandKey, restClient, context);
this.errorCode = errorCode;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment