use of com.sforce.ws.ConnectorConfig in project incubator-gobblin by apache.
the class SalesforceExtractor method bulkApiLogin.
/**
* Login to salesforce
* @return login status
*/
public boolean bulkApiLogin() throws Exception {
log.info("Authenticating salesforce bulk api");
boolean success = false;
String hostName = this.workUnitState.getProp(ConfigurationKeys.SOURCE_CONN_HOST_NAME);
String apiVersion = this.workUnitState.getProp(ConfigurationKeys.SOURCE_CONN_VERSION);
if (Strings.isNullOrEmpty(apiVersion)) {
apiVersion = "29.0";
}
String soapAuthEndPoint = hostName + SALESFORCE_SOAP_SERVICE + "/" + apiVersion;
try {
ConnectorConfig partnerConfig = new ConnectorConfig();
if (super.workUnitState.contains(ConfigurationKeys.SOURCE_CONN_USE_PROXY_URL) && !super.workUnitState.getProp(ConfigurationKeys.SOURCE_CONN_USE_PROXY_URL).isEmpty()) {
partnerConfig.setProxy(super.workUnitState.getProp(ConfigurationKeys.SOURCE_CONN_USE_PROXY_URL), super.workUnitState.getPropAsInt(ConfigurationKeys.SOURCE_CONN_USE_PROXY_PORT));
}
String accessToken = sfConnector.getAccessToken();
if (accessToken == null) {
boolean isConnectSuccess = sfConnector.connect();
if (isConnectSuccess) {
accessToken = sfConnector.getAccessToken();
}
}
if (accessToken != null) {
String serviceEndpoint = sfConnector.getInstanceUrl() + SALESFORCE_SOAP_SERVICE + "/" + apiVersion;
partnerConfig.setSessionId(accessToken);
partnerConfig.setServiceEndpoint(serviceEndpoint);
} else {
String securityToken = this.workUnitState.getProp(ConfigurationKeys.SOURCE_CONN_SECURITY_TOKEN);
String password = PasswordManager.getInstance(this.workUnitState).readPassword(this.workUnitState.getProp(ConfigurationKeys.SOURCE_CONN_PASSWORD));
partnerConfig.setUsername(this.workUnitState.getProp(ConfigurationKeys.SOURCE_CONN_USERNAME));
partnerConfig.setPassword(password + securityToken);
}
partnerConfig.setAuthEndpoint(soapAuthEndPoint);
new PartnerConnection(partnerConfig);
String soapEndpoint = partnerConfig.getServiceEndpoint();
String restEndpoint = soapEndpoint.substring(0, soapEndpoint.indexOf("Soap/")) + "async/" + apiVersion;
ConnectorConfig config = new ConnectorConfig();
config.setSessionId(partnerConfig.getSessionId());
config.setRestEndpoint(restEndpoint);
config.setCompression(true);
config.setTraceFile("traceLogs.txt");
config.setTraceMessage(false);
config.setPrettyPrintXml(true);
if (super.workUnitState.contains(ConfigurationKeys.SOURCE_CONN_USE_PROXY_URL) && !super.workUnitState.getProp(ConfigurationKeys.SOURCE_CONN_USE_PROXY_URL).isEmpty()) {
config.setProxy(super.workUnitState.getProp(ConfigurationKeys.SOURCE_CONN_USE_PROXY_URL), super.workUnitState.getPropAsInt(ConfigurationKeys.SOURCE_CONN_USE_PROXY_PORT));
}
this.bulkConnection = new BulkConnection(config);
success = true;
} catch (RuntimeException e) {
throw new RuntimeException("Failed to connect to salesforce bulk api; error - " + e, e);
}
return success;
}
use of com.sforce.ws.ConnectorConfig in project components by Talend.
the class SalesforceSourceOrSink method connectBulk.
protected BulkConnection connectBulk(ConnectorConfig config) throws ComponentException {
final SalesforceConnectionProperties connProps = getConnectionProperties();
/*
* When PartnerConnection is instantiated, a login is implicitly executed and, if successful, a valid session id is
* stored in the ConnectorConfig instance. Use this key to initialize a BulkConnection:
*/
ConnectorConfig bulkConfig = new ConnectorConfig();
setProxy(bulkConfig);
bulkConfig.setSessionId(config.getSessionId());
// For session renew
bulkConfig.setSessionRenewer(config.getSessionRenewer());
bulkConfig.setUsername(config.getUsername());
bulkConfig.setPassword(config.getPassword());
/*
* The endpoint for the Bulk API service is the same as for the normal SOAP uri until the /Soap/ part. From here
* it's '/async/versionNumber'
*/
String soapEndpoint = config.getServiceEndpoint();
// Service endpoint should be like this:
// https://ap1.salesforce.com/services/Soap/u/37.0/00D90000000eSq3
String apiVersion = soapEndpoint.substring(soapEndpoint.lastIndexOf("/services/Soap/u/") + 17);
apiVersion = apiVersion.substring(0, apiVersion.indexOf("/"));
String restEndpoint = soapEndpoint.substring(0, soapEndpoint.indexOf("Soap/")) + "async/" + apiVersion;
bulkConfig.setRestEndpoint(restEndpoint);
// This should only be false when doing debugging.
bulkConfig.setCompression(connProps.needCompression.getValue());
bulkConfig.setTraceMessage(connProps.httpTraceMessage.getValue());
bulkConfig.setValidateSchema(false);
try {
return new BulkConnection(bulkConfig);
} catch (AsyncApiException e) {
throw new ComponentException(e);
}
}
use of com.sforce.ws.ConnectorConfig in project components by Talend.
the class SalesforceSourceOrSinkTestIT method testSalesForcePasswordExpired.
@Test(expected = ConnectionException.class)
public void testSalesForcePasswordExpired() throws ConnectionException {
SalesforceSourceOrSink salesforceSourceOrSink = new SalesforceSourceOrSink();
TSalesforceInputProperties properties = (TSalesforceInputProperties) new TSalesforceInputProperties(null).init();
salesforceSourceOrSink.initialize(null, properties);
ConnectorConfig config = new ConnectorConfig();
config.setUsername(StringUtils.strip(USER_ID_EXPIRED, "\""));
String password = StringUtils.strip(PASSWORD_EXPIRED, "\"");
String securityKey = StringUtils.strip(SECURITY_KEY_EXPIRED, "\"");
if (StringUtils.isNotEmpty(securityKey)) {
password = password + securityKey;
}
config.setPassword(password);
PartnerConnection connection = null;
try {
connection = salesforceSourceOrSink.doConnection(config, true);
} catch (LoginFault ex) {
Assert.fail("Must be an exception related to expired password, not the Login Fault.");
} finally {
if (null != connection) {
connection.logout();
}
}
}
use of com.sforce.ws.ConnectorConfig in project components by Talend.
the class SalesforceDataprepSource method connect.
ConnectionHolder connect(RuntimeContainer container) throws IOException {
SalesforceRuntimeCommon.enableTLSv11AndTLSv12ForJava7();
final ConnectionHolder ch = new ConnectionHolder();
ConnectorConfig config = new ConnectorConfig();
config.setUsername(datastore.userId.getValue());
String password = datastore.password.getValue();
String securityKey = datastore.securityKey.getValue();
if (!StringUtils.isEmpty(securityKey)) {
password = password + securityKey;
}
config.setPassword(password);
// Notes on how to test this
// http://thysmichels.com/2014/02/15/salesforce-wsc-partner-connection-session-renew-when-session-timeout/
config.setSessionRenewer(new SessionRenewer() {
@Override
public SessionRenewalHeader renewSession(ConnectorConfig connectorConfig) throws ConnectionException {
LOG.debug("renewing session...");
SessionRenewalHeader header = new SessionRenewalHeader();
connectorConfig.setSessionId(null);
PartnerConnection connection = doConnection(connectorConfig);
// update the connection session header
ch.connection.setSessionHeader(connection.getSessionHeader().getSessionId());
header.name = new QName("urn:partner.soap.sforce.com", "SessionHeader");
header.headerElement = connection.getSessionHeader();
LOG.debug("session renewed!");
return header;
}
});
config.setConnectionTimeout(timeout);
// This should only be false when doing debugging.
config.setCompression(true);
config.setUseChunkedPost(true);
config.setValidateSchema(false);
try {
ch.connection = doConnection(config);
ch.bulkConnection = connectBulk(ch.connection.getConfig());
return ch;
} catch (ConnectionException e) {
throw new IOException(e);
}
}
use of com.sforce.ws.ConnectorConfig in project components by Talend.
the class SalesforceRuntimeCommonTest method testRenewSession.
@Test
public void testRenewSession() throws Exception {
SessionRenewer sessionRenewer = mock(SessionRenewer.class);
ConnectorConfig connectorConfig = new ConnectorConfig();
connectorConfig.setSessionRenewer(sessionRenewer);
SalesforceRuntimeCommon.renewSession(connectorConfig);
verify(sessionRenewer, only()).renewSession(eq(connectorConfig));
}
Aggregations