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 39c850a4..b5423ce7 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,18 +39,27 @@ import com.netflix.niws.client.http.RestClient; @SuppressWarnings("deprecation") public class RestClientRibbonCommand extends AbstractRibbonCommand { - 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); } + @Deprecated + public RestClientRibbonCommand(String commandKey, RestClient restClient, + HttpRequest.Verb verb, String uri, Boolean retryable, + MultiValueMap headers, MultiValueMap params, + InputStream requestEntity) { + this(commandKey, restClient, new RibbonCommandContext(commandKey, verb.verb(), + uri, retryable, headers, params, requestEntity), new ZuulProperties()); + } + @Override protected HttpRequest createRequest() throws Exception { HttpRequest.Builder builder = HttpRequest.newBuilder() - .verb(getVerb(this.context.getMethod())) - .uri(this.context.uri()) + .verb(getVerb(this.context.getMethod())).uri(this.context.uri()) .entity(this.context.getRequestEntity()); - if(this.context.getRetryable() != null) { + if (this.context.getRetryable() != null) { builder.setRetriable(this.context.getRetryable()); } diff --git a/spring-cloud-netflix-core/src/main/java/org/springframework/cloud/netflix/zuul/filters/route/RestClientRibbonCommandFactory.java b/spring-cloud-netflix-core/src/main/java/org/springframework/cloud/netflix/zuul/filters/route/RestClientRibbonCommandFactory.java index 9f8718f2..b184e370 100644 --- a/spring-cloud-netflix-core/src/main/java/org/springframework/cloud/netflix/zuul/filters/route/RestClientRibbonCommandFactory.java +++ b/spring-cloud-netflix-core/src/main/java/org/springframework/cloud/netflix/zuul/filters/route/RestClientRibbonCommandFactory.java @@ -23,18 +23,24 @@ 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 { +public class RestClientRibbonCommandFactory implements RibbonCommandFactory { private final SpringClientFactory clientFactory; - private final ZuulProperties zuulProperties; + private ZuulProperties zuulProperties; + + public RestClientRibbonCommandFactory(SpringClientFactory clientFactory) { + this(clientFactory, new ZuulProperties()); + } + + public RestClientRibbonCommandFactory(SpringClientFactory clientFactory, + ZuulProperties zuulProperties) { + this.clientFactory = clientFactory; + this.zuulProperties = zuulProperties; + } @Override @SuppressWarnings("deprecation") @@ -49,7 +55,12 @@ public class RestClientRibbonCommandFactory return clientFactory; } + public void setZuulProperties(ZuulProperties zuulProperties) { + this.zuulProperties = zuulProperties; + } + protected static HttpRequest.Verb getVerb(String method) { return RestClientRibbonCommand.getVerb(method); } + } 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 a558c5fd..288f4e52 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,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,6 +54,13 @@ 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(), null); + } + public URI uri() { try { return new URI(this.uri);