Skip to content

Commit

Permalink
rename httpclient classes for consistency
Browse files Browse the repository at this point in the history
Rename:
HttpClientTransport to HttpTransportImpl
DefaultSimplePost to SimplePostImpl
SimplePost to SimplePostInterface
ashitsalesforce committed Jan 12, 2025
1 parent 0bd976b commit 7620524
Showing 19 changed files with 52 additions and 53 deletions.
Original file line number Diff line number Diff line change
@@ -28,7 +28,7 @@

import com.salesforce.dataloader.action.AbstractExtractAction;
import com.salesforce.dataloader.action.progress.ILoaderProgress;
import com.salesforce.dataloader.client.HttpClientTransport;
import com.salesforce.dataloader.client.HttpTransportImpl;
import com.salesforce.dataloader.config.AppConfig;
import com.salesforce.dataloader.config.Messages;
import com.salesforce.dataloader.controller.Controller;
@@ -206,7 +206,7 @@ private String getBinaryContentForURL(String urlStr, String fieldName) {
+ "/"
+ refId;

HttpClientTransport transport = HttpClientTransport.getInstance();
HttpTransportImpl transport = HttpTransportImpl.getInstance();
transport.setConfig(controller.getClient().getConnectorConfig());
InputStream is = transport.httpGet(urlStr);
byte[] binaryResponse = is.readAllBytes();
Original file line number Diff line number Diff line change
@@ -35,7 +35,7 @@
import org.apache.logging.log4j.Logger;

import com.salesforce.dataloader.client.ClientBase;
import com.salesforce.dataloader.client.HttpClientTransport;
import com.salesforce.dataloader.client.HttpTransportImpl;
import com.salesforce.dataloader.client.HttpTransportInterface;
import com.salesforce.dataloader.config.AppConfig;
import com.salesforce.dataloader.exception.HttpClientTransportException;
@@ -136,7 +136,7 @@ private InputStream invokeBulkV1GET(String[] urlParts) throws AsyncApiException
}
}
try {
HttpTransportInterface transport = HttpClientTransport.getInstance();
HttpTransportInterface transport = HttpTransportImpl.getInstance();
transport.setConfig(getConfig());
return transport.httpGet(endpoint);
} catch (IOException | HttpClientTransportException e) {
Original file line number Diff line number Diff line change
@@ -151,7 +151,7 @@ private static void writeTo(BufferedInputStream bis, BufferedOutputStream bos) t
import org.apache.logging.log4j.Logger;

import com.salesforce.dataloader.client.ClientBase;
import com.salesforce.dataloader.client.HttpClientTransport;
import com.salesforce.dataloader.client.HttpTransportImpl;
import com.salesforce.dataloader.client.HttpTransportInterface;
import com.salesforce.dataloader.controller.Controller;
import com.salesforce.dataloader.exception.HttpClientTransportException;
@@ -284,7 +284,7 @@ public JobInfo startIngest(String jobId, InputStream bulkUploadStream) throws As
String urlString = constructRequestURL(jobId) + "batches/";
HashMap<String, String> headers = getHeaders(CSV_CONTENT_TYPE, JSON_CONTENT_TYPE);
try {
HttpClientTransport clientTransport = HttpClientTransport.getInstance();
HttpTransportImpl clientTransport = HttpTransportImpl.getInstance();
clientTransport.setConfig(getConfig());
clientTransport.connect(urlString, headers, false, HttpTransportInterface.SupportedHttpMethodType.PUT, bulkUploadStream, CSV_CONTENT_TYPE);

@@ -413,7 +413,7 @@ private JobInfo doSendJobRequestToServer(String urlString,
try {
InputStream in = null;
boolean successfulRequest = true;
HttpClientTransport transport = HttpClientTransport.getInstance();
HttpTransportImpl transport = HttpTransportImpl.getInstance();
transport.setConfig(getConfig());
if (requestMethod == HttpMethod.GET) {
if (requestBodyMap != null && !requestBodyMap.isEmpty()) {
@@ -528,7 +528,7 @@ private HashMap<String, String> getHeaders(String requestContentType, String acc
private InputStream doGetQueryResultStream(URL resultsURL, HashMap<String, String> headers) throws IOException, AsyncApiException, ConnectionException {
InputStream is = null;
try {
HttpClientTransport transport = HttpClientTransport.getInstance();
HttpTransportImpl transport = HttpTransportImpl.getInstance();
transport.setConfig(getConfig());
is = transport.httpGet(resultsURL.toString());
HttpResponse httpResponse = transport.getHttpResponse();
@@ -559,7 +559,7 @@ private InputStream doGetIngestResultsStream(String jobId, String resultsType) t
String resultsURLString = constructRequestURL(jobId) + resultsType;
InputStream is = null;
try {
HttpClientTransport transport = HttpClientTransport.getInstance();
HttpTransportImpl transport = HttpTransportImpl.getInstance();
transport.setConfig(getConfig());
is = transport.httpGet(resultsURLString);
} catch (IOException e) {
Original file line number Diff line number Diff line change
@@ -41,7 +41,7 @@
import org.apache.logging.log4j.Logger;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.salesforce.dataloader.client.HttpClientTransport;
import com.salesforce.dataloader.client.HttpTransportImpl;
import com.salesforce.dataloader.client.HttpTransportInterface;
import com.salesforce.dataloader.client.SessionInfo;
import com.salesforce.dataloader.client.CompositeRESTClient.ACTION_ENUM;
@@ -110,7 +110,7 @@ public SaveResult[] loadAction(SessionInfo session, ACTION_ENUM action, List<Dyn
logger.error(message);
throw new ConnectionException(message);
}
HttpClientTransport transport = HttpClientTransport.getInstance();
HttpTransportImpl transport = HttpTransportImpl.getInstance();
transport.setConfig(connectorConfig);

// assume update operation by default and set http method value to PATCH
Original file line number Diff line number Diff line change
@@ -92,7 +92,7 @@ public class HttpClientTransportv1 implements HttpTransportInterfacev1 {
private static CloseableHttpClient currentHttpClient = null;
private static boolean reuseConnection = true;
private static long serverInvocationCount = 0;
private static Logger logger = DLLogManager.getLogger(HttpClientTransport.class);
private static Logger logger = DLLogManager.getLogger(HttpTransportImpl.class);

public HttpClientTransportv1() {
}
Original file line number Diff line number Diff line change
@@ -80,7 +80,7 @@
* @author Jeff Lai
* @since 25.0.2
*/
public class HttpClientTransport implements HttpTransportInterface {
public class HttpTransportImpl implements HttpTransportInterface {


private static final String AUTH_HEADER_VALUE_PREFIX = "Bearer ";
@@ -95,9 +95,9 @@ public class HttpClientTransport implements HttpTransportInterface {
private ByteArrayOutputStream entityByteOut;
private static CloseableHttpClient currentHttpClient = null;
private static long serverInvocationCount = 0;
private static Logger logger = DLLogManager.getLogger(HttpClientTransport.class);
private static Logger logger = DLLogManager.getLogger(HttpTransportImpl.class);
private HttpResponse httpResponse;
private static final HttpClientTransport singletonTransportInstance = new HttpClientTransport();
private static final HttpTransportImpl singletonTransportInstance = new HttpTransportImpl();

@Override
public synchronized void setConfig(ConnectorConfig newConfig) {
@@ -476,7 +476,7 @@ public InputStream httpGet(String urlStr) throws IOException, AsyncApiException,
return in;
}

public static HttpClientTransport getInstance() {
public static HttpTransportImpl getInstance() {
return singletonTransportInstance;
}
}
Original file line number Diff line number Diff line change
@@ -52,6 +52,7 @@ enum SupportedHttpMethodType {
DELETE,
GET
}
int PROXY_AUTHENTICATION_REQUIRED = 407;
OutputStream connect(String endpoint, HashMap<String, String> httpHeaders, boolean enableCompression,
HttpTransportInterface.SupportedHttpMethodType httpMethod) throws IOException;

Original file line number Diff line number Diff line change
@@ -35,25 +35,25 @@
*/
public class SimplePostFactory {

private static Function<Criteria, SimplePost> constructor = c -> new DefaultSimplePost(c.appConfig, c.endpoint, c.pairs);;
private static Function<Criteria, SimplePostInterface> constructor = c -> new SimplePostImpl(c.appConfig, c.endpoint, c.pairs);;

public static class Criteria{
public AppConfig appConfig;
public String endpoint;
public BasicNameValuePair[] pairs;
}

public static Function<Criteria, SimplePost> getConstructor()
public static Function<Criteria, SimplePostInterface> getConstructor()
{
return constructor;
}

public static void setConstructor(Function<Criteria, SimplePost> constructor)
public static void setConstructor(Function<Criteria, SimplePostInterface> constructor)
{
SimplePostFactory.constructor = constructor;
}

public static SimplePost getInstance(AppConfig appConfig, String endpoint, BasicNameValuePair... pairs){
public static SimplePostInterface getInstance(AppConfig appConfig, String endpoint, BasicNameValuePair... pairs){
Criteria criteria = new Criteria();
criteria.appConfig = appConfig;
criteria.endpoint = endpoint;
Original file line number Diff line number Diff line change
@@ -39,9 +39,7 @@
/**
* simplied http client transport for posts (used for oauth)
*/
public class DefaultSimplePost implements SimplePost {

public static final int PROXY_AUTHENTICATION_REQUIRED = 407;
public class SimplePostImpl implements SimplePostInterface {

private boolean successful;
private AppConfig appConfig;
@@ -52,7 +50,7 @@ public class DefaultSimplePost implements SimplePost {
private String reasonPhrase;
private CloseableHttpResponse response;

DefaultSimplePost(AppConfig appConfig, String endpoint, BasicNameValuePair... pairs) {
SimplePostImpl(AppConfig appConfig, String endpoint, BasicNameValuePair... pairs) {
this.appConfig = appConfig;
this.endpoint = endpoint;
this.pairs = pairs;
@@ -71,7 +69,7 @@ public void addBasicNameValuePair(BasicNameValuePair pair) {
public void post() throws IOException, ParameterLoadException {
ConnectorConfig connConfig = new ConnectorConfig();
AppUtil.setConnectorConfigProxySettings(appConfig, connConfig);
HttpClientTransport clientTransport = HttpClientTransport.getInstance();
HttpTransportImpl clientTransport = HttpTransportImpl.getInstance();
clientTransport.setConfig(connConfig);
this.input = clientTransport.simplePost(endpoint, null, pairs);
successful = clientTransport.isSuccessful();
Original file line number Diff line number Diff line change
@@ -36,7 +36,7 @@
/**
* Created by rmazzeo on 12/9/15.
*/
public interface SimplePost {
public interface SimplePostInterface {
void post() throws IOException, ParameterLoadException;

boolean isSuccessful();
Original file line number Diff line number Diff line change
@@ -35,7 +35,7 @@ public TransportFactoryImpl() {

@Override
public Transport createTransport() {
return HttpClientTransport.getInstance();
return HttpTransportImpl.getInstance();
}

}
Original file line number Diff line number Diff line change
@@ -31,7 +31,7 @@
import com.salesforce.dataloader.client.BulkV1Client;
import com.salesforce.dataloader.client.BulkV2Client;
import com.salesforce.dataloader.client.ClientBase;
import com.salesforce.dataloader.client.HttpClientTransport;
import com.salesforce.dataloader.client.HttpTransportImpl;
import com.salesforce.dataloader.client.PartnerClient;
import com.salesforce.dataloader.client.CompositeRESTClient;
import com.salesforce.dataloader.client.ReferenceEntitiesDescribeMap;
@@ -149,7 +149,7 @@ public synchronized String getLatestDownloadableDataLoaderVersion() {
try {
ConnectorConfig connConfig = new ConnectorConfig();
AppUtil.setConnectorConfigProxySettings(appConfig, connConfig);
HttpClientTransport clientTransport = HttpClientTransport.getInstance();
HttpTransportImpl clientTransport = HttpTransportImpl.getInstance();
clientTransport.setConfig(connConfig);
InputStream inputStream = clientTransport.httpGet(AppUtil.DATALOADER_DOWNLOAD_URL);

Original file line number Diff line number Diff line change
@@ -35,7 +35,7 @@

import org.apache.http.message.BasicNameValuePair;

import com.salesforce.dataloader.client.SimplePost;
import com.salesforce.dataloader.client.SimplePostInterface;
import com.salesforce.dataloader.client.SimplePostFactory;
import com.salesforce.dataloader.config.AppConfig;
import com.salesforce.dataloader.exception.ParameterLoadException;
@@ -56,9 +56,9 @@ public static String getStartUrlImpl(AppConfig appConfig) throws UnsupportedEnco
+ URLEncoder.encode(appConfig.getOAuthRedirectURIForCurrentEnv(), StandardCharsets.UTF_8.name());
}

public static SimplePost handleSecondPost(String code, AppConfig appConfig) throws IOException, ParameterLoadException {
public static SimplePostInterface handleSecondPost(String code, AppConfig appConfig) throws IOException, ParameterLoadException {
String server = appConfig.getAuthEndpointForCurrentEnv() + "/services/oauth2/token";
SimplePost client = SimplePostFactory.getInstance(appConfig, server,
SimplePostInterface client = SimplePostFactory.getInstance(appConfig, server,
new BasicNameValuePair("grant_type", "authorization_code"),
new BasicNameValuePair("code", code),
new BasicNameValuePair(AppConfig.CLIENT_ID_HEADER_NAME, appConfig.getClientIDForCurrentEnv()),
Original file line number Diff line number Diff line change
@@ -54,7 +54,7 @@
import org.eclipse.swt.widgets.Shell;

import com.salesforce.dataloader.action.progress.ILoaderProgress;
import com.salesforce.dataloader.client.HttpClientTransport;
import com.salesforce.dataloader.client.HttpTransportImpl;
import com.salesforce.dataloader.config.AppConfig;
import com.salesforce.dataloader.controller.Controller;

@@ -67,7 +67,7 @@ public class DataLoaderRunner extends Thread {

public void run() {
// called just before the program closes
HttpClientTransport.closeHttpClient();
HttpTransportImpl.closeHttpClient();
}

public static void main(String[] commandLineOptions) {
@@ -82,7 +82,7 @@ public static void main(String[] commandLineOptions) {
System.exit(ex.getExitCode());
} finally {
if (logger != null) {
logger.debug("Number of server API invocations = " + HttpClientTransport.getServerInvocationCount());
logger.debug("Number of server API invocations = " + HttpTransportImpl.getServerInvocationCount());
}
}
System.exit(exitCode);
Original file line number Diff line number Diff line change
@@ -26,7 +26,7 @@

package com.salesforce.dataloader.ui;

import com.salesforce.dataloader.client.DefaultSimplePost;
import com.salesforce.dataloader.client.HttpTransportInterface;
import com.salesforce.dataloader.config.AppConfig;
import com.salesforce.dataloader.controller.Controller;
import com.salesforce.dataloader.model.LoginCriteria;
@@ -102,7 +102,7 @@ private void loginAsync(){
OAuthFlow flow = hasSecret ? new OAuthSecretFlow(shell, appConfig) : new OAuthTokenFlow(shell, appConfig);
if (!flow.open()) {
String message = Labels.getString("LoginPage.invalidLoginOAuth");
if (flow.getStatusCode() == DefaultSimplePost.PROXY_AUTHENTICATION_REQUIRED) {
if (flow.getStatusCode() == HttpTransportInterface.PROXY_AUTHENTICATION_REQUIRED) {
message = Labels.getFormattedString("LoginPage.proxyError", flow.getReasonPhrase());
}

Original file line number Diff line number Diff line change
@@ -25,7 +25,7 @@
*/
package com.salesforce.dataloader.ui;

import com.salesforce.dataloader.client.SimplePost;
import com.salesforce.dataloader.client.SimplePostInterface;
import com.salesforce.dataloader.config.AppConfig;
import com.salesforce.dataloader.exception.ParameterLoadException;
import com.salesforce.dataloader.oauth.OAuthSecretFlowUtil;
@@ -82,7 +82,7 @@ public void completed(ProgressEvent progressEvent) {
String code = OAuthSecretFlowUtil.handleInitialUrl(url);

if (code != null) {
SimplePost client = OAuthSecretFlowUtil.handleSecondPost(code, appConfig);
SimplePostInterface client = OAuthSecretFlowUtil.handleSecondPost(code, appConfig);
setReasonPhrase(client.getReasonPhrase());
setStatusCode(client.getStatusCode());
setResult(client.isSuccessful());
Original file line number Diff line number Diff line change
@@ -48,7 +48,7 @@
import com.google.gson.FieldNamingPolicy;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.salesforce.dataloader.client.SimplePost;
import com.salesforce.dataloader.client.SimplePostInterface;
import com.salesforce.dataloader.client.SimplePostFactory;
import com.salesforce.dataloader.config.AppConfig;
import com.salesforce.dataloader.config.Messages;
@@ -97,7 +97,7 @@ private void startBrowserLogin(AppConfig appConfig, boolean skipUserCodePage) th
this.appConfig = appConfig;
appConfig.setServerEnvironment(appConfig.getString(AppConfig.PROP_SELECTED_SERVER_ENVIRONMENT));
oAuthTokenURLStr = appConfig.getAuthEndpointForCurrentEnv() + "/services/oauth2/token";
SimplePost client = SimplePostFactory.getInstance(appConfig, oAuthTokenURLStr,
SimplePostInterface client = SimplePostFactory.getInstance(appConfig, oAuthTokenURLStr,
new BasicNameValuePair("response_type", "device_code"),
new BasicNameValuePair(AppConfig.CLIENT_ID_HEADER_NAME, appConfig.getClientIDForCurrentEnv()),
new BasicNameValuePair("scope", "api")
@@ -191,7 +191,7 @@ public void run() {
// other than 'authorization_pending'.
int maxPollingTimeInSec = 1200;
int elapsedTimeInSec = 0;
SimplePost client;
SimplePostInterface client;
InputStream in;
while (elapsedTimeInSec <= maxPollingTimeInSec) {
try {
Original file line number Diff line number Diff line change
@@ -29,7 +29,7 @@
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.salesforce.dataloader.ConfigTestBase;
import com.salesforce.dataloader.client.SimplePost;
import com.salesforce.dataloader.client.SimplePostInterface;
import com.salesforce.dataloader.client.SimplePostFactory;
import com.salesforce.dataloader.config.AppConfig;
import com.salesforce.dataloader.exception.ParameterLoadException;
@@ -54,14 +54,14 @@
*/
public class OAuthSecretFlowUtilTests extends ConfigTestBase {

private SimplePost mockSimplePost;
private SimplePostInterface mockSimplePost;
private AppConfig appConfig;
private ArrayList<String> existingOAuthEnvironments;
private String oauthServer;
private String oauthClientId;
private String oauthRedirectUri;
private String existingEndPoint;
private Function<SimplePostFactory.Criteria, SimplePost> existingConstructor;
private Function<SimplePostFactory.Criteria, SimplePostInterface> existingConstructor;

@Before
public void testSetup(){
@@ -71,7 +71,7 @@ public void testSetup(){
oauthServer = "https://OAUTH_PARTIAL_SERVER";
oauthClientId = "CLIENTID";
oauthRedirectUri = "https://REDIRECTURI";
mockSimplePost = mock(SimplePost.class);
mockSimplePost = mock(SimplePostInterface.class);

appConfig.setValue(AppConfig.PROP_SERVER_ENVIRONMENTS, "Testing");
appConfig.setOAuthEnvironmentString("Testing", AppConfig.CLIENTID_LITERAL, oauthClientId);
@@ -147,7 +147,7 @@ public void testValidSecondResponseAccessToken(){
when(mockSimplePost.isSuccessful()).thenReturn(true);

@SuppressWarnings("unused")
SimplePost simplePost = OAuthSecretFlowUtil.handleSecondPost("simplePost", appConfig);
SimplePostInterface simplePost = OAuthSecretFlowUtil.handleSecondPost("simplePost", appConfig);

String expected = "ACCESS";
String actual = appConfig.getString(AppConfig.PROP_OAUTH_ACCESSTOKEN);
@@ -176,7 +176,7 @@ public void testValidSecondResponseRefreshToken(){
when(mockSimplePost.isSuccessful()).thenReturn(true);

@SuppressWarnings("unused")
SimplePost simplePost = OAuthSecretFlowUtil.handleSecondPost("simplePost", appConfig);
SimplePostInterface simplePost = OAuthSecretFlowUtil.handleSecondPost("simplePost", appConfig);

String expected = "REFRESHTOKEN";
String actual = appConfig.getString(AppConfig.PROP_OAUTH_REFRESHTOKEN);
@@ -203,7 +203,7 @@ public void testValidSecondResponseInstanceUrl(){
when(mockSimplePost.isSuccessful()).thenReturn(true);

@SuppressWarnings("unused")
SimplePost simplePost = OAuthSecretFlowUtil.handleSecondPost("simplePost", appConfig);
SimplePostInterface simplePost = OAuthSecretFlowUtil.handleSecondPost("simplePost", appConfig);

String expected = "https://INSTANCEURL";
String actual = appConfig.getString(AppConfig.PROP_OAUTH_INSTANCE_URL);;
Original file line number Diff line number Diff line change
@@ -45,7 +45,7 @@
import com.salesforce.dataloader.*;
import com.salesforce.dataloader.action.OperationInfo;
import com.salesforce.dataloader.action.progress.ILoaderProgress;
import com.salesforce.dataloader.client.HttpClientTransport;
import com.salesforce.dataloader.client.HttpTransportImpl;
import com.salesforce.dataloader.client.PartnerClient;
import com.salesforce.dataloader.config.AppConfig;
import com.salesforce.dataloader.controller.Controller;
@@ -110,12 +110,12 @@ protected void setMemoryIncreaseThresholds(int expectedIncreaseInMb) {
}
protected ProcessTestBase() {
super(Collections.<String, String>emptyMap());
HttpClientTransport.resetServerInvocationCount();
HttpTransportImpl.resetServerInvocationCount();
}

protected ProcessTestBase(Map<String, String> config) {
super(config);
HttpClientTransport.resetServerInvocationCount();
HttpTransportImpl.resetServerInvocationCount();
}

protected void verifyErrors(Controller controller, String expectedErrorMessage) throws DataAccessObjectException {
@@ -784,7 +784,7 @@ protected Controller runProcess(Map<String, String> argMap, boolean expectProces
assertTrue("Process failed: " + actualMessage, monitor.isSuccess());
verifyFailureFile(controller, numFailures); //A.S.: To be removed and replaced
verifySuccessFile(controller, numInserts, numUpdates, emptyId);
long serverAPIInvocations = HttpClientTransport.getServerInvocationCount();
long serverAPIInvocations = HttpTransportImpl.getServerInvocationCount();
assertTrue("Number of server invocations (" + serverAPIInvocations + ") have exceeded the threshold of " + serverApiInvocationThreshold, serverAPIInvocations <= serverApiInvocationThreshold);
} else {
assertFalse("Expected process to fail but got success: " + actualMessage, monitor.isSuccess());

0 comments on commit 7620524

Please sign in to comment.