Skip to content

Commit

Permalink
Pass along client config in RibbonCommand.run (#1573)
Browse files Browse the repository at this point in the history
Pass along client config in RibbonCommand.run.  

Fixes gh-1530
  • Loading branch information
ryanjbaxter authored and spencergibb committed Jan 9, 2017
1 parent ab454f1 commit f3deb04
Show file tree
Hide file tree
Showing 8 changed files with 49 additions and 6 deletions.
Expand Up @@ -131,7 +131,12 @@ public RequestSpecificRetryHandler getRequestSpecificRetryHandler(
}

protected boolean isSecure(final IClientConfig config) {
return (config != null) ? config.get(CommonClientConfigKey.IsSecure)
: this.secure;
if(config != null) {
Boolean result = config.get(CommonClientConfigKey.IsSecure);
if(result != null) {
return result;
}
}
return this.secure;
}
}
Expand Up @@ -23,6 +23,7 @@
import org.springframework.cloud.netflix.zuul.filters.ZuulProperties;
import org.springframework.cloud.netflix.zuul.filters.route.support.AbstractRibbonCommand;
import org.springframework.util.MultiValueMap;
import com.netflix.client.config.IClientConfig;
import com.netflix.client.http.HttpRequest;
import com.netflix.client.http.HttpResponse;
import com.netflix.niws.client.http.RestClient;
Expand All @@ -48,6 +49,12 @@ public RestClientRibbonCommand(String commandKey, RestClient client,
super(commandKey, client, context, zuulProperties, zuulFallbackProvider);
}

public RestClientRibbonCommand(String commandKey, RestClient client,
RibbonCommandContext context, ZuulProperties zuulProperties,
ZuulFallbackProvider zuulFallbackProvider, IClientConfig config) {
super(commandKey, client, context, zuulProperties, zuulFallbackProvider, config);
}

@Deprecated
public RestClientRibbonCommand(String commandKey, RestClient restClient,
HttpRequest.Verb verb, String uri, Boolean retryable,
Expand Down
Expand Up @@ -57,7 +57,7 @@ public RestClientRibbonCommand create(RibbonCommandContext context) {
RestClient restClient = this.clientFactory.getClient(serviceId,
RestClient.class);
return new RestClientRibbonCommand(context.getServiceId(), restClient, context,
this.zuulProperties, fallbackProvider);
this.zuulProperties, fallbackProvider, clientFactory.getClientConfig(serviceId));
}

public SpringClientFactory getClientFactory() {
Expand Down
Expand Up @@ -24,6 +24,7 @@
import org.springframework.cloud.netflix.zuul.filters.route.RibbonCommandContext;
import org.springframework.cloud.netflix.zuul.filters.route.ZuulFallbackProvider;
import org.springframework.cloud.netflix.zuul.filters.route.support.AbstractRibbonCommand;
import com.netflix.client.config.IClientConfig;

/**
* @author Spencer Gibb
Expand All @@ -46,6 +47,15 @@ public HttpClientRibbonCommand(final String commandKey,
super(commandKey, client, context, zuulProperties, zuulFallbackProvider);
}

public HttpClientRibbonCommand(final String commandKey,
final RibbonLoadBalancingHttpClient client,
final RibbonCommandContext context,
final ZuulProperties zuulProperties,
final ZuulFallbackProvider zuulFallbackProvider,
final IClientConfig config) {
super(commandKey, client, context, zuulProperties, zuulFallbackProvider, config);
}

@Override
protected RibbonApacheHttpRequest createRequest() throws Exception {
return new RibbonApacheHttpRequest(this.context);
Expand Down
Expand Up @@ -55,7 +55,8 @@ public HttpClientRibbonCommand create(final RibbonCommandContext context) {
serviceId, RibbonLoadBalancingHttpClient.class);
client.setLoadBalancer(this.clientFactory.getLoadBalancer(serviceId));

return new HttpClientRibbonCommand(serviceId, client, context, zuulProperties, zuulFallbackProvider);
return new HttpClientRibbonCommand(serviceId, client, context, zuulProperties, zuulFallbackProvider,
clientFactory.getClientConfig(serviceId));
}

}
Expand Up @@ -24,6 +24,7 @@
import org.springframework.cloud.netflix.zuul.filters.route.RibbonCommandContext;
import org.springframework.cloud.netflix.zuul.filters.route.ZuulFallbackProvider;
import org.springframework.cloud.netflix.zuul.filters.route.support.AbstractRibbonCommand;
import com.netflix.client.config.IClientConfig;

/**
* @author Spencer Gibb
Expand All @@ -46,6 +47,15 @@ public OkHttpRibbonCommand(final String commandKey,
super(commandKey, client, context, zuulProperties, zuulFallbackProvider);
}

public OkHttpRibbonCommand(final String commandKey,
final OkHttpLoadBalancingClient client,
final RibbonCommandContext context,
final ZuulProperties zuulProperties,
final ZuulFallbackProvider zuulFallbackProvider,
final IClientConfig config) {
super(commandKey, client, context, zuulProperties, zuulFallbackProvider, config);
}

@Override
protected OkHttpRibbonRequest createRequest() throws Exception {
return new OkHttpRibbonRequest(this.context);
Expand Down
Expand Up @@ -55,7 +55,8 @@ public OkHttpRibbonCommand create(final RibbonCommandContext context) {
serviceId, OkHttpLoadBalancingClient.class);
client.setLoadBalancer(this.clientFactory.getLoadBalancer(serviceId));

return new OkHttpRibbonCommand(serviceId, client, context, zuulProperties, fallbackProvider);
return new OkHttpRibbonCommand(serviceId, client, context, zuulProperties, fallbackProvider,
clientFactory.getClientConfig(serviceId));
}

}
Expand Up @@ -25,6 +25,7 @@
import org.springframework.http.client.ClientHttpResponse;
import com.netflix.client.AbstractLoadBalancerAwareClient;
import com.netflix.client.ClientRequest;
import com.netflix.client.config.IClientConfig;
import com.netflix.client.http.HttpResponse;
import com.netflix.config.DynamicIntProperty;
import com.netflix.config.DynamicPropertyFactory;
Expand All @@ -45,6 +46,7 @@ public abstract class AbstractRibbonCommand<LBC extends AbstractLoadBalancerAwar
protected final LBC client;
protected RibbonCommandContext context;
protected ZuulFallbackProvider zuulFallbackProvider;
protected IClientConfig config;

public AbstractRibbonCommand(LBC client, RibbonCommandContext context,
ZuulProperties zuulProperties) {
Expand All @@ -59,10 +61,17 @@ public AbstractRibbonCommand(String commandKey, LBC client,
public AbstractRibbonCommand(String commandKey, LBC client,
RibbonCommandContext context, ZuulProperties zuulProperties,
ZuulFallbackProvider fallbackProvider) {
this(commandKey, client, context, zuulProperties, fallbackProvider, null);
}

public AbstractRibbonCommand(String commandKey, LBC client,
RibbonCommandContext context, ZuulProperties zuulProperties,
ZuulFallbackProvider fallbackProvider, IClientConfig config) {
super(getSetter(commandKey, zuulProperties));
this.client = client;
this.context = context;
this.zuulFallbackProvider = fallbackProvider;
this.config = config;
}

protected static Setter getSetter(final String commandKey,
Expand Down Expand Up @@ -93,7 +102,7 @@ protected ClientHttpResponse run() throws Exception {
final RequestContext context = RequestContext.getCurrentContext();

RQ request = createRequest();
RS response = this.client.executeWithLoadBalancer(request);
RS response = this.client.executeWithLoadBalancer(request, config);

context.set("ribbonResponse", response);

Expand Down

0 comments on commit f3deb04

Please sign in to comment.