use of org.talend.components.api.exception.ComponentException in project components by Talend.
the class SalesforceRuntimeCommon method getSchemaNames.
public static List<NamedThing> getSchemaNames(PartnerConnection connection) throws IOException {
List<NamedThing> returnList = new ArrayList<>();
DescribeGlobalResult result = null;
try {
result = connection.describeGlobal();
} catch (ConnectionException e) {
throw new ComponentException(e);
}
DescribeGlobalSObjectResult[] objects = result.getSobjects();
for (DescribeGlobalSObjectResult obj : objects) {
LOG.debug("module label: " + obj.getLabel() + " name: " + obj.getName());
returnList.add(new SimpleNamedThing(obj.getName(), obj.getLabel()));
}
return returnList;
}
use of org.talend.components.api.exception.ComponentException 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 org.talend.components.api.exception.ComponentException in project components by Talend.
the class SalesforceSourceOrSink method getSchema.
public static Schema getSchema(RuntimeContainer container, SalesforceProvideConnectionProperties properties, String module) throws IOException {
ClassLoader classLoader = SalesforceSourceOrSink.class.getClassLoader();
// org.talend.components.salesforce.runtime.common.SalesforceRuntimeCommon.enableTLSv11AndTLSv12ForJava7()
try (SandboxedInstance sandboxedInstance = RuntimeUtil.createRuntimeClassWithCurrentJVMProperties(getStaticRuntimeInfo(), classLoader)) {
SalesforceSourceOrSink ss = (SalesforceSourceOrSink) sandboxedInstance.getInstance();
ss.initialize(null, (ComponentProperties) properties);
PartnerConnection connection = null;
try {
connection = ss.connect(container).connection;
} catch (IOException ex) {
throw new ComponentException(SalesforceRuntimeCommon.exceptionToValidationResult(ex));
}
return ss.getSchema(connection, module);
}
}
use of org.talend.components.api.exception.ComponentException in project components by Talend.
the class AzureStorageTableSourceOrSink method getEndpointSchema.
@Override
public Schema getEndpointSchema(RuntimeContainer container, String schemaName) throws IOException {
try {
AzureStorageTableService tableService = new AzureStorageTableService(getAzureConnection(container));
TableQuery<DynamicTableEntity> partitionQuery;
partitionQuery = TableQuery.from(DynamicTableEntity.class).take(1);
Iterable<DynamicTableEntity> entities = tableService.executeQuery(schemaName, partitionQuery);
if (entities.iterator().hasNext()) {
DynamicTableEntity result = entities.iterator().next();
return AzureStorageAvroRegistry.get().inferSchema(result);
} else {
return null;
}
} catch (InvalidKeyException | URISyntaxException | StorageException e) {
LOGGER.error(e.getLocalizedMessage());
throw new ComponentException(e);
}
}
use of org.talend.components.api.exception.ComponentException in project components by Talend.
the class AzureStorageTableWriter method processBatch.
private void processBatch() throws IOException {
TableBatchOperation batch = new TableBatchOperation();
batch.addAll(batchOperations);
//
try {
tableservice.executeOperation(tableName, batch);
handleSuccess(null, batchOperationsCount);
} catch (StorageException e) {
LOGGER.error(i18nMessages.getMessage("error.ProcessBatch", actionData, e.getLocalizedMessage()));
handleReject(null, e, batchOperationsCount);
if (dieOnError) {
throw new ComponentException(e);
}
} catch (URISyntaxException | InvalidKeyException e) {
// connection problem so next operation will also fail, we stop the process
throw new ComponentException(e);
}
// reset operations, count and marker
batchOperations.clear();
batchRecords.clear();
batchOperationsCount = 0;
latestPartitionKey = "";
}
Aggregations