Browse Source

cherry pick from master for ribbon 2 compatibility issue

pull/119/head
Amit Joshi 10 years ago committed by Allen Wang
parent
commit
37917020ff
  1. 26
      build.gradle
  2. 61
      ribbon/src/main/java/feign/ribbon/LBClient.java

26
build.gradle

@ -10,6 +10,11 @@ buildscript { @@ -10,6 +10,11 @@ buildscript {
}
allprojects {
if (JavaVersion.current().isJava8Compatible()) {
tasks.withType(Javadoc) {
options.addStringOption('Xdoclint:none', '-quiet') // Doclint is onerous in Java 8.
}
}
repositories {
mavenLocal()
mavenCentral()
@ -19,7 +24,9 @@ allprojects { @@ -19,7 +24,9 @@ allprojects {
apply from: file('gradle/convention.gradle')
apply from: file('gradle/maven.gradle')
apply from: file('gradle/check.gradle')
if (!JavaVersion.current().isJava8Compatible()) {
apply from: file('gradle/check.gradle') // FindBugs is incompatible with Java 8.
}
apply from: file('gradle/license.gradle')
apply from: file('gradle/release.gradle')
apply plugin: 'idea'
@ -113,8 +120,23 @@ project(':feign-ribbon') { @@ -113,8 +120,23 @@ project(':feign-ribbon') {
dependencies {
compile project(':feign-core')
compile 'com.netflix.ribbon:ribbon-core:0.3.1'
compile 'com.netflix.ribbon:ribbon-loadbalancer:2.0-RC5'
testCompile 'org.testng:testng:6.8.5'
testCompile 'com.google.mockwebserver:mockwebserver:20130706'
}
}
project(':feign-slf4j') {
apply plugin: 'java'
test {
useTestNG()
}
dependencies {
compile project(':feign-core')
compile 'org.slf4j:slf4j-api:1.7.5'
testCompile 'org.testng:testng:6.8.5'
testCompile 'org.slf4j:slf4j-simple:1.7.5'
}
}

61
ribbon/src/main/java/feign/ribbon/LBClient.java

@ -19,10 +19,10 @@ import com.netflix.client.AbstractLoadBalancerAwareClient; @@ -19,10 +19,10 @@ import com.netflix.client.AbstractLoadBalancerAwareClient;
import com.netflix.client.ClientException;
import com.netflix.client.ClientRequest;
import com.netflix.client.IResponse;
import com.netflix.client.RequestSpecificRetryHandler;
import com.netflix.client.config.CommonClientConfigKey;
import com.netflix.client.config.IClientConfig;
import com.netflix.loadbalancer.ILoadBalancer;
import com.netflix.util.Pair;
import java.io.IOException;
import java.net.URI;
@ -35,9 +35,6 @@ import feign.RequestTemplate; @@ -35,9 +35,6 @@ import feign.RequestTemplate;
import feign.Response;
import feign.RetryableException;
import static com.netflix.client.config.CommonClientConfigKey.ConnectTimeout;
import static com.netflix.client.config.CommonClientConfigKey.ReadTimeout;
class LBClient extends AbstractLoadBalancerAwareClient<LBClient.RibbonRequest, LBClient.RibbonResponse> {
private final Client delegate;
@ -45,34 +42,40 @@ class LBClient extends AbstractLoadBalancerAwareClient<LBClient.RibbonRequest, L @@ -45,34 +42,40 @@ class LBClient extends AbstractLoadBalancerAwareClient<LBClient.RibbonRequest, L
private final int readTimeout;
LBClient(Client delegate, ILoadBalancer lb, IClientConfig clientConfig) {
super(lb, clientConfig);
this.delegate = delegate;
this.connectTimeout = Integer.valueOf(clientConfig.getProperty(ConnectTimeout).toString());
this.readTimeout = Integer.valueOf(clientConfig.getProperty(ReadTimeout).toString());
setLoadBalancer(lb);
initWithNiwsConfig(clientConfig);
connectTimeout = clientConfig.get(CommonClientConfigKey.ConnectTimeout);
readTimeout = clientConfig.get(CommonClientConfigKey.ReadTimeout);
}
@Override
public RibbonResponse execute(RibbonRequest request) throws IOException {
int connectTimeout = config(request, ConnectTimeout, this.connectTimeout);
int readTimeout = config(request, ReadTimeout, this.readTimeout);
Request.Options options = new Request.Options(connectTimeout, readTimeout);
public RibbonResponse execute(RibbonRequest request, IClientConfig configOverride) throws IOException {
Request.Options options;
if (configOverride != null) {
options = new Request.Options(configOverride.get(CommonClientConfigKey.ConnectTimeout, connectTimeout),
(configOverride.get(CommonClientConfigKey.ReadTimeout, readTimeout)));
} else {
options = new Request.Options(connectTimeout, readTimeout);
}
Response response = delegate.execute(request.toRequest(), options);
return new RibbonResponse(request.getUri(), response);
}
@Override protected boolean isCircuitBreakerException(Throwable e) {
return e instanceof IOException;
}
@Override protected boolean isRetriableException(Throwable e) {
return e instanceof RetryableException;
}
@Override
protected Pair<String, Integer> deriveSchemeAndPortFromPartialUri(RibbonRequest task) {
return new Pair<String, Integer>(URI.create(task.request.url()).getScheme(), task.getUri().getPort());
public RequestSpecificRetryHandler getRequestSpecificRetryHandler(
RibbonRequest request, IClientConfig requestConfig) {
return new RequestSpecificRetryHandler(true, false) {
@Override
public boolean isRetriableException(Throwable e, boolean sameServer) {
return e instanceof RetryableException;
}
@Override
public boolean isCircuitTrippingException(Throwable e) {
return e instanceof IOException;
}
};
}
static class RibbonRequest extends ClientRequest implements Cloneable {
@ -134,15 +137,11 @@ class LBClient extends AbstractLoadBalancerAwareClient<LBClient.RibbonRequest, L @@ -134,15 +137,11 @@ class LBClient extends AbstractLoadBalancerAwareClient<LBClient.RibbonRequest, L
@Override
public void close() throws IOException {
if (response.body() != null) {
response.body().close();
}
if (response != null && response.body() != null) {
response.body().close();
}
}
}
static int config(RibbonRequest request, CommonClientConfigKey key, int defaultValue) {
if (request.getOverrideConfig() != null && request.getOverrideConfig().containsProperty(key))
return Integer.valueOf(request.getOverrideConfig().getProperty(key).toString());
return defaultValue;
}
}

Loading…
Cancel
Save