use of org.apache.camel.component.salesforce.api.SalesforceException in project camel by apache.
the class DefaultBulkApiClient method getBatch.
@Override
public void getBatch(String jobId, String batchId, final BatchInfoResponseCallback callback) {
final Request get = getRequest(HttpMethod.GET, batchUrl(jobId, batchId));
// make the call and parse the result
doHttpRequest(get, new ClientResponseCallback() {
@Override
public void onResponse(InputStream response, SalesforceException ex) {
BatchInfo value = null;
try {
value = unmarshalResponse(response, get, BatchInfo.class);
} catch (SalesforceException e) {
ex = e;
}
callback.onResponse(value, ex);
}
});
}
use of org.apache.camel.component.salesforce.api.SalesforceException in project camel by apache.
the class BulkApiProcessor method processCreateBatch.
private void processCreateBatch(final Exchange exchange, final AsyncCallback callback) throws SalesforceException {
String jobId;
// since request is in the body, use headers or endpoint params
ContentType contentType = ContentType.fromValue(getParameter(CONTENT_TYPE, exchange, IGNORE_BODY, NOT_OPTIONAL));
jobId = getParameter(JOB_ID, exchange, IGNORE_BODY, NOT_OPTIONAL);
InputStream request;
try {
request = exchange.getIn().getMandatoryBody(InputStream.class);
} catch (CamelException e) {
String msg = "Error preparing batch request: " + e.getMessage();
throw new SalesforceException(msg, e);
}
bulkClient.createBatch(request, jobId, 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 processCloseJob.
private void processCloseJob(final Exchange exchange, final AsyncCallback callback) throws SalesforceException {
JobInfo jobBody;
String jobId;
jobBody = exchange.getIn().getBody(JobInfo.class);
if (jobBody != null) {
jobId = jobBody.getId();
} else {
jobId = getParameter(JOB_ID, exchange, USE_BODY, NOT_OPTIONAL);
}
bulkClient.closeJob(jobId, new BulkApiClient.JobInfoResponseCallback() {
@Override
public void onResponse(JobInfo jobInfo, SalesforceException ex) {
processResponse(exchange, jobInfo, ex, callback);
}
});
}
use of org.apache.camel.component.salesforce.api.SalesforceException in project camel by apache.
the class CompositeApiProcessor method processInternal.
<T, R> boolean processInternal(final Class<T> bodyType, final Exchange exchange, final CompositeApiClient.Operation<T, R> clientOperation, final ResponseHandler<R> responseHandler, final AsyncCallback callback) throws SalesforceException {
final T body;
final Message in = exchange.getIn();
try {
body = in.getMandatoryBody(bodyType);
} catch (final InvalidPayloadException e) {
throw new SalesforceException(e);
}
clientOperation.submit(body, (response, exception) -> responseHandler.handleResponse(exchange, response, exception, callback));
return false;
}
use of org.apache.camel.component.salesforce.api.SalesforceException in project camel by apache.
the class JsonRestProcessor method getRequestStream.
@Override
protected InputStream getRequestStream(Exchange exchange) throws SalesforceException {
InputStream request;
Message in = exchange.getIn();
request = in.getBody(InputStream.class);
if (request == null) {
AbstractDTOBase dto = in.getBody(AbstractDTOBase.class);
if (dto != null) {
// marshall the DTO
request = getRequestStream(dto);
} else {
// if all else fails, get body as String
final String body = in.getBody(String.class);
if (null == body) {
String msg = "Unsupported request message body " + (in.getBody() == null ? null : in.getBody().getClass());
throw new SalesforceException(msg, null);
} else {
request = new ByteArrayInputStream(body.getBytes(StandardCharsets.UTF_8));
}
}
}
return request;
}
Aggregations