Search in sources :

Example 31 with SalesforceException

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

the class DefaultBulkApiClient method getQueryResultIds.

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

        @Override
        public void onResponse(InputStream response, SalesforceException ex) {
            QueryResultList value = null;
            try {
                value = unmarshalResponse(response, get, QueryResultList.class);
            } catch (SalesforceException e) {
                ex = e;
            }
            callback.onResponse(value != null ? Collections.unmodifiableList(value.getResult()) : null, ex);
        }
    });
}
Also used : SalesforceException(org.apache.camel.component.salesforce.api.SalesforceException) QueryResultList(org.apache.camel.component.salesforce.api.dto.bulk.QueryResultList) InputStream(java.io.InputStream) Request(org.eclipse.jetty.client.api.Request)

Example 32 with SalesforceException

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

the class DefaultBulkApiClient method unmarshalResponse.

private <T> T unmarshalResponse(InputStream response, Request request, Class<T> resultClass) throws SalesforceException {
    try {
        Unmarshaller unmarshaller = context.createUnmarshaller();
        JAXBElement<T> result = unmarshaller.unmarshal(new StreamSource(response), resultClass);
        return result.getValue();
    } catch (JAXBException e) {
        throw new SalesforceException(String.format("Error unmarshaling response {%s:%s} : %s", request.getMethod(), request.getURI(), e.getMessage()), e);
    } catch (IllegalArgumentException e) {
        throw new SalesforceException(String.format("Error unmarshaling response for {%s:%s} : %s", request.getMethod(), request.getURI(), e.getMessage()), e);
    }
}
Also used : SalesforceException(org.apache.camel.component.salesforce.api.SalesforceException) StreamSource(javax.xml.transform.stream.StreamSource) JAXBException(javax.xml.bind.JAXBException) Unmarshaller(javax.xml.bind.Unmarshaller)

Example 33 with SalesforceException

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

the class DefaultBulkApiClient method abortJob.

@Override
public void abortJob(String jobId, final JobInfoResponseCallback callback) {
    final JobInfo request = new JobInfo();
    request.setState(JobStateEnum.ABORTED);
    final Request post = getRequest(HttpMethod.POST, jobUrl(jobId));
    try {
        marshalRequest(objectFactory.createJobInfo(request), post, APPLICATION_XML_UTF8);
    } catch (SalesforceException e) {
        callback.onResponse(null, e);
        return;
    }
    // make the call and parse the result
    doHttpRequest(post, new ClientResponseCallback() {

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

Example 34 with SalesforceException

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

the class DefaultBulkApiClient method getResults.

@Override
public void getResults(String jobId, String batchId, final StreamResponseCallback callback) {
    final Request get = getRequest(HttpMethod.GET, batchResultUrl(jobId, batchId, null));
    // make the call and return the result
    doHttpRequest(get, new ClientResponseCallback() {

        @Override
        public void onResponse(InputStream response, SalesforceException ex) {
            callback.onResponse(response, ex);
        }
    });
}
Also used : SalesforceException(org.apache.camel.component.salesforce.api.SalesforceException) InputStream(java.io.InputStream) Request(org.eclipse.jetty.client.api.Request)

Example 35 with SalesforceException

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

the class DefaultBulkApiClient method createJob.

@Override
public void createJob(JobInfo request, final JobInfoResponseCallback callback) {
    // clear system fields if set
    sanitizeJobRequest(request);
    final Request post = getRequest(HttpMethod.POST, jobUrl(null));
    try {
        marshalRequest(objectFactory.createJobInfo(request), post, APPLICATION_XML_UTF8);
    } catch (SalesforceException e) {
        callback.onResponse(null, e);
        return;
    }
    // make the call and parse the result in callback
    doHttpRequest(post, new ClientResponseCallback() {

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

Aggregations

SalesforceException (org.apache.camel.component.salesforce.api.SalesforceException)77 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 CamelException (org.apache.camel.CamelException)7 HashMap (java.util.HashMap)6 Message (org.apache.camel.Message)6 ByteArrayInputStream (java.io.ByteArrayInputStream)5 List (java.util.List)4 InvocationTargetException (java.lang.reflect.InvocationTargetException)3 Method (java.lang.reflect.Method)3 Map (java.util.Map)3