use of org.apache.camel.component.salesforce.api.SalesforceException in project camel by apache.
the class AbstractRestProcessor method setPropertyValue.
private void setPropertyValue(Object sObjectBase, String name, Object value) throws SalesforceException {
try {
// set the value with the set method
Method setMethod = sObjectBase.getClass().getMethod("set" + name, value.getClass());
setMethod.invoke(sObjectBase, value);
} catch (NoSuchMethodException e) {
throw new SalesforceException(String.format("SObject %s does not have a field %s", sObjectBase.getClass().getName(), name), e);
} catch (InvocationTargetException e) {
throw new SalesforceException(String.format("Error setting value %s.%s", sObjectBase.getClass().getSimpleName(), name), e);
} catch (IllegalAccessException e) {
throw new SalesforceException(String.format("Error accessing value %s.%s", sObjectBase.getClass().getSimpleName(), name), e);
}
}
use of org.apache.camel.component.salesforce.api.SalesforceException in project camel by apache.
the class AbstractRestProcessor method processDeleteSobject.
private void processDeleteSobject(final Exchange exchange, final AsyncCallback callback) throws SalesforceException {
String sObjectName;
// determine parameters from input AbstractSObject
final AbstractSObjectBase sObjectBase = exchange.getIn().getBody(AbstractSObjectBase.class);
String sObjectIdValue;
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;
restClient.deleteSObject(sObjectName, sObjectId, 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 AbstractRestProcessor method processGetSobjectWithId.
private void processGetSobjectWithId(final Exchange exchange, final AsyncCallback callback) throws SalesforceException {
String sObjectName;
Object oldValue = null;
String sObjectExtIdValue;
final String sObjectExtIdName = getParameter(SOBJECT_EXT_ID_NAME, exchange, IGNORE_BODY, NOT_OPTIONAL);
// determine parameters from input AbstractSObject
final AbstractSObjectBase sObjectBase = exchange.getIn().getBody(AbstractSObjectBase.class);
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);
}
// use sObject name to load class
setResponseClass(exchange, sObjectName);
final Object finalOldValue = oldValue;
restClient.getSObjectWithId(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);
}
});
}
use of org.apache.camel.component.salesforce.api.SalesforceException in project camel by apache.
the class DefaultBulkApiClient method getRequest.
@Override
public void getRequest(String jobId, String batchId, final StreamResponseCallback callback) {
final Request get = getRequest(HttpMethod.GET, batchRequestUrl(jobId, batchId, null));
// make the call and parse the result
doHttpRequest(get, new ClientResponseCallback() {
@Override
public void onResponse(InputStream response, SalesforceException ex) {
callback.onResponse(response, ex);
}
});
}
use of org.apache.camel.component.salesforce.api.SalesforceException in project camel by apache.
the class DefaultBulkApiClient method closeJob.
@Override
public void closeJob(String jobId, final JobInfoResponseCallback callback) {
final JobInfo request = new JobInfo();
request.setState(JobStateEnum.CLOSED);
final Request post = getRequest(HttpMethod.POST, jobUrl(jobId));
try {
marshalRequest(objectFactory.createJobInfo(request), post, APPLICATION_XML_UTF8);
} catch (SalesforceException e) {
callback.onResponse(null, e);
return;
}
// make the call and parse the result
doHttpRequest(post, new ClientResponseCallback() {
@Override
public void onResponse(InputStream response, SalesforceException ex) {
JobInfo value = null;
try {
value = unmarshalResponse(response, post, JobInfo.class);
} catch (SalesforceException e) {
ex = e;
}
callback.onResponse(value, ex);
}
});
}
Aggregations