Search in sources :

Example 26 with SalesforceException

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

the class DefaultAnalyticsApiClient method getReportInstances.

@Override
public void getReportInstances(String reportId, final ReportInstanceListResponseCallback callback) {
    final Request request = getRequest(HttpMethod.GET, reportInstancesUrl(reportId));
    doHttpRequest(request, new ClientResponseCallback() {

        @Override
        public void onResponse(InputStream response, SalesforceException ex) {
            List<ReportInstance> reportInstances = null;
            if (response != null) {
                try {
                    reportInstances = unmarshalResponse(response, request, TypeReferences.REPORT_INSTANCE_LIST_TYPE);
                } catch (SalesforceException e) {
                    ex = e;
                }
            }
            callback.onResponse(reportInstances, ex);
        }
    });
}
Also used : SalesforceException(org.apache.camel.component.salesforce.api.SalesforceException) InputStream(java.io.InputStream) Request(org.eclipse.jetty.client.api.Request) List(java.util.List)

Example 27 with SalesforceException

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

the class DefaultAnalyticsApiClient method executeAsyncReport.

@Override
public void executeAsyncReport(String reportId, Boolean includeDetails, ReportMetadata reportMetadata, final ReportInstanceResponseCallback callback) {
    final Request request = getRequest(HttpMethod.POST, reportInstancesUrl(reportId, includeDetails));
    // set POST data
    if (reportMetadata != null) {
        try {
            // wrap reportMetadata in a map
            final HashMap<String, Object> input = new HashMap<String, Object>();
            input.put("reportMetadata", reportMetadata);
            marshalRequest(input, request);
        } catch (SalesforceException e) {
            callback.onResponse(null, e);
            return;
        }
    }
    doHttpRequest(request, new ClientResponseCallback() {

        @Override
        public void onResponse(InputStream response, SalesforceException ex) {
            ReportInstance reportInstance = null;
            try {
                reportInstance = unmarshalResponse(response, request, ReportInstance.class);
            } catch (SalesforceException e) {
                ex = e;
            }
            callback.onResponse(reportInstance, ex);
        }
    });
}
Also used : SalesforceException(org.apache.camel.component.salesforce.api.SalesforceException) HashMap(java.util.HashMap) InputStream(java.io.InputStream) Request(org.eclipse.jetty.client.api.Request) ReportInstance(org.apache.camel.component.salesforce.api.dto.analytics.reports.ReportInstance)

Example 28 with SalesforceException

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

the class DefaultBulkApiClient method getQueryResult.

@Override
public void getQueryResult(String jobId, String batchId, String resultId, final StreamResponseCallback callback) {
    final Request get = getRequest(HttpMethod.GET, batchResultUrl(jobId, batchId, resultId));
    // make the call and parse 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 29 with SalesforceException

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

the class DefaultBulkApiClient method marshalRequest.

private void marshalRequest(Object input, Request request, String contentType) throws SalesforceException {
    try {
        Marshaller marshaller = context.createMarshaller();
        ByteArrayOutputStream byteStream = new ByteArrayOutputStream();
        marshaller.marshal(input, byteStream);
        request.content(new BytesContentProvider(contentType, byteStream.toByteArray()));
    } catch (JAXBException e) {
        throw new SalesforceException(String.format("Error marshaling request for {%s:%s} : %s", request.getMethod(), request.getURI(), e.getMessage()), e);
    } catch (IllegalArgumentException e) {
        throw new SalesforceException(String.format("Error marshaling request for {%s:%s} : %s", request.getMethod(), request.getURI(), e.getMessage()), e);
    }
}
Also used : SalesforceException(org.apache.camel.component.salesforce.api.SalesforceException) Marshaller(javax.xml.bind.Marshaller) JAXBException(javax.xml.bind.JAXBException) ByteArrayOutputStream(java.io.ByteArrayOutputStream) BytesContentProvider(org.eclipse.jetty.client.util.BytesContentProvider)

Example 30 with SalesforceException

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

the class DefaultBulkApiClient method getJob.

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

        @Override
        public void onResponse(InputStream response, SalesforceException ex) {
            JobInfo value = null;
            try {
                value = unmarshalResponse(response, get, 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