Browse Source

Keep old constructors to maintain backwards compatibility with spring cloud sleuth

pull/6/head
Stéphane Lagraulet 8 years ago
parent
commit
f5bb5ff9c1
  1. 17
      spring-cloud-netflix-core/src/main/java/org/springframework/cloud/netflix/zuul/filters/route/RestClientRibbonCommand.java
  2. 23
      spring-cloud-netflix-core/src/main/java/org/springframework/cloud/netflix/zuul/filters/route/RestClientRibbonCommandFactory.java
  3. 8
      spring-cloud-netflix-core/src/main/java/org/springframework/cloud/netflix/zuul/filters/route/RibbonCommandContext.java

17
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; @@ -39,18 +39,27 @@ import com.netflix.niws.client.http.RestClient;
@SuppressWarnings("deprecation")
public class RestClientRibbonCommand extends AbstractRibbonCommand<RestClient, HttpRequest, HttpResponse> {
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<String, String> headers, MultiValueMap<String, String> 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());
}

23
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; @@ -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<RestClientRibbonCommand> {
public class RestClientRibbonCommandFactory implements RibbonCommandFactory<RestClientRibbonCommand> {
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 @@ -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);
}
}

8
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; @@ -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 { @@ -53,6 +54,13 @@ 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);

Loading…
Cancel
Save