use of org.apache.camel.component.salesforce.api.SalesforceException in project camel by apache.
the class DefaultBulkApiClient method createBatch.
@Override
public void createBatch(InputStream batchStream, String jobId, ContentType contentTypeEnum, final BatchInfoResponseCallback callback) {
final Request post = getRequest(HttpMethod.POST, batchUrl(jobId, null));
post.content(new InputStreamContentProvider(batchStream));
post.header(HttpHeader.CONTENT_TYPE, getContentType(contentTypeEnum) + ";charset=" + StringUtil.__UTF8);
// make the call and parse the result
doHttpRequest(post, new ClientResponseCallback() {
@Override
public void onResponse(InputStream response, SalesforceException ex) {
BatchInfo value = null;
try {
value = unmarshalResponse(response, post, 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 DefaultRestClient method queryAll.
@Override
public void queryAll(String soqlQuery, ResponseCallback callback) {
try {
String encodedQuery = urlEncode(soqlQuery);
final Request get = getRequest(HttpMethod.GET, versionUrl() + "queryAll/?q=" + encodedQuery);
// requires authorization token
setAccessToken(get);
doHttpRequest(get, new DelegatingClientCallback(callback));
} catch (UnsupportedEncodingException e) {
String msg = "Unexpected error: " + e.getMessage();
callback.onResponse(null, new SalesforceException(msg, e));
}
}
use of org.apache.camel.component.salesforce.api.SalesforceException in project camel by apache.
the class DefaultRestClient method apexCall.
@Override
public void apexCall(String httpMethod, String apexUrl, Map<String, Object> queryParams, InputStream requestDto, ResponseCallback callback) {
// create APEX call request
final Request request;
try {
request = getRequest(httpMethod, apexCallUrl(apexUrl, queryParams));
// set request SObject and content type
if (requestDto != null) {
request.content(new InputStreamContentProvider(requestDto));
request.header(HttpHeader.CONTENT_TYPE, PayloadFormat.JSON.equals(format) ? APPLICATION_JSON_UTF8 : APPLICATION_XML_UTF8);
}
// requires authorization token
setAccessToken(request);
doHttpRequest(request, new DelegatingClientCallback(callback));
} catch (UnsupportedEncodingException e) {
String msg = "Unexpected error: " + e.getMessage();
callback.onResponse(null, new SalesforceException(msg, e));
} catch (URISyntaxException e) {
String msg = "Unexpected error: " + e.getMessage();
callback.onResponse(null, new SalesforceException(msg, e));
}
}
use of org.apache.camel.component.salesforce.api.SalesforceException in project camel by apache.
the class RestApiIntegrationTest method testStatus400.
@Test
public void testStatus400() throws Exception {
// get test merchandise
// note that the header value overrides sObjectFields in endpoint
final Merchandise__c merchandise = template().requestBodyAndHeader("direct:getSObject", testId, "sObjectFields", "Description__c,Price__c", Merchandise__c.class);
assertNotNull(merchandise);
assertNotNull(merchandise.getPrice__c());
assertNull(merchandise.getTotal_Inventory__c());
merchandise.clearBaseFields();
// required field Total_Inventory__c is missing
CreateSObjectResult result = null;
try {
result = template().requestBody("direct:createSObject", merchandise, CreateSObjectResult.class);
fail("Expected SalesforceException with statusCode 400");
} catch (final CamelExecutionException e) {
assertTrue(e.getCause() instanceof SalesforceException);
assertTrue(e.getCause().getCause() instanceof SalesforceException);
final SalesforceException cause = (SalesforceException) e.getCause().getCause();
assertEquals(400, cause.getStatusCode());
assertEquals(1, cause.getErrors().size());
assertEquals("[Total_Inventory__c]", cause.getErrors().get(0).getFields().toString());
} finally {
// delete the clone if created
if (result != null) {
template().requestBody("direct:deleteSObject", result.getId());
}
}
}
use of org.apache.camel.component.salesforce.api.SalesforceException in project camel by apache.
the class RestApiIntegrationTest method testStatus300.
@Test
public void testStatus300() throws Exception {
// get test merchandise
// note that the header value overrides sObjectFields in endpoint
final Merchandise__c merchandise = template().requestBodyAndHeader("direct:getSObject", testId, "sObjectFields", "Name,Description__c,Price__c,Total_Inventory__c", Merchandise__c.class);
assertNotNull(merchandise);
assertNotNull(merchandise.getName());
assertNotNull(merchandise.getPrice__c());
assertNotNull(merchandise.getTotal_Inventory__c());
CreateSObjectResult result = null;
try {
merchandise.clearBaseFields();
result = template().requestBody("direct:createSObject", merchandise, CreateSObjectResult.class);
assertNotNull(result);
assertNotNull(result.getId());
// note that the request SObject overrides settings on the endpoint for LineItem__c
try {
template().requestBody("direct:getSObjectWithId", merchandise, Merchandise__c.class);
fail("Expected SalesforceException with statusCode 300");
} catch (final CamelExecutionException e) {
assertTrue(e.getCause() instanceof SalesforceException);
assertTrue(e.getCause().getCause() instanceof SalesforceMultipleChoicesException);
final SalesforceMultipleChoicesException cause = (SalesforceMultipleChoicesException) e.getCause().getCause();
assertEquals(300, cause.getStatusCode());
final List<String> choices = cause.getChoices();
assertNotNull(choices);
assertFalse(choices.isEmpty());
}
} finally {
// delete the test clone
if (result != null) {
template().requestBody("direct:deleteSObject", result.getId());
}
}
}
Aggregations