Search in sources :

Example 56 with SalesforceException

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

Example 57 with SalesforceException

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

the class BulkApiProcessor method processCreateBatch.

private void processCreateBatch(final Exchange exchange, final AsyncCallback callback) throws SalesforceException {
    String jobId;
    // since request is in the body, use headers or endpoint params
    ContentType contentType = ContentType.fromValue(getParameter(CONTENT_TYPE, exchange, IGNORE_BODY, NOT_OPTIONAL));
    jobId = getParameter(JOB_ID, exchange, IGNORE_BODY, NOT_OPTIONAL);
    InputStream request;
    try {
        request = exchange.getIn().getMandatoryBody(InputStream.class);
    } catch (CamelException e) {
        String msg = "Error preparing batch request: " + e.getMessage();
        throw new SalesforceException(msg, e);
    }
    bulkClient.createBatch(request, jobId, contentType, 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) ContentType(org.apache.camel.component.salesforce.api.dto.bulk.ContentType) CamelException(org.apache.camel.CamelException) InputStream(java.io.InputStream) 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 58 with SalesforceException

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

the class BulkApiProcessor method processCloseJob.

private void processCloseJob(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.closeJob(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)

Example 59 with SalesforceException

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

the class CompositeApiProcessor method processInternal.

<T, R> boolean processInternal(final Class<T> bodyType, final Exchange exchange, final CompositeApiClient.Operation<T, R> clientOperation, final ResponseHandler<R> responseHandler, final AsyncCallback callback) throws SalesforceException {
    final T body;
    final Message in = exchange.getIn();
    try {
        body = in.getMandatoryBody(bodyType);
    } catch (final InvalidPayloadException e) {
        throw new SalesforceException(e);
    }
    clientOperation.submit(body, (response, exception) -> responseHandler.handleResponse(exchange, response, exception, callback));
    return false;
}
Also used : SalesforceException(org.apache.camel.component.salesforce.api.SalesforceException) Message(org.apache.camel.Message) InvalidPayloadException(org.apache.camel.InvalidPayloadException)

Example 60 with SalesforceException

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

the class JsonRestProcessor method getRequestStream.

@Override
protected InputStream getRequestStream(Exchange exchange) throws SalesforceException {
    InputStream request;
    Message in = exchange.getIn();
    request = in.getBody(InputStream.class);
    if (request == null) {
        AbstractDTOBase dto = in.getBody(AbstractDTOBase.class);
        if (dto != null) {
            // marshall the DTO
            request = getRequestStream(dto);
        } else {
            // if all else fails, get body as String
            final String body = in.getBody(String.class);
            if (null == body) {
                String msg = "Unsupported request message body " + (in.getBody() == null ? null : in.getBody().getClass());
                throw new SalesforceException(msg, null);
            } else {
                request = new ByteArrayInputStream(body.getBytes(StandardCharsets.UTF_8));
            }
        }
    }
    return request;
}
Also used : SalesforceException(org.apache.camel.component.salesforce.api.SalesforceException) Message(org.apache.camel.Message) AbstractDTOBase(org.apache.camel.component.salesforce.api.dto.AbstractDTOBase) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream)

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