use of com.sforce.ws.ConnectorConfig in project components by Talend.
the class SalesforceDataprepSource method connectBulk.
protected BulkConnection connectBulk(ConnectorConfig config) throws ComponentException {
/*
* When PartnerConnection is instantiated, a login is implicitly executed and, if successful, a valid session is
* stored in the ConnectorConfig instance. Use this key to initialize a BulkConnection:
*/
ConnectorConfig bulkConfig = new ConnectorConfig();
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();
// set it by a default property file
// 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(true);
bulkConfig.setTraceMessage(false);
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 SalesforceSourceOrSink method connect.
protected ConnectionHolder connect(RuntimeContainer container) throws IOException {
SalesforceRuntimeCommon.enableTLSv11AndTLSv12ForJava7();
final ConnectionHolder ch = new ConnectionHolder();
SalesforceConnectionProperties connProps = properties.getConnectionProperties();
String refComponentId = connProps.getReferencedComponentId();
// Using another component's connection
if (refComponentId != null) {
// In a runtime container
if (container != null) {
// PartnerConnection must be created. BulkConnection is optional.
PartnerConnection connection = (PartnerConnection) container.getComponentData(refComponentId, KEY_CONNECTION);
if (connection == null) {
throw new IOException("Referenced component: " + refComponentId + " not connected");
}
ch.connection = connection;
ch.bulkConnection = (BulkConnection) container.getComponentData(refComponentId, KEY_CONNECTION_BULK);
return ch;
}
// Design time
connProps = connProps.getReferencedConnectionProperties();
}
ConnectorConfig config = new ConnectorConfig();
config.setUsername(StringUtils.strip(connProps.userPassword.userId.getStringValue(), "\""));
String password = StringUtils.strip(connProps.userPassword.password.getStringValue(), "\"");
String securityKey = StringUtils.strip(connProps.userPassword.securityKey.getStringValue(), "\"");
if (StringUtils.isNotEmpty(securityKey)) {
password = password + securityKey;
}
config.setPassword(password);
setProxy(config);
// 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, true);
// 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;
}
});
if (connProps.timeout.getValue() > 0) {
config.setConnectionTimeout(connProps.timeout.getValue());
}
config.setCompression(connProps.needCompression.getValue());
config.setUseChunkedPost(connProps.httpChunked.getValue());
config.setValidateSchema(false);
try {
// Get session from session file or new connection
if (isReuseSession()) {
Properties properties = getSessionProperties();
if (properties != null) {
this.sessionId = properties.getProperty(SalesforceConstant.SESSION_ID);
this.serviceEndPoint = properties.getProperty(SalesforceConstant.SERVICE_ENDPOINT);
}
}
if (this.sessionId != null && this.serviceEndPoint != null) {
ch.connection = doConnection(config, false);
} else {
ch.connection = doConnection(config, true);
}
if (ch.connection != null) {
String clientId = connProps.clientId.getStringValue();
if (clientId != null) {
// Need the test.
ch.connection.setCallOptions(clientId, null);
}
}
if (connProps.bulkConnection.getValue()) {
ch.bulkConnection = connectBulk(ch.connection.getConfig());
}
if (container != null) {
container.setComponentData(container.getCurrentComponentId(), KEY_CONNECTION, ch.connection);
if (ch.bulkConnection != null) {
container.setComponentData(container.getCurrentComponentId(), KEY_CONNECTION_BULK, ch.bulkConnection);
}
}
return ch;
} catch (ConnectionException e) {
throw new IOException(e);
}
}
use of com.sforce.ws.ConnectorConfig in project components by Talend.
the class SalesforceRuntimeTestUtil method login.
private void login(String endpoint) throws ConnectionException {
ConnectorConfig config = new ConnectorConfig();
config.setAuthEndpoint(endpoint);
config.setUsername(username);
config.setPassword(password + securityKey);
config.setConnectionTimeout(60000);
config.setUseChunkedPost(true);
partnerConnection = new PartnerConnection(config);
}
use of com.sforce.ws.ConnectorConfig in project gitblit by gitblit.
the class SalesforceAuthProvider method authenticate.
@Override
public UserModel authenticate(String username, char[] password) {
ConnectorConfig config = new ConnectorConfig();
config.setUsername(username);
config.setPassword(new String(password));
try {
PartnerConnection connection = Connector.newConnection(config);
GetUserInfoResult info = connection.getUserInfo();
String org = settings.getString(Keys.realm.salesforce.orgId, "0").trim();
if (!org.equals("0")) {
if (!org.equals(info.getOrganizationId())) {
logger.warn("Access attempted by user of an invalid org: " + info.getUserName() + ", org: " + info.getOrganizationName() + "(" + info.getOrganizationId() + ")");
return null;
}
}
logger.info("Authenticated user " + info.getUserName() + " using org " + info.getOrganizationName() + "(" + info.getOrganizationId() + ")");
String simpleUsername = getSimpleUsername(info);
UserModel user = null;
synchronized (this) {
user = userManager.getUserModel(simpleUsername);
if (user == null) {
user = new UserModel(simpleUsername);
}
setCookie(user);
setUserAttributes(user, info);
updateUser(user);
}
return user;
} catch (ConnectionException e) {
logger.error("Failed to authenticate", e);
}
return null;
}
use of com.sforce.ws.ConnectorConfig in project tdi-studio-se by Talend.
the class SforceBasicBulkConnection method init.
private void init() throws Exception {
config = new ConnectorConfig();
setProxyToConnection(config);
// This should only be false when doing debugging.
config.setCompression(needCompression);
// Set this to true to see HTTP requests and responses on stdout
config.setTraceMessage(needTraceMessage);
renewSession();
connection = new BulkConnection(config);
}
Aggregations