use of org.talend.components.salesforce.runtime.common.ConnectionHolder in project components by Talend.
the class SalesforceSourceOrSinkTestIT method prepareAndGetConnectionHolder.
private void prepareAndGetConnectionHolder(boolean isBulk) throws Exception {
final SalesforceConnectionProperties connectionProperties = setupProps(null, false);
connectionProperties.bulkConnection.setValue(isBulk);
RuntimeContainer container = new DefaultComponentRuntimeContainerImpl() {
@Override
public String getCurrentComponentId() {
return connectionProperties.getName();
}
};
SalesforceSourceOrSink sourceOrSink = new SalesforceSourceOrSink();
sourceOrSink.initialize(container, connectionProperties);
// Creating and saving PartnerConnection + BulkConnection(holder) inside container.
sourceOrSink.validate(container);
PartnerConnection partnerConnection = (PartnerConnection) container.getComponentData(connectionProperties.getName(), SalesforceSourceOrSink.KEY_CONNECTION);
TSalesforceInputProperties inputProperties = new TSalesforceInputProperties("input");
inputProperties.connection.referencedComponent.componentInstanceId.setValue(connectionProperties.getName());
sourceOrSink.initialize(container, inputProperties);
ConnectionHolder actualHolder = sourceOrSink.connect(container);
Assert.assertEquals(partnerConnection, actualHolder.connection);
if (isBulk) {
Assert.assertNotNull(actualHolder.bulkConnection);
} else {
// Check if bulk connection was not chosen but created.
Assert.assertNull(actualHolder.bulkConnection);
}
}
use of org.talend.components.salesforce.runtime.common.ConnectionHolder in project components by Talend.
the class SalesforceSessionReuseTestIT method invalidSession.
protected void invalidSession(SalesforceConnectionProperties props, String sessionId) throws Exception {
SalesforceSourceOrSink sourceOrSink = new SalesforceSourceOrSink();
sourceOrSink.initialize(null, props);
ConnectionHolder connectionHolder = sourceOrSink.connect(null);
assertNotNull(connectionHolder.connection);
if (sessionId != null) {
connectionHolder.connection.invalidateSessions(new String[] { sessionId });
}
connectionHolder.connection.logout();
LOGGER.debug("session \"" + connectionHolder.connection.getConfig().getSessionId() + "\" invalided!");
}
use of org.talend.components.salesforce.runtime.common.ConnectionHolder 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 org.talend.components.salesforce.runtime.common.ConnectionHolder in project components by Talend.
the class SalesforceWriter method open.
@Override
public void open(String uId) throws IOException {
this.uId = uId;
ConnectionHolder ch = sink.connect(container);
connection = ch.connection;
if (ch.bulkConnection != null) {
LOGGER.info(MESSAGES.getMessage("info.bulkConnectionUsage"));
}
if (null == mainSchema) {
mainSchema = sprops.module.main.schema.getValue();
moduleSchema = sink.getSchema(connection, sprops.module.moduleName.getStringValue());
if (AvroUtils.isIncludeAllFields(mainSchema)) {
mainSchema = moduleSchema;
}
// else schema is fully specified
}
upsertKeyColumn = sprops.upsertKeyColumn.getStringValue();
if (!StringUtils.isEmpty(sprops.logFileName.getValue())) {
logWriter = new BufferedWriter(new FileWriter(sprops.logFileName.getValue()));
}
}
use of org.talend.components.salesforce.runtime.common.ConnectionHolder in project components by Talend.
the class SalesforceBulkQueryReader method start.
@Override
public boolean start() throws IOException {
try {
if (bulkRuntime == null) {
ConnectionHolder connectionHolder = ((SalesforceDataprepSource) getCurrentSource()).getConnectionHolder();
bulkRuntime = new SalesforceBulkRuntime(connectionHolder.bulkConnection);
}
executeSalesforceBulkQuery();
bulkResultSet = bulkRuntime.getQueryResultSet(bulkRuntime.nextResultId());
currentRecord = bulkResultSet.next();
boolean start = currentRecord != null;
if (start) {
dataCount++;
}
return start;
} catch (ConnectionException | AsyncApiException e) {
// Wrap the exception in an IOException.
throw new IOException(e);
}
}
Aggregations