Commit 9da71b16 by Ryan Baxter

Removed unnecessary null check and fixed imports

parent ed31004a
...@@ -76,19 +76,12 @@ public class RibbonLoadBalancingHttpClient ...@@ -76,19 +76,12 @@ public class RibbonLoadBalancingHttpClient
final IClientConfig configOverride) throws Exception { final IClientConfig configOverride) throws Exception {
final RequestConfig.Builder builder = RequestConfig.custom(); final RequestConfig.Builder builder = RequestConfig.custom();
IClientConfig config = configOverride != null ? configOverride : this.config; IClientConfig config = configOverride != null ? configOverride : this.config;
if (config != null) { builder.setConnectTimeout(config.get(
builder.setConnectTimeout(config.get( CommonClientConfigKey.ConnectTimeout, this.connectTimeout));
CommonClientConfigKey.ConnectTimeout, this.connectTimeout)); builder.setSocketTimeout(config.get(
builder.setSocketTimeout(config.get( CommonClientConfigKey.ReadTimeout, this.readTimeout));
CommonClientConfigKey.ReadTimeout, this.readTimeout)); builder.setRedirectsEnabled(config.get(
builder.setRedirectsEnabled(config.get( CommonClientConfigKey.FollowRedirects, this.followRedirects));
CommonClientConfigKey.FollowRedirects, this.followRedirects));
}
else {
builder.setConnectTimeout(this.connectTimeout);
builder.setSocketTimeout(this.readTimeout);
builder.setRedirectsEnabled(this.followRedirects);
}
final RequestConfig requestConfig = builder.build(); final RequestConfig requestConfig = builder.build();
......
...@@ -16,15 +16,17 @@ ...@@ -16,15 +16,17 @@
package org.springframework.cloud.netflix.ribbon.okhttp; package org.springframework.cloud.netflix.ribbon.okhttp;
import java.net.URI;
import java.util.concurrent.TimeUnit;
import okhttp3.OkHttpClient; import okhttp3.OkHttpClient;
import okhttp3.Request; import okhttp3.Request;
import okhttp3.Response; import okhttp3.Response;
import java.net.URI;
import java.util.concurrent.TimeUnit;
import org.springframework.cloud.netflix.ribbon.ServerIntrospector; import org.springframework.cloud.netflix.ribbon.ServerIntrospector;
import org.springframework.cloud.netflix.ribbon.support.AbstractLoadBalancingClient; import org.springframework.cloud.netflix.ribbon.support.AbstractLoadBalancingClient;
import org.springframework.web.util.UriComponentsBuilder; import org.springframework.web.util.UriComponentsBuilder;
import com.netflix.client.config.CommonClientConfigKey; import com.netflix.client.config.CommonClientConfigKey;
import com.netflix.client.config.IClientConfig; import com.netflix.client.config.IClientConfig;
import com.netflix.loadbalancer.ILoadBalancer; import com.netflix.loadbalancer.ILoadBalancer;
...@@ -84,25 +86,15 @@ public class OkHttpLoadBalancingClient ...@@ -84,25 +86,15 @@ public class OkHttpLoadBalancingClient
OkHttpClient getOkHttpClient(IClientConfig configOverride, boolean secure) { OkHttpClient getOkHttpClient(IClientConfig configOverride, boolean secure) {
OkHttpClient.Builder builder = this.delegate.newBuilder(); OkHttpClient.Builder builder = this.delegate.newBuilder();
IClientConfig config = configOverride != null ? configOverride : this.config; IClientConfig config = configOverride != null ? configOverride : this.config;
if (config != null) { builder.connectTimeout(config.get(
builder.connectTimeout(config.get( CommonClientConfigKey.ConnectTimeout, this.connectTimeout), TimeUnit.MILLISECONDS);
CommonClientConfigKey.ConnectTimeout, this.connectTimeout), TimeUnit.MILLISECONDS); builder.readTimeout(config.get(
builder.readTimeout(config.get( CommonClientConfigKey.ReadTimeout, this.readTimeout), TimeUnit.MILLISECONDS);
CommonClientConfigKey.ReadTimeout, this.readTimeout), TimeUnit.MILLISECONDS); builder.followRedirects(config.get(
builder.followRedirects(config.get( CommonClientConfigKey.FollowRedirects, this.followRedirects));
if (secure) {
builder.followSslRedirects(configOverride.get(
CommonClientConfigKey.FollowRedirects, this.followRedirects)); CommonClientConfigKey.FollowRedirects, this.followRedirects));
if (secure) {
builder.followSslRedirects(configOverride.get(
CommonClientConfigKey.FollowRedirects, this.followRedirects));
}
}
else {
builder.connectTimeout(this.connectTimeout, TimeUnit.MILLISECONDS);
builder.readTimeout(this.readTimeout, TimeUnit.MILLISECONDS);
builder.followRedirects(this.followRedirects);
if (secure) {
builder.followSslRedirects(this.followRedirects);
}
} }
return builder.build(); return builder.build();
......
...@@ -16,6 +16,8 @@ ...@@ -16,6 +16,8 @@
package org.springframework.cloud.netflix.ribbon.okhttp; package org.springframework.cloud.netflix.ribbon.okhttp;
import static org.hamcrest.Matchers.is;
import static org.junit.Assert.assertThat;
import okhttp3.OkHttpClient; import okhttp3.OkHttpClient;
import org.junit.Test; import org.junit.Test;
...@@ -24,12 +26,11 @@ import org.springframework.cloud.netflix.ribbon.SpringClientFactory; ...@@ -24,12 +26,11 @@ import org.springframework.cloud.netflix.ribbon.SpringClientFactory;
import org.springframework.context.annotation.AnnotationConfigApplicationContext; import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import com.netflix.client.config.CommonClientConfigKey; import com.netflix.client.config.CommonClientConfigKey;
import com.netflix.client.config.DefaultClientConfigImpl; import com.netflix.client.config.DefaultClientConfigImpl;
import com.netflix.client.config.IClientConfig; import com.netflix.client.config.IClientConfig;
import static org.hamcrest.Matchers.is;
import static org.junit.Assert.assertThat;
/** /**
* @author Spencer Gibb * @author Spencer Gibb
......
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