Search in sources :

Example 66 with SalesforceException

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

the class AbstractRestProcessor method processCreateSobject.

private void processCreateSobject(final Exchange exchange, final AsyncCallback callback) throws SalesforceException {
    String sObjectName;
    // determine parameters from input AbstractSObject
    AbstractSObjectBase sObjectBase = exchange.getIn().getBody(AbstractSObjectBase.class);
    if (sObjectBase != null) {
        sObjectName = sObjectBase.getClass().getSimpleName();
    } else {
        sObjectName = getParameter(SOBJECT_NAME, exchange, IGNORE_BODY, NOT_OPTIONAL);
    }
    restClient.createSObject(sObjectName, getRequestStream(exchange), 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) 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 67 with SalesforceException

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

the class AbstractRestProcessor method processGetSobject.

private void processGetSobject(final Exchange exchange, final AsyncCallback callback) throws SalesforceException {
    String sObjectName;
    String sObjectIdValue;
    // determine parameters from input AbstractSObject
    final AbstractSObjectBase sObjectBase = exchange.getIn().getBody(AbstractSObjectBase.class);
    if (sObjectBase != null) {
        sObjectName = sObjectBase.getClass().getSimpleName();
        sObjectIdValue = sObjectBase.getId();
    } else {
        sObjectName = getParameter(SOBJECT_NAME, exchange, IGNORE_BODY, NOT_OPTIONAL);
        sObjectIdValue = getParameter(SOBJECT_ID, exchange, USE_BODY, NOT_OPTIONAL);
    }
    final String sObjectId = sObjectIdValue;
    // use sObject name to load class
    setResponseClass(exchange, sObjectName);
    // get optional field list
    String fieldsValue = getParameter(SOBJECT_FIELDS, exchange, IGNORE_BODY, IS_OPTIONAL);
    String[] fields = null;
    if (fieldsValue != null) {
        fields = fieldsValue.split(",");
    }
    restClient.getSObject(sObjectName, sObjectId, fields, new RestClient.ResponseCallback() {

        @Override
        public void onResponse(InputStream response, SalesforceException exception) {
            processResponse(exchange, response, exception, callback);
            restoreFields(exchange, sObjectBase, sObjectId, null, null);
        }
    });
}
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 68 with SalesforceException

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

the class AbstractSalesforceProcessor method getParameter.

/**
     * Gets value for a parameter from header, endpoint config, or exchange body (optional).
     *
     * @param exchange          exchange to inspect
     * @param convertInBody     converts In body to parameterClass value if true
     * @param propName          name of property
     * @param optional          if {@code true} returns null, otherwise throws RestException
     * @param parameterClass    parameter type
     * @return value of property, or {@code null} for optional parameters if not found.
     * @throws org.apache.camel.component.salesforce.api.SalesforceException
     *          if the property can't be found or on conversion errors.
     */
protected final <T> T getParameter(String propName, Exchange exchange, boolean convertInBody, boolean optional, Class<T> parameterClass) throws SalesforceException {
    final Message in = exchange.getIn();
    T propValue = in.getHeader(propName, parameterClass);
    if (propValue == null) {
        // check if type conversion failed
        if (in.getHeader(propName) != null) {
            throw new IllegalArgumentException("Header " + propName + " could not be converted to type " + parameterClass.getName());
        }
        final Object value = endpointConfigMap.get(propName);
        if (value == null || parameterClass.isInstance(value)) {
            propValue = parameterClass.cast(value);
        } else {
            try {
                propValue = exchange.getContext().getTypeConverter().mandatoryConvertTo(parameterClass, value);
            } catch (NoTypeConversionAvailableException e) {
                throw new SalesforceException(e);
            }
        }
    }
    propValue = (propValue == null && convertInBody) ? in.getBody(parameterClass) : propValue;
    // error if property was not set
    if (propValue == null && !optional) {
        String msg = "Missing property " + propName + (convertInBody ? ", message body could not be converted to type " + parameterClass.getName() : "");
        throw new SalesforceException(msg, null);
    }
    return propValue;
}
Also used : SalesforceException(org.apache.camel.component.salesforce.api.SalesforceException) Message(org.apache.camel.Message) NoTypeConversionAvailableException(org.apache.camel.NoTypeConversionAvailableException)

Example 69 with SalesforceException

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

the class BulkApiProcessor method processCreateBatchQuery.

private void processCreateBatchQuery(final Exchange exchange, final AsyncCallback callback) throws SalesforceException {
    JobInfo jobBody;
    String jobId;
    ContentType contentType;
    jobBody = exchange.getIn().getBody(JobInfo.class);
    String soqlQuery;
    if (jobBody != null) {
        jobId = jobBody.getId();
        contentType = jobBody.getContentType();
        // use SOQL query from header or endpoint config
        soqlQuery = getParameter(SOBJECT_QUERY, exchange, IGNORE_BODY, NOT_OPTIONAL);
    } else {
        jobId = getParameter(JOB_ID, exchange, IGNORE_BODY, NOT_OPTIONAL);
        contentType = ContentType.fromValue(getParameter(CONTENT_TYPE, exchange, IGNORE_BODY, NOT_OPTIONAL));
        // reuse SOBJECT_QUERY property
        soqlQuery = getParameter(SOBJECT_QUERY, exchange, USE_BODY, NOT_OPTIONAL);
    }
    bulkClient.createBatchQuery(jobId, soqlQuery, 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) 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) BatchInfo(org.apache.camel.component.salesforce.api.dto.bulk.BatchInfo)

Example 70 with SalesforceException

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

the class BulkApiProcessor method processGetQueryResultIds.

private void processGetQueryResultIds(final Exchange exchange, final AsyncCallback callback) throws SalesforceException {
    String jobId;
    BatchInfo batchBody;
    String batchId;
    batchBody = exchange.getIn().getBody(BatchInfo.class);
    if (batchBody != null) {
        jobId = batchBody.getJobId();
        batchId = batchBody.getId();
    } else {
        jobId = getParameter(JOB_ID, exchange, IGNORE_BODY, NOT_OPTIONAL);
        batchId = getParameter(BATCH_ID, exchange, USE_BODY, NOT_OPTIONAL);
    }
    bulkClient.getQueryResultIds(jobId, batchId, new BulkApiClient.QueryResultIdsCallback() {

        @Override
        public void onResponse(List<String> ids, SalesforceException ex) {
            processResponse(exchange, ids, ex, callback);
        }
    });
}
Also used : SalesforceException(org.apache.camel.component.salesforce.api.SalesforceException) 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)

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