Search in sources :

Example 1 with BatchInfo

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

the class BulkApiProcessor method processGetResults.

private void processGetResults(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.getResults(jobId, batchId, new BulkApiClient.StreamResponseCallback() {

        @Override
        public void onResponse(InputStream inputStream, SalesforceException ex) {
            // read the result 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 results: " + 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 2 with BatchInfo

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

the class BulkApiProcessor method processGetAllBatches.

private void processGetAllBatches(final Exchange exchange, final AsyncCallback callback) throws SalesforceException {
    JobInfo jobBody;
    String jobId;
    jobBody = exchange.getIn().getBody(JobInfo.class);
    if (jobBody != null) {
        jobId = jobBody.getId();
    } else {
        jobId = getParameter(JOB_ID, exchange, USE_BODY, NOT_OPTIONAL);
    }
    bulkClient.getAllBatches(jobId, new BulkApiClient.BatchInfoListResponseCallback() {

        @Override
        public void onResponse(List<BatchInfo> batchInfoList, SalesforceException ex) {
            processResponse(exchange, batchInfoList, ex, callback);
        }
    });
}
Also used : SalesforceException(org.apache.camel.component.salesforce.api.SalesforceException) JobInfo(org.apache.camel.component.salesforce.api.dto.bulk.JobInfo) 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 3 with BatchInfo

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

the class DefaultBulkApiClient method createBatchQuery.

@Override
public void createBatchQuery(String jobId, String soqlQuery, ContentType jobContentType, final BatchInfoResponseCallback callback) {
    final Request post = getRequest(HttpMethod.POST, batchUrl(jobId, null));
    final byte[] queryBytes;
    try {
        queryBytes = soqlQuery.getBytes(StringUtil.__UTF8);
    } catch (UnsupportedEncodingException e) {
        callback.onResponse(null, new SalesforceException("Unexpected exception: " + e.getMessage(), e));
        return;
    }
    post.content(new BytesContentProvider(queryBytes));
    post.header(HttpHeader.CONTENT_TYPE, getContentType(jobContentType) + ";charset=" + StringUtil.__UTF8);
    // make the call and parse the result
    doHttpRequest(post, new ClientResponseCallback() {

        @Override
        public void onResponse(InputStream response, SalesforceException ex) {
            BatchInfo value = null;
            try {
                value = unmarshalResponse(response, post, BatchInfo.class);
            } catch (SalesforceException e) {
                ex = e;
            }
            callback.onResponse(value, ex);
        }
    });
}
Also used : SalesforceException(org.apache.camel.component.salesforce.api.SalesforceException) InputStream(java.io.InputStream) Request(org.eclipse.jetty.client.api.Request) UnsupportedEncodingException(java.io.UnsupportedEncodingException) BytesContentProvider(org.eclipse.jetty.client.util.BytesContentProvider) BatchInfo(org.apache.camel.component.salesforce.api.dto.bulk.BatchInfo)

Example 4 with BatchInfo

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

the class DefaultBulkApiClient method createBatch.

@Override
public void createBatch(InputStream batchStream, String jobId, ContentType contentTypeEnum, final BatchInfoResponseCallback callback) {
    final Request post = getRequest(HttpMethod.POST, batchUrl(jobId, null));
    post.content(new InputStreamContentProvider(batchStream));
    post.header(HttpHeader.CONTENT_TYPE, getContentType(contentTypeEnum) + ";charset=" + StringUtil.__UTF8);
    // make the call and parse the result
    doHttpRequest(post, new ClientResponseCallback() {

        @Override
        public void onResponse(InputStream response, SalesforceException ex) {
            BatchInfo value = null;
            try {
                value = unmarshalResponse(response, post, BatchInfo.class);
            } catch (SalesforceException e) {
                ex = e;
            }
            callback.onResponse(value, ex);
        }
    });
}
Also used : SalesforceException(org.apache.camel.component.salesforce.api.SalesforceException) InputStream(java.io.InputStream) Request(org.eclipse.jetty.client.api.Request) InputStreamContentProvider(org.eclipse.jetty.client.util.InputStreamContentProvider) BatchInfo(org.apache.camel.component.salesforce.api.dto.bulk.BatchInfo)

Example 5 with BatchInfo

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

the class DefaultBulkApiClient method getBatch.

@Override
public void getBatch(String jobId, String batchId, final BatchInfoResponseCallback callback) {
    final Request get = getRequest(HttpMethod.GET, batchUrl(jobId, batchId));
    // make the call and parse the result
    doHttpRequest(get, new ClientResponseCallback() {

        @Override
        public void onResponse(InputStream response, SalesforceException ex) {
            BatchInfo value = null;
            try {
                value = unmarshalResponse(response, get, BatchInfo.class);
            } catch (SalesforceException e) {
                ex = e;
            }
            callback.onResponse(value, ex);
        }
    });
}
Also used : SalesforceException(org.apache.camel.component.salesforce.api.SalesforceException) InputStream(java.io.InputStream) Request(org.eclipse.jetty.client.api.Request) 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