Search in sources :

Example 11 with BatchInfo

use of org.apache.camel.component.salesforce.api.dto.bulk.BatchInfo in project camel by apache.

the class BulkApiProcessor method processGetQueryResult.

private void processGetQueryResult(final Exchange exchange, final AsyncCallback callback) throws SalesforceException {
    String jobId;
    BatchInfo batchBody;
    String batchId;
    batchBody = exchange.getIn().getBody(BatchInfo.class);
    String resultId;
    if (batchBody != null) {
        jobId = batchBody.getJobId();
        batchId = batchBody.getId();
        resultId = getParameter(RESULT_ID, exchange, IGNORE_BODY, NOT_OPTIONAL);
    } else {
        jobId = getParameter(JOB_ID, exchange, IGNORE_BODY, NOT_OPTIONAL);
        batchId = getParameter(BATCH_ID, exchange, IGNORE_BODY, NOT_OPTIONAL);
        resultId = getParameter(RESULT_ID, exchange, USE_BODY, NOT_OPTIONAL);
    }
    bulkClient.getQueryResult(jobId, batchId, resultId, new BulkApiClient.StreamResponseCallback() {

        @Override
        public void onResponse(InputStream inputStream, SalesforceException ex) {
            StreamCache body = null;
            if (inputStream != null) {
                // ensures the connection is read
                try {
                    body = StreamCacheConverter.convertToStreamCache(inputStream, exchange);
                } catch (IOException e) {
                    String msg = "Error retrieving query result: " + e.getMessage();
                    ex = new SalesforceException(msg, e);
                } finally {
                    // close the input stream to release the Http connection
                    try {
                        inputStream.close();
                    } catch (IOException e) {
                    // ignore
                    }
                }
            }
            processResponse(exchange, body, ex, callback);
        }
    });
}
Also used : SalesforceException(org.apache.camel.component.salesforce.api.SalesforceException) StreamCache(org.apache.camel.StreamCache) InputStream(java.io.InputStream) IOException(java.io.IOException) DefaultBulkApiClient(org.apache.camel.component.salesforce.internal.client.DefaultBulkApiClient) BulkApiClient(org.apache.camel.component.salesforce.internal.client.BulkApiClient) BatchInfo(org.apache.camel.component.salesforce.api.dto.bulk.BatchInfo)

Example 12 with BatchInfo

use of org.apache.camel.component.salesforce.api.dto.bulk.BatchInfo in project camel by apache.

the class BulkApiProcessor method processGetRequest.

private void processGetRequest(final Exchange exchange, final AsyncCallback callback) throws SalesforceException {
    String jobId;
    BatchInfo batchBody;
    String batchId;
    batchBody = exchange.getIn().getBody(BatchInfo.class);
    if (batchBody != null) {
        jobId = batchBody.getJobId();
        batchId = batchBody.getId();
    } else {
        jobId = getParameter(JOB_ID, exchange, IGNORE_BODY, NOT_OPTIONAL);
        batchId = getParameter(BATCH_ID, exchange, USE_BODY, NOT_OPTIONAL);
    }
    bulkClient.getRequest(jobId, batchId, new BulkApiClient.StreamResponseCallback() {

        @Override
        public void onResponse(InputStream inputStream, SalesforceException ex) {
            // read the request stream into a StreamCache temp file
            // ensures the connection is read
            StreamCache body = null;
            if (inputStream != null) {
                try {
                    body = StreamCacheConverter.convertToStreamCache(inputStream, exchange);
                } catch (IOException e) {
                    String msg = "Error retrieving batch request: " + e.getMessage();
                    ex = new SalesforceException(msg, e);
                } finally {
                    // close the input stream to release the Http connection
                    try {
                        inputStream.close();
                    } catch (IOException ignore) {
                    }
                }
            }
            processResponse(exchange, body, ex, callback);
        }
    });
}
Also used : SalesforceException(org.apache.camel.component.salesforce.api.SalesforceException) StreamCache(org.apache.camel.StreamCache) InputStream(java.io.InputStream) IOException(java.io.IOException) DefaultBulkApiClient(org.apache.camel.component.salesforce.internal.client.DefaultBulkApiClient) BulkApiClient(org.apache.camel.component.salesforce.internal.client.BulkApiClient) BatchInfo(org.apache.camel.component.salesforce.api.dto.bulk.BatchInfo)

Example 13 with BatchInfo

use of org.apache.camel.component.salesforce.api.dto.bulk.BatchInfo in project camel by apache.

the class BulkApiProcessor method processGetBatch.

private void processGetBatch(final Exchange exchange, final AsyncCallback callback) throws SalesforceException {
    String jobId;
    BatchInfo batchBody = exchange.getIn().getBody(BatchInfo.class);
    String batchId;
    if (batchBody != null) {
        jobId = batchBody.getJobId();
        batchId = batchBody.getId();
    } else {
        jobId = getParameter(JOB_ID, exchange, IGNORE_BODY, NOT_OPTIONAL);
        batchId = getParameter(BATCH_ID, exchange, USE_BODY, NOT_OPTIONAL);
    }
    bulkClient.getBatch(jobId, batchId, new BulkApiClient.BatchInfoResponseCallback() {

        @Override
        public void onResponse(BatchInfo batchInfo, SalesforceException ex) {
            processResponse(exchange, batchInfo, ex, callback);
        }
    });
}
Also used : SalesforceException(org.apache.camel.component.salesforce.api.SalesforceException) DefaultBulkApiClient(org.apache.camel.component.salesforce.internal.client.DefaultBulkApiClient) BulkApiClient(org.apache.camel.component.salesforce.internal.client.BulkApiClient) BatchInfo(org.apache.camel.component.salesforce.api.dto.bulk.BatchInfo)

Aggregations

BatchInfo (org.apache.camel.component.salesforce.api.dto.bulk.BatchInfo)13 SalesforceException (org.apache.camel.component.salesforce.api.SalesforceException)11 InputStream (java.io.InputStream)9 BulkApiClient (org.apache.camel.component.salesforce.internal.client.BulkApiClient)8 DefaultBulkApiClient (org.apache.camel.component.salesforce.internal.client.DefaultBulkApiClient)8 JobInfo (org.apache.camel.component.salesforce.api.dto.bulk.JobInfo)4 IOException (java.io.IOException)3 StreamCache (org.apache.camel.StreamCache)3 Request (org.eclipse.jetty.client.api.Request)3 ContentType (org.apache.camel.component.salesforce.api.dto.bulk.ContentType)2 Merchandise__c (org.apache.camel.component.salesforce.dto.generated.Merchandise__c)2 Theory (org.junit.experimental.theories.Theory)2 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 HashMap (java.util.HashMap)1 CamelException (org.apache.camel.CamelException)1 BytesContentProvider (org.eclipse.jetty.client.util.BytesContentProvider)1 InputStreamContentProvider (org.eclipse.jetty.client.util.InputStreamContentProvider)1