Search in sources :

Example 46 with SalesforceException

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

the class DefaultAnalyticsApiClient method getReportResults.

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

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

Example 47 with SalesforceException

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

the class DefaultAnalyticsApiClient method getRecentReports.

@Override
public void getRecentReports(final RecentReportsResponseCallback callback) {
    final Request request = getRequest(HttpMethod.GET, reportsUrl());
    doHttpRequest(request, new ClientResponseCallback() {

        @Override
        public void onResponse(InputStream response, SalesforceException ex) {
            List<RecentReport> recentReports = null;
            if (response != null) {
                try {
                    recentReports = unmarshalResponse(response, request, TypeReferences.RECENT_REPORT_LIST_TYPE);
                } catch (SalesforceException e) {
                    ex = e;
                }
            }
            callback.onResponse(recentReports, 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 48 with SalesforceException

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

the class DefaultBulkApiClient method getAllBatches.

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

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

Example 49 with SalesforceException

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

the class DefaultRestClient method search.

@Override
public void search(String soslQuery, ResponseCallback callback) {
    try {
        String encodedQuery = urlEncode(soslQuery);
        final Request get = getRequest(HttpMethod.GET, versionUrl() + "search/?q=" + encodedQuery);
        // requires authorization token
        setAccessToken(get);
        doHttpRequest(get, new DelegatingClientCallback(callback));
    } catch (UnsupportedEncodingException e) {
        String msg = "Unexpected error: " + e.getMessage();
        callback.onResponse(null, new SalesforceException(msg, e));
    }
}
Also used : SalesforceException(org.apache.camel.component.salesforce.api.SalesforceException) Request(org.eclipse.jetty.client.api.Request) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Example 50 with SalesforceException

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

the class DefaultRestClient method createRestException.

@Override
protected SalesforceException createRestException(Response response, InputStream responseContent) {
    // get status code and reason phrase
    final int statusCode = response.getStatus();
    String reason = response.getReason();
    if (reason == null || reason.isEmpty()) {
        reason = HttpStatus.getMessage(statusCode);
    }
    // try parsing response according to format
    try {
        if (responseContent != null && responseContent.available() > 0) {
            final List<String> choices;
            // return list of choices as error message for 300
            if (statusCode == HttpStatus.MULTIPLE_CHOICES_300) {
                if (PayloadFormat.JSON.equals(format)) {
                    choices = objectMapper.readValue(responseContent, TypeReferences.STRING_LIST_TYPE);
                } else {
                    RestChoices restChoices = new RestChoices();
                    xStream.fromXML(responseContent, restChoices);
                    choices = restChoices.getUrls();
                }
                return new SalesforceMultipleChoicesException(reason, statusCode, choices);
            } else {
                final List<RestError> restErrors;
                if (PayloadFormat.JSON.equals(format)) {
                    restErrors = objectMapper.readValue(responseContent, TypeReferences.REST_ERROR_LIST_TYPE);
                } else {
                    RestErrors errors = new RestErrors();
                    xStream.fromXML(responseContent, errors);
                    restErrors = errors.getErrors();
                }
                return new SalesforceException(restErrors, statusCode);
            }
        }
    } catch (IOException e) {
        // log and ignore
        String msg = "Unexpected Error parsing " + format + " error response body + [" + responseContent + "] : " + e.getMessage();
        log.warn(msg, e);
    } catch (RuntimeException e) {
        // log and ignore
        String msg = "Unexpected Error parsing " + format + " error response body + [" + responseContent + "] : " + e.getMessage();
        log.warn(msg, e);
    }
    // just report HTTP status info
    return new SalesforceException("Unexpected error: " + reason + ", with content: " + responseContent, statusCode);
}
Also used : SalesforceException(org.apache.camel.component.salesforce.api.SalesforceException) RestErrors(org.apache.camel.component.salesforce.internal.dto.RestErrors) RestChoices(org.apache.camel.component.salesforce.internal.dto.RestChoices) RestError(org.apache.camel.component.salesforce.api.dto.RestError) SalesforceMultipleChoicesException(org.apache.camel.component.salesforce.api.SalesforceMultipleChoicesException) IOException(java.io.IOException)

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