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);
}
});
}
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);
}
});
}
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;
}
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);
}
});
}
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);
}
});
}
Aggregations