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;
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
public class RestClientRibbonCommand extends AbstractRibbonCommand<RestClient, HttpRequest, HttpResponse> { 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); 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 @Override
protected HttpRequest createRequest() throws Exception { protected HttpRequest createRequest() throws Exception {
HttpRequest.Builder builder = HttpRequest.newBuilder() HttpRequest.Builder builder = HttpRequest.newBuilder()
.verb(getVerb(this.context.getMethod())) .verb(getVerb(this.context.getMethod())).uri(this.context.uri())
.uri(this.context.uri())
.entity(this.context.getRequestEntity()); .entity(this.context.getRequestEntity());
if(this.context.getRetryable() != null) { if (this.context.getRetryable() != null) {
builder.setRetriable(this.context.getRetryable()); 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;
import com.netflix.client.http.HttpRequest; import com.netflix.client.http.HttpRequest;
import com.netflix.niws.client.http.RestClient; import com.netflix.niws.client.http.RestClient;
import lombok.RequiredArgsConstructor;
/** /**
* @author Spencer Gibb * @author Spencer Gibb
*/ */
@RequiredArgsConstructor public class RestClientRibbonCommandFactory implements RibbonCommandFactory<RestClientRibbonCommand> {
public class RestClientRibbonCommandFactory
implements RibbonCommandFactory<RestClientRibbonCommand> {
private final SpringClientFactory clientFactory; 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 @Override
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
@ -49,7 +55,12 @@ public class RestClientRibbonCommandFactory
return clientFactory; return clientFactory;
} }
public void setZuulProperties(ZuulProperties zuulProperties) {
this.zuulProperties = zuulProperties;
}
protected static HttpRequest.Verb getVerb(String method) { protected static HttpRequest.Verb getVerb(String method) {
return RestClientRibbonCommand.getVerb(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;
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;
@ -53,6 +54,13 @@ 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>(), null);
}
public URI uri() { public URI uri() {
try { try {
return new URI(this.uri); return new URI(this.uri);

Loading…
Cancel
Save