Skip to content

Commit

Permalink
optimize server connection setups
Browse files Browse the repository at this point in the history
Revert areEquivalentConfigs() method to 9185feb to minimize the number of server connection setups.
  • Loading branch information
ashitsalesforce committed Sep 23, 2024
1 parent a9e4eb7 commit bad8787
Showing 1 changed file with 43 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
package com.salesforce.dataloader.client;

import java.io.*;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.net.*;
import java.nio.charset.StandardCharsets;
import java.util.HashMap;
Expand Down Expand Up @@ -135,8 +137,48 @@ private boolean areEquivalentConfigs(ConnectorConfig config1, ConnectorConfig co
} else if (config1 == null || config2 == null) {
// one of the configs is null, other isn't. They can't be equal.
return false;
} else if (!config1.equals(config2)) {
} else if (config1.equals(config2)) {
return true;
}

InetSocketAddress socketAddress1 = (InetSocketAddress)config1.getProxy().address();
InetSocketAddress socketAddress2 = (InetSocketAddress)config2.getProxy().address();

if (socketAddress1 == null && socketAddress2 == null) {
return true;
} else if (socketAddress1 == null || socketAddress2 == null) {
return false;
} else {
String field1, field2;
field1 = config1.getProxyUsername() == null ? "" : config1.getProxyUsername();
field2 = config2.getProxyUsername() == null ? "" : config2.getProxyUsername();
if (field1.compareTo(field2) != 0) {
return false;
}

field1 = config1.getProxyPassword() == null ? "" : config1.getProxyPassword();
field2 = config2.getProxyPassword() == null ? "" : config2.getProxyPassword();
if (field1.compareTo(field2) != 0) {
return false;
}

field1 = config1.getNtlmDomain() == null ? "" : config1.getNtlmDomain();
field2 = config2.getNtlmDomain() == null ? "" : config2.getNtlmDomain();
if (field1.compareTo(field2) != 0) {
return false;
}

field1 = socketAddress1.getHostName() == null ? "" : socketAddress1.getHostName();
field2 = socketAddress2.getHostName() == null ? "" : socketAddress2.getHostName();
if (field1.compareTo(field2) != 0) {
return false;
}

int intField1 = socketAddress1.getPort();
int intField2 = socketAddress2.getPort();
if (intField1 != intField2) {
return false;
}
}
return true;
}
Expand Down Expand Up @@ -190,17 +232,6 @@ private synchronized void initializeHttpClient() throws UnknownHostException {
httpClientBuilder.setDefaultCredentialsProvider(credentialsprovider);
httpClientBuilder.setProxyAuthenticationStrategy(new ProxyAuthenticationStrategy());
currentHttpClient = httpClientBuilder.build();
if (AppUtil.getOSType() == AppUtil.OSType.WINDOWS) {
/*
try (CloseableHttpResponse ignored = currentHttpClient.execute(new HttpHead(AppUtil.DATALOADER_DOWNLOAD_URL))) {
logger.debug("able to ping salesforce service");
} catch (Exception e) {
logger.info("Unable to use NTCredentials for proxy. Switching to UsernamePasswordCredentials");
credentials = new UsernamePasswordCredentials(proxyUser, proxyPassword);
credentialsprovider.setCredentials(scope, credentials);
}
*/
}
}
if (currentHttpClient == null) {
currentHttpClient = httpClientBuilder.build();
Expand Down

0 comments on commit bad8787

Please sign in to comment.