Search in sources :

Example 36 with SalesforceException

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);
        }
    });
}
Also used : SalesforceException(org.apache.camel.component.salesforce.api.SalesforceException) InputStream(java.io.InputStream) Request(org.eclipse.jetty.client.api.Request) InputStreamContentProvider(org.eclipse.jetty.client.util.InputStreamContentProvider) BatchInfo(org.apache.camel.component.salesforce.api.dto.bulk.BatchInfo)

Example 37 with SalesforceException

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));
    }
}
Also used : SalesforceException(org.apache.camel.component.salesforce.api.SalesforceException) Request(org.eclipse.jetty.client.api.Request) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Example 38 with SalesforceException

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));
    }
}
Also used : SalesforceException(org.apache.camel.component.salesforce.api.SalesforceException) Request(org.eclipse.jetty.client.api.Request) UnsupportedEncodingException(java.io.UnsupportedEncodingException) InputStreamContentProvider(org.eclipse.jetty.client.util.InputStreamContentProvider) URISyntaxException(java.net.URISyntaxException)

Example 39 with SalesforceException

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());
        }
    }
}
Also used : CamelExecutionException(org.apache.camel.CamelExecutionException) SalesforceException(org.apache.camel.component.salesforce.api.SalesforceException) CreateSObjectResult(org.apache.camel.component.salesforce.api.dto.CreateSObjectResult) Merchandise__c(org.apache.camel.component.salesforce.dto.generated.Merchandise__c) Test(org.junit.Test)

Example 40 with SalesforceException

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());
        }
    }
}
Also used : CamelExecutionException(org.apache.camel.CamelExecutionException) SalesforceException(org.apache.camel.component.salesforce.api.SalesforceException) CreateSObjectResult(org.apache.camel.component.salesforce.api.dto.CreateSObjectResult) Merchandise__c(org.apache.camel.component.salesforce.dto.generated.Merchandise__c) SalesforceMultipleChoicesException(org.apache.camel.component.salesforce.api.SalesforceMultipleChoicesException) List(java.util.List) Test(org.junit.Test)

Aggregations

SalesforceException (org.apache.camel.component.salesforce.api.SalesforceException)77 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 CamelException (org.apache.camel.CamelException)7 HashMap (java.util.HashMap)6 Message (org.apache.camel.Message)6 ByteArrayInputStream (java.io.ByteArrayInputStream)5 List (java.util.List)4 InvocationTargetException (java.lang.reflect.InvocationTargetException)3 Method (java.lang.reflect.Method)3 Map (java.util.Map)3