未验证 提交 0b2253fa 编写于 作者: E elandau 提交者: GitHub

Merge pull request #430 from elandau/misc

config: Misc cleanup
...@@ -35,10 +35,10 @@ public class RequestSpecificRetryHandler implements RetryHandler { ...@@ -35,10 +35,10 @@ public class RequestSpecificRetryHandler implements RetryHandler {
this.okToRetryOnAllErrors = okToRetryOnAllErrors; this.okToRetryOnAllErrors = okToRetryOnAllErrors;
this.fallback = baseRetryHandler; this.fallback = baseRetryHandler;
if (requestConfig != null) { if (requestConfig != null) {
Optional.ofNullable(requestConfig.get(CommonClientConfigKey.MaxAutoRetries)).ifPresent( requestConfig.getIfSet(CommonClientConfigKey.MaxAutoRetries).ifPresent(
value -> retrySameServer = value value -> retrySameServer = value
); );
Optional.ofNullable(requestConfig.get(CommonClientConfigKey.MaxAutoRetriesNextServer)).ifPresent( requestConfig.getIfSet(CommonClientConfigKey.MaxAutoRetriesNextServer).ifPresent(
value -> retryNextServer = value value -> retryNextServer = value
); );
} }
......
...@@ -456,10 +456,10 @@ public abstract class ReloadableClientConfig implements IClientConfig { ...@@ -456,10 +456,10 @@ public abstract class ReloadableClientConfig implements IClientConfig {
private String generateToString() { private String generateToString() {
return "ClientConfig:" + internalProperties.entrySet().stream() return "ClientConfig:" + internalProperties.entrySet().stream()
.map(t -> { .map(t -> {
if (t.getKey().key().endsWith("Password")) { if (t.getKey().key().endsWith("Password") && t.getValue().isPresent()) {
return t.getKey() + ":***"; return t.getKey() + ":***";
} }
return t.getKey() + ":" + t.getValue(); return t.getKey() + ":" + t.getValue().orElse(null);
}) })
.collect(Collectors.joining(", ")); .collect(Collectors.joining(", "));
} }
......
...@@ -117,7 +117,7 @@ public class DiscoveryEnabledNIWSServerList extends AbstractServerList<Discovery ...@@ -117,7 +117,7 @@ public class DiscoveryEnabledNIWSServerList extends AbstractServerList<Discovery
shouldUseIpAddr = clientConfig.getOrDefault(CommonClientConfigKey.UseIPAddrForServer); shouldUseIpAddr = clientConfig.getOrDefault(CommonClientConfigKey.UseIPAddrForServer);
// override client configuration and use client-defined port // override client configuration and use client-defined port
if (clientConfig.get(CommonClientConfigKey.ForceClientPortConfiguration, false)){ if (clientConfig.get(CommonClientConfigKey.ForceClientPortConfiguration, false)) {
if (isSecure) { if (isSecure) {
final Integer port = clientConfig.get(CommonClientConfigKey.SecurePort); final Integer port = clientConfig.get(CommonClientConfigKey.SecurePort);
if (port != null) { if (port != null) {
......
...@@ -181,7 +181,6 @@ public class DiscoveryEnabledLoadBalancerSupportsPortOverrideTest { ...@@ -181,7 +181,6 @@ public class DiscoveryEnabledLoadBalancerSupportsPortOverrideTest {
ConfigurationManager.getConfigInstance().setProperty("DiscoveryEnabled.testSecureVipPortCanBeOverriden.ribbon.SecurePort", "6002"); ConfigurationManager.getConfigInstance().setProperty("DiscoveryEnabled.testSecureVipPortCanBeOverriden.ribbon.SecurePort", "6002");
ConfigurationManager.getConfigInstance().setProperty("DiscoveryEnabled.testSecureVipPortCanBeOverriden.ribbon.TargetRegion", "region"); ConfigurationManager.getConfigInstance().setProperty("DiscoveryEnabled.testSecureVipPortCanBeOverriden.ribbon.TargetRegion", "region");
ConfigurationManager.getConfigInstance().setProperty("DiscoveryEnabled.testSecureVipPortCanBeOverriden.ribbon.NIWSServerListClassName", DiscoveryEnabledNIWSServerList.class.getName()); ConfigurationManager.getConfigInstance().setProperty("DiscoveryEnabled.testSecureVipPortCanBeOverriden.ribbon.NIWSServerListClassName", DiscoveryEnabledNIWSServerList.class.getName());
ConfigurationManager.getConfigInstance().setProperty("DiscoveryEnabled.testSecureVipPortCanBeOverriden.ribbon.ForceClientPortConfiguration", "true"); ConfigurationManager.getConfigInstance().setProperty("DiscoveryEnabled.testSecureVipPortCanBeOverriden.ribbon.ForceClientPortConfiguration", "true");
DiscoveryEnabledNIWSServerList deList = new DiscoveryEnabledNIWSServerList(); DiscoveryEnabledNIWSServerList deList = new DiscoveryEnabledNIWSServerList();
......
...@@ -147,19 +147,19 @@ public class RestClient extends AbstractLoadBalancerAwareClient<HttpRequest, Htt ...@@ -147,19 +147,19 @@ public class RestClient extends AbstractLoadBalancerAwareClient<HttpRequest, Htt
super.initWithNiwsConfig(clientConfig); super.initWithNiwsConfig(clientConfig);
this.ncc = clientConfig; this.ncc = clientConfig;
this.restClientName = ncc.getClientName(); this.restClientName = ncc.getClientName();
this.isSecure = getBooleanFromConfig(ncc, CommonClientConfigKey.IsSecure, this.isSecure); this.isSecure = ncc.get(CommonClientConfigKey.IsSecure, this.isSecure);
this.isHostnameValidationRequired = getBooleanFromConfig(ncc, CommonClientConfigKey.IsHostnameValidationRequired, this.isHostnameValidationRequired); this.isHostnameValidationRequired = ncc.get(CommonClientConfigKey.IsHostnameValidationRequired, this.isHostnameValidationRequired);
this.isClientAuthRequired = getBooleanFromConfig(ncc, CommonClientConfigKey.IsClientAuthRequired, this.isClientAuthRequired); this.isClientAuthRequired = ncc.get(CommonClientConfigKey.IsClientAuthRequired, this.isClientAuthRequired);
this.bFollowRedirects = getBooleanFromConfig(ncc, CommonClientConfigKey.FollowRedirects, true); this.bFollowRedirects = ncc.get(CommonClientConfigKey.FollowRedirects, true);
this.ignoreUserToken = getBooleanFromConfig(ncc, CommonClientConfigKey.IgnoreUserTokenInConnectionPoolForSecureClient, this.ignoreUserToken); this.ignoreUserToken = ncc.get(CommonClientConfigKey.IgnoreUserTokenInConnectionPoolForSecureClient, this.ignoreUserToken);
this.config = new DefaultApacheHttpClient4Config(); this.config = new DefaultApacheHttpClient4Config();
this.config.getProperties().put( this.config.getProperties().put(
ApacheHttpClient4Config.PROPERTY_CONNECT_TIMEOUT, ApacheHttpClient4Config.PROPERTY_CONNECT_TIMEOUT,
ncc.getOrDefault(CommonClientConfigKey.ConnectTimeout)); ncc.get(CommonClientConfigKey.ConnectTimeout));
this.config.getProperties().put( this.config.getProperties().put(
ApacheHttpClient4Config.PROPERTY_READ_TIMEOUT, ApacheHttpClient4Config.PROPERTY_READ_TIMEOUT,
ncc.getOrDefault(CommonClientConfigKey.ReadTimeout)); ncc.get(CommonClientConfigKey.ReadTimeout));
this.restClient = apacheHttpClientSpecificInitialization(); this.restClient = apacheHttpClientSpecificInitialization();
this.setRetryHandler(new HttpClientLoadBalancerErrorHandler(ncc)); this.setRetryHandler(new HttpClientLoadBalancerErrorHandler(ncc));
...@@ -470,13 +470,6 @@ public class RestClient extends AbstractLoadBalancerAwareClient<HttpRequest, Htt ...@@ -470,13 +470,6 @@ public class RestClient extends AbstractLoadBalancerAwareClient<HttpRequest, Htt
task.getHeaders(), task.getQueryParams(), config, task.getEntity()); task.getHeaders(), task.getQueryParams(), config, task.getEntity());
} }
private boolean getBooleanFromConfig(IClientConfig overriddenClientConfig, IClientConfigKey<Boolean> key, boolean defaultValue) {
return Optional.ofNullable(overriddenClientConfig)
.map(config -> config.get(key))
.orElse(defaultValue);
}
@Override @Override
protected int getDefaultPortFromScheme(String scheme) { protected int getDefaultPortFromScheme(String scheme) {
int port = super.getDefaultPortFromScheme(scheme); int port = super.getDefaultPortFromScheme(scheme);
...@@ -489,7 +482,7 @@ public class RestClient extends AbstractLoadBalancerAwareClient<HttpRequest, Htt ...@@ -489,7 +482,7 @@ public class RestClient extends AbstractLoadBalancerAwareClient<HttpRequest, Htt
@Override @Override
protected Pair<String, Integer> deriveSchemeAndPortFromPartialUri(URI uri) { protected Pair<String, Integer> deriveSchemeAndPortFromPartialUri(URI uri) {
boolean isSecure = getBooleanFromConfig(ncc, CommonClientConfigKey.IsSecure, this.isSecure); boolean isSecure = ncc.get(CommonClientConfigKey.IsSecure, this.isSecure);
String scheme = uri.getScheme(); String scheme = uri.getScheme();
if (scheme != null) { if (scheme != null) {
isSecure = scheme.equalsIgnoreCase("https"); isSecure = scheme.equalsIgnoreCase("https");
...@@ -507,7 +500,7 @@ public class RestClient extends AbstractLoadBalancerAwareClient<HttpRequest, Htt ...@@ -507,7 +500,7 @@ public class RestClient extends AbstractLoadBalancerAwareClient<HttpRequest, Htt
scheme = "http"; scheme = "http";
} }
} }
return new Pair<String, Integer>(scheme, port); return new Pair<>(scheme, port);
} }
private HttpResponse execute(HttpRequest.Verb verb, URI uri, private HttpResponse execute(HttpRequest.Verb verb, URI uri,
...@@ -516,7 +509,7 @@ public class RestClient extends AbstractLoadBalancerAwareClient<HttpRequest, Htt ...@@ -516,7 +509,7 @@ public class RestClient extends AbstractLoadBalancerAwareClient<HttpRequest, Htt
HttpClientResponse thisResponse = null; HttpClientResponse thisResponse = null;
final boolean bbFollowRedirects = Optional.ofNullable(overriddenClientConfig) final boolean bbFollowRedirects = Optional.ofNullable(overriddenClientConfig)
.map(config -> config.get(CommonClientConfigKey.FollowRedirects, bFollowRedirects)) .flatMap(config -> config.getIfSet(CommonClientConfigKey.FollowRedirects))
.orElse(bFollowRedirects); .orElse(bFollowRedirects);
restClient.setFollowRedirects(bbFollowRedirects); restClient.setFollowRedirects(bbFollowRedirects);
......
...@@ -456,7 +456,7 @@ public class LoadBalancingHttpClient<I, O> extends LoadBalancingRxClientWithPool ...@@ -456,7 +456,7 @@ public class LoadBalancingHttpClient<I, O> extends LoadBalancingRxClientWithPool
} }
int port = uri.getPort(); int port = uri.getPort();
if (port < 0) { if (port < 0) {
if (Optional.ofNullable(clientConfig.get(IClientConfigKey.Keys.IsSecure)).orElse(false)) { if (clientConfig.get(IClientConfigKey.Keys.IsSecure, false)) {
port = 443; port = 443;
} else { } else {
port = 80; port = 80;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册