Search in sources :

Example 1 with ComponentException

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;
}
Also used : DescribeGlobalResult(com.sforce.soap.partner.DescribeGlobalResult) DescribeGlobalSObjectResult(com.sforce.soap.partner.DescribeGlobalSObjectResult) SimpleNamedThing(org.talend.daikon.SimpleNamedThing) ArrayList(java.util.ArrayList) ComponentException(org.talend.components.api.exception.ComponentException) NamedThing(org.talend.daikon.NamedThing) SimpleNamedThing(org.talend.daikon.SimpleNamedThing) ConnectionException(com.sforce.ws.ConnectionException)

Example 2 with ComponentException

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);
    }
}
Also used : ConnectorConfig(com.sforce.ws.ConnectorConfig) ComponentException(org.talend.components.api.exception.ComponentException) BulkConnection(com.sforce.async.BulkConnection) AsyncApiException(com.sforce.async.AsyncApiException)

Example 3 with ComponentException

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);
    }
}
Also used : SandboxedInstance(org.talend.daikon.sandbox.SandboxedInstance) PartnerConnection(com.sforce.soap.partner.PartnerConnection) ComponentException(org.talend.components.api.exception.ComponentException) IOException(java.io.IOException)

Example 4 with ComponentException

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);
    }
}
Also used : AzureStorageTableService(org.talend.components.azurestorage.table.AzureStorageTableService) DynamicTableEntity(com.microsoft.azure.storage.table.DynamicTableEntity) ComponentException(org.talend.components.api.exception.ComponentException) URISyntaxException(java.net.URISyntaxException) InvalidKeyException(java.security.InvalidKeyException) StorageException(com.microsoft.azure.storage.StorageException)

Example 5 with ComponentException

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 = "";
}
Also used : ComponentException(org.talend.components.api.exception.ComponentException) URISyntaxException(java.net.URISyntaxException) InvalidKeyException(java.security.InvalidKeyException) TableBatchOperation(com.microsoft.azure.storage.table.TableBatchOperation) StorageException(com.microsoft.azure.storage.StorageException)

Aggregations

ComponentException (org.talend.components.api.exception.ComponentException)101 URL (java.net.URL)32 MalformedURLException (java.net.MalformedURLException)30 JarRuntimeInfo (org.talend.components.api.component.runtime.JarRuntimeInfo)27 IOException (java.io.IOException)18 ArrayList (java.util.ArrayList)17 InvalidKeyException (java.security.InvalidKeyException)14 Schema (org.apache.avro.Schema)14 URISyntaxException (java.net.URISyntaxException)12 StorageException (com.microsoft.azure.storage.StorageException)11 NamedThing (org.talend.daikon.NamedThing)11 ValidationResult (org.talend.daikon.properties.ValidationResult)10 SandboxedInstance (org.talend.daikon.sandbox.SandboxedInstance)10 IndexedRecord (org.apache.avro.generic.IndexedRecord)8 Test (org.junit.Test)8 SimpleNamedThing (org.talend.daikon.SimpleNamedThing)8 NetSuiteException (org.talend.components.netsuite.client.NetSuiteException)6 GeneralSecurityException (java.security.GeneralSecurityException)5 JDBCSource (org.talend.components.jdbc.runtime.JDBCSource)5 TJDBCInputDefinition (org.talend.components.jdbc.tjdbcinput.TJDBCInputDefinition)5