Add back RestClientRibbonCommand api's.

parent 7c2f8067
......@@ -21,7 +21,10 @@ import com.netflix.client.http.HttpRequest;
import com.netflix.client.http.HttpResponse;
import com.netflix.niws.client.http.RestClient;
import org.springframework.cloud.netflix.zuul.filters.route.support.AbstractRibbonCommand;
import org.springframework.util.MultiValueMap;
import java.io.InputStream;
import java.net.URI;
import java.util.List;
/**
......@@ -34,6 +37,14 @@ import java.util.List;
@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) {
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);
}
......@@ -41,7 +52,7 @@ public class RestClientRibbonCommand extends AbstractRibbonCommand<RestClient, H
@Override
protected HttpRequest createRequest() throws Exception {
HttpRequest.Builder builder = HttpRequest.newBuilder()
.verb(RestClientRibbonCommandFactory.getVerb(this.context.getMethod()))
.verb(getVerb(this.context.getMethod()))
.uri(this.context.uri())
.entity(this.context.getRequestEntity());
......@@ -62,6 +73,35 @@ public class RestClientRibbonCommand extends AbstractRibbonCommand<RestClient, H
}
}
customizeRequest(builder);
return builder.build();
}
protected void customizeRequest(HttpRequest.Builder requestBuilder) {
// noop
}
@Deprecated
public URI getUri() {
return this.context.uri();
}
@SuppressWarnings("unused")
@Deprecated
public HttpRequest.Verb getVerb() {
return getVerb(this.context.getVerb());
}
protected static HttpRequest.Verb getVerb(String method) {
if (method == null)
return HttpRequest.Verb.GET;
try {
return HttpRequest.Verb.valueOf(method.toUpperCase());
}
catch (IllegalArgumentException e) {
return HttpRequest.Verb.GET;
}
}
}
......@@ -41,14 +41,11 @@ public class RestClientRibbonCommandFactory implements RibbonCommandFactory<Rest
return new RestClientRibbonCommand(context.getServiceId(), restClient, context);
}
static HttpRequest.Verb getVerb(String method) {
if (method == null)
return HttpRequest.Verb.GET;
try {
return HttpRequest.Verb.valueOf(method.toUpperCase());
}
catch (IllegalArgumentException e) {
return HttpRequest.Verb.GET;
}
public SpringClientFactory getClientFactory() {
return clientFactory;
}
protected static HttpRequest.Verb getVerb(String method) {
return RestClientRibbonCommand.getVerb(method);
}
}
......@@ -47,4 +47,13 @@ public class RibbonCommandContext {
}
return null;
}
/**
* Use getMethod()
* @return
*/
@Deprecated
public String getVerb() {
return this.method;
}
}
......@@ -96,5 +96,13 @@ public abstract class AbstractRibbonCommand<LBC extends AbstractLoadBalancerAwar
return new RibbonHttpResponse(response);
}
public LBC getClient() {
return client;
}
public RibbonCommandContext getContext() {
return context;
}
protected abstract RQ createRequest() throws Exception;
}
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