Skip to content

Commit f952109

Browse files
committed
polishing
1 parent bdad865 commit f952109

File tree

2 files changed

+29
-26
lines changed

2 files changed

+29
-26
lines changed

client/src/main/java/io/split/client/SplitClientConfig.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import io.split.storages.enums.OperationMode;
1010
import io.split.storages.enums.StorageMode;
1111
import org.apache.hc.core5.http.HttpHost;
12+
import org.slf4j.LoggerFactory;
1213
import pluggable.CustomStorageWrapper;
1314

1415
import java.io.IOException;
@@ -28,6 +29,7 @@
2829
*/
2930
public class SplitClientConfig {
3031

32+
private static final org.slf4j.Logger _log = LoggerFactory.getLogger(SplitClientConfig.class);
3133
public static final String LOCALHOST_DEFAULT_FILE = "split.yaml";
3234
public static final String SDK_ENDPOINT = "https://sdk.split.io";
3335
public static final String EVENTS_ENDPOINT = "https://events.split.io";
@@ -1140,6 +1142,11 @@ private void verifyProxy() {
11401142
if (_proxyConfiguration == null)
11411143
return;
11421144

1145+
if (!_proxyHost.equals("localhost")) {
1146+
_log.warn("Both the deprecated proxy configuration methods (`proxyHost`, `proxyPort`, `proxyUsername`, or `proxyPassword`) " +
1147+
"and the new `ProxyConfiguration` builder are being used. `ProxyConfiguration` will take precedence.");
1148+
}
1149+
11431150
if (!(_proxyConfiguration.getHost().getSchemeName().equals(HttpScheme.HTTP) ||
11441151
_proxyConfiguration.getHost().getSchemeName().equals(HttpScheme.HTTPS))) {
11451152
throw new IllegalArgumentException("Proxy scheme must be either http or https.");

client/src/main/java/io/split/client/SplitFactoryImpl.java

Lines changed: 22 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -629,47 +629,43 @@ private static SSLContext buildSSLContext(SplitClientConfig config) throws IOExc
629629
private static HttpClientBuilder setupProxy(HttpClientBuilder httpClientbuilder, SplitClientConfig config) {
630630
_log.info("Initializing Split SDK with proxy settings");
631631
HttpHost proxyHost;
632-
if (config.proxyConfiguration() != null && config.proxyConfiguration().getHost() != null) {
632+
String userName = null;
633+
String password = null;
634+
if (config.proxyConfiguration() != null) {
633635
proxyHost = config.proxyConfiguration().getHost();
634-
} else {
635-
_log.warn("`proxyHost`, `proxyPort` configuration methods are deprecated. Please use `ProxyConfiguration` builder instead.");
636-
proxyHost = config.proxy();
637-
}
638-
DefaultProxyRoutePlanner routePlanner = new DefaultProxyRoutePlanner(proxyHost);
639-
httpClientbuilder.setRoutePlanner(routePlanner);
640-
641-
if ((config.proxyUsername() != null && config.proxyPassword() != null) ||
642-
(config.proxyConfiguration() != null && config.proxyConfiguration().getProxyCredentialsProvider() != null &&
643-
config.proxyConfiguration().getProxyCredentialsProvider() instanceof io.split.client.dtos.BasicCredentialsProvider)) {
644-
_log.debug("Proxy setup using credentials");
645-
String userName;
646-
String password;
647-
if (config.proxyUsername() == null && config.proxyPassword() == null) {
636+
if (config.proxyConfiguration().getProxyCredentialsProvider() != null &&
637+
config.proxyConfiguration().getProxyCredentialsProvider() instanceof io.split.client.dtos.BasicCredentialsProvider) {
648638
io.split.client.dtos.BasicCredentialsProvider basicAuth =
649639
(io.split.client.dtos.BasicCredentialsProvider) config.proxyConfiguration().getProxyCredentialsProvider();
650640
userName = basicAuth.getUsername();
651641
password = basicAuth.getPassword();
652-
} else {
653-
_log.warn("`proxyUsername` and `proxyPassword` configuration methods are deprecated. " +
654-
"Please use `ProxyConfiguration` builder instead.");
642+
}
643+
if (config.proxyConfiguration().getProxyCredentialsProvider() instanceof io.split.client.dtos.BearerCredentialsProvider) {
644+
_log.debug("Proxy setup using Bearer token");
645+
httpClientbuilder.setDefaultCredentialsProvider(new HttpClientDynamicCredentials(
646+
(BearerCredentialsProvider) config.proxyConfiguration().getProxyCredentialsProvider()));
647+
}
648+
} else {
649+
proxyHost = config.proxy();
650+
if (config.proxyUsername() != null && config.proxyPassword() != null) {
655651
userName = config.proxyUsername();
656652
password = config.proxyPassword();
657653
}
654+
}
655+
656+
DefaultProxyRoutePlanner routePlanner = new DefaultProxyRoutePlanner(proxyHost);
657+
httpClientbuilder.setRoutePlanner(routePlanner);
658+
659+
if (userName != null && password != null) {
660+
_log.debug("Proxy setup using credentials");
658661
BasicCredentialsProvider credsProvider = new BasicCredentialsProvider();
659662
AuthScope siteScope = new AuthScope(proxyHost.getHostName(), proxyHost.getPort());
660663
Credentials siteCreds = new UsernamePasswordCredentials(userName,
661664
password.toCharArray());
662665
credsProvider.setCredentials(siteScope, siteCreds);
663666
httpClientbuilder.setDefaultCredentialsProvider(credsProvider);
664667
}
665-
666-
if (config.proxyConfiguration() != null &&
667-
config.proxyConfiguration().getProxyCredentialsProvider() instanceof io.split.client.dtos.BearerCredentialsProvider) {
668-
_log.debug("Proxy setup using Bearer token");
669-
httpClientbuilder.setDefaultCredentialsProvider(new HttpClientDynamicCredentials(
670-
(BearerCredentialsProvider) config.proxyConfiguration().getProxyCredentialsProvider()));
671-
}
672-
668+
673669
return httpClientbuilder;
674670
}
675671

0 commit comments

Comments
 (0)