Search in sources :

Example 16 with SalesforceException

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

the class AbstractRestProcessor method processApexCall.

private void processApexCall(final Exchange exchange, final AsyncCallback callback) throws SalesforceException {
    // HTTP method, URL and query params for APEX call
    final String apexUrl = getApexUrl(exchange);
    String apexMethod = getParameter(APEX_METHOD, exchange, IGNORE_BODY, IS_OPTIONAL);
    // default to GET
    if (apexMethod == null) {
        apexMethod = "GET";
        log.debug("Using HTTP GET method by default for APEX REST call for {}", apexUrl);
    }
    final Map<String, Object> queryParams = getQueryParams(exchange);
    // set response class
    setResponseClass(exchange, getParameter(SOBJECT_NAME, exchange, IGNORE_BODY, IS_OPTIONAL));
    // set request stream
    final Object requestBody = exchange.getIn().getBody();
    final InputStream requestDto = (requestBody != null && !(requestBody instanceof Map)) ? getRequestStream(exchange) : null;
    restClient.apexCall(apexMethod, apexUrl, queryParams, requestDto, new RestClient.ResponseCallback() {

        @Override
        public void onResponse(InputStream response, SalesforceException exception) {
            processResponse(exchange, response, exception, callback);
        }
    });
}
Also used : SalesforceException(org.apache.camel.component.salesforce.api.SalesforceException) InputStream(java.io.InputStream) RestClient(org.apache.camel.component.salesforce.internal.client.RestClient) DefaultRestClient(org.apache.camel.component.salesforce.internal.client.DefaultRestClient) HashMap(java.util.HashMap) Map(java.util.Map)

Example 17 with SalesforceException

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

the class AbstractRestProcessor method getAndClearPropertyValue.

private Object getAndClearPropertyValue(AbstractSObjectBase sObjectBase, String propertyName) throws SalesforceException {
    try {
        // obtain the value using the get method
        Method getMethod = sObjectBase.getClass().getMethod("get" + propertyName);
        Object value = getMethod.invoke(sObjectBase);
        // clear the value with the set method
        Method setMethod = sObjectBase.getClass().getMethod("set" + propertyName, getMethod.getReturnType());
        setMethod.invoke(sObjectBase, new Object[] { null });
        return value;
    } catch (NoSuchMethodException e) {
        throw new SalesforceException(String.format("SObject %s does not have a field %s", sObjectBase.getClass().getSimpleName(), propertyName), e);
    } catch (InvocationTargetException e) {
        throw new SalesforceException(String.format("Error getting/setting value %s.%s", sObjectBase.getClass().getSimpleName(), propertyName), e);
    } catch (IllegalAccessException e) {
        throw new SalesforceException(String.format("Error accessing value %s.%s", sObjectBase.getClass().getSimpleName(), propertyName), e);
    }
}
Also used : SalesforceException(org.apache.camel.component.salesforce.api.SalesforceException) Method(java.lang.reflect.Method) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 18 with SalesforceException

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

the class AbstractRestProcessor method processDeleteSobjectWithId.

private void processDeleteSobjectWithId(final Exchange exchange, final AsyncCallback callback) throws SalesforceException {
    String sObjectName;
    final String sObjectExtIdName = getParameter(SOBJECT_EXT_ID_NAME, exchange, IGNORE_BODY, NOT_OPTIONAL);
    // determine parameters from input AbstractSObject
    Object oldValue = null;
    final AbstractSObjectBase sObjectBase = exchange.getIn().getBody(AbstractSObjectBase.class);
    String sObjectExtIdValue;
    if (sObjectBase != null) {
        sObjectName = sObjectBase.getClass().getSimpleName();
        oldValue = getAndClearPropertyValue(sObjectBase, sObjectExtIdName);
        sObjectExtIdValue = oldValue.toString();
    } else {
        sObjectName = getParameter(SOBJECT_NAME, exchange, IGNORE_BODY, NOT_OPTIONAL);
        sObjectExtIdValue = getParameter(SOBJECT_EXT_ID_VALUE, exchange, USE_BODY, NOT_OPTIONAL);
    }
    final Object finalOldValue = oldValue;
    restClient.deleteSObjectWithId(sObjectName, sObjectExtIdName, sObjectExtIdValue, new RestClient.ResponseCallback() {

        @Override
        public void onResponse(InputStream response, SalesforceException exception) {
            processResponse(exchange, response, exception, callback);
            restoreFields(exchange, sObjectBase, null, sObjectExtIdName, finalOldValue);
        }
    });
}
Also used : SalesforceException(org.apache.camel.component.salesforce.api.SalesforceException) AbstractSObjectBase(org.apache.camel.component.salesforce.api.dto.AbstractSObjectBase) InputStream(java.io.InputStream) RestClient(org.apache.camel.component.salesforce.internal.client.RestClient) DefaultRestClient(org.apache.camel.component.salesforce.internal.client.DefaultRestClient)

Example 19 with SalesforceException

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

the class AnalyticsApiProcessor method processExecuteAsyncReport.

private void processExecuteAsyncReport(final Exchange exchange, final AsyncCallback callback) throws SalesforceException {
    String reportId;
    final Boolean includeDetails = getParameter(INCLUDE_DETAILS, exchange, IGNORE_BODY, IS_OPTIONAL, Boolean.class);
    // try getting report metadata from body first
    ReportMetadata reportMetadata = exchange.getIn().getBody(ReportMetadata.class);
    if (reportMetadata != null) {
        reportId = reportMetadata.getId();
        if (reportId == null) {
            reportId = getParameter(REPORT_ID, exchange, IGNORE_BODY, NOT_OPTIONAL);
        }
    } else {
        reportId = getParameter(REPORT_ID, exchange, USE_BODY, NOT_OPTIONAL);
        reportMetadata = getParameter(REPORT_METADATA, exchange, IGNORE_BODY, IS_OPTIONAL, ReportMetadata.class);
    }
    analyticsClient.executeAsyncReport(reportId, includeDetails, reportMetadata, new AnalyticsApiClient.ReportInstanceResponseCallback() {

        @Override
        public void onResponse(ReportInstance reportInstance, SalesforceException ex) {
            processResponse(exchange, reportInstance, ex, callback);
        }
    });
}
Also used : SalesforceException(org.apache.camel.component.salesforce.api.SalesforceException) AnalyticsApiClient(org.apache.camel.component.salesforce.internal.client.AnalyticsApiClient) DefaultAnalyticsApiClient(org.apache.camel.component.salesforce.internal.client.DefaultAnalyticsApiClient) ReportInstance(org.apache.camel.component.salesforce.api.dto.analytics.reports.ReportInstance) ReportMetadata(org.apache.camel.component.salesforce.api.dto.analytics.reports.ReportMetadata)

Example 20 with SalesforceException

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

the class AnalyticsApiProcessor method processExecuteSyncReport.

private void processExecuteSyncReport(final Exchange exchange, final AsyncCallback callback) throws SalesforceException {
    String reportId;
    final Boolean includeDetails = getParameter(INCLUDE_DETAILS, exchange, IGNORE_BODY, IS_OPTIONAL, Boolean.class);
    // try getting report metadata from body first
    ReportMetadata reportMetadata = exchange.getIn().getBody(ReportMetadata.class);
    if (reportMetadata != null) {
        reportId = reportMetadata.getId();
        if (reportId == null) {
            reportId = getParameter(REPORT_ID, exchange, IGNORE_BODY, NOT_OPTIONAL);
        }
    } else {
        reportId = getParameter(REPORT_ID, exchange, USE_BODY, NOT_OPTIONAL);
        reportMetadata = getParameter(REPORT_METADATA, exchange, IGNORE_BODY, IS_OPTIONAL, ReportMetadata.class);
    }
    analyticsClient.executeSyncReport(reportId, includeDetails, reportMetadata, new AnalyticsApiClient.ReportResultsResponseCallback() {

        @Override
        public void onResponse(AbstractReportResultsBase reportResults, SalesforceException ex) {
            processResponse(exchange, reportResults, ex, callback);
        }
    });
}
Also used : SalesforceException(org.apache.camel.component.salesforce.api.SalesforceException) AnalyticsApiClient(org.apache.camel.component.salesforce.internal.client.AnalyticsApiClient) DefaultAnalyticsApiClient(org.apache.camel.component.salesforce.internal.client.DefaultAnalyticsApiClient) AbstractReportResultsBase(org.apache.camel.component.salesforce.api.dto.analytics.reports.AbstractReportResultsBase) ReportMetadata(org.apache.camel.component.salesforce.api.dto.analytics.reports.ReportMetadata)

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