Search in sources :

Example 71 with SalesforceException

use of org.apache.camel.component.salesforce.api.SalesforceException 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 72 with SalesforceException

use of org.apache.camel.component.salesforce.api.SalesforceException 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 73 with SalesforceException

use of org.apache.camel.component.salesforce.api.SalesforceException 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)

Example 74 with SalesforceException

use of org.apache.camel.component.salesforce.api.SalesforceException in project camel by apache.

the class BulkApiProcessor method processCreateJob.

private void processCreateJob(final Exchange exchange, final AsyncCallback callback) throws InvalidPayloadException {
    JobInfo jobBody = exchange.getIn().getMandatoryBody(JobInfo.class);
    bulkClient.createJob(jobBody, new BulkApiClient.JobInfoResponseCallback() {

        @Override
        public void onResponse(JobInfo jobInfo, SalesforceException ex) {
            processResponse(exchange, jobInfo, 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)

Example 75 with SalesforceException

use of org.apache.camel.component.salesforce.api.SalesforceException in project camel by apache.

the class BulkApiProcessor method processAbortJob.

private void processAbortJob(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.abortJob(jobId, new BulkApiClient.JobInfoResponseCallback() {

        @Override
        public void onResponse(JobInfo jobInfo, SalesforceException ex) {
            processResponse(exchange, jobInfo, 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)

Aggregations

SalesforceException (org.apache.camel.component.salesforce.api.SalesforceException)79 InputStream (java.io.InputStream)35 Request (org.eclipse.jetty.client.api.Request)25 BulkApiClient (org.apache.camel.component.salesforce.internal.client.BulkApiClient)12 DefaultBulkApiClient (org.apache.camel.component.salesforce.internal.client.DefaultBulkApiClient)12 DefaultRestClient (org.apache.camel.component.salesforce.internal.client.DefaultRestClient)12 IOException (java.io.IOException)11 BatchInfo (org.apache.camel.component.salesforce.api.dto.bulk.BatchInfo)11 RestClient (org.apache.camel.component.salesforce.internal.client.RestClient)11 UnsupportedEncodingException (java.io.UnsupportedEncodingException)10 JobInfo (org.apache.camel.component.salesforce.api.dto.bulk.JobInfo)10 AbstractSObjectBase (org.apache.camel.component.salesforce.api.dto.AbstractSObjectBase)9 HashMap (java.util.HashMap)7 CamelException (org.apache.camel.CamelException)7 Message (org.apache.camel.Message)7 ByteArrayInputStream (java.io.ByteArrayInputStream)5 List (java.util.List)5 Map (java.util.Map)5 CreateSObjectResult (org.apache.camel.component.salesforce.api.dto.CreateSObjectResult)3 SyncResponseCallback (org.apache.camel.component.salesforce.internal.client.SyncResponseCallback)3