use of org.apache.camel.component.salesforce.api.SalesforceException in project camel by apache.
the class BulkApiProcessor method processGetAllBatches.
private void processGetAllBatches(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.getAllBatches(jobId, new BulkApiClient.BatchInfoListResponseCallback() {
@Override
public void onResponse(List<BatchInfo> batchInfoList, SalesforceException ex) {
processResponse(exchange, batchInfoList, ex, callback);
}
});
}
use of org.apache.camel.component.salesforce.api.SalesforceException in project camel by apache.
the class SalesforceSession method logout.
public synchronized void logout() throws SalesforceException {
if (accessToken == null) {
return;
}
try {
String logoutUrl = (instanceUrl == null ? config.getLoginUrl() : instanceUrl) + OAUTH2_REVOKE_PATH + accessToken;
final Request logoutGet = httpClient.newRequest(logoutUrl).timeout(timeout, TimeUnit.MILLISECONDS);
final ContentResponse logoutResponse = logoutGet.send();
final int statusCode = logoutResponse.getStatus();
final String reason = logoutResponse.getReason();
if (statusCode == HttpStatus.OK_200) {
LOG.info("Logout successful");
} else {
throw new SalesforceException(String.format("Logout error, code: [%s] reason: [%s]", statusCode, reason), statusCode);
}
} catch (InterruptedException e) {
String msg = "Logout error: " + e.getMessage();
throw new SalesforceException(msg, e);
} catch (ExecutionException e) {
final Throwable ex = e.getCause();
throw new SalesforceException("Unexpected logout exception: " + ex.getMessage(), ex);
} catch (TimeoutException e) {
throw new SalesforceException("Logout request TIMEOUT!", null);
} finally {
// reset session
accessToken = null;
instanceUrl = null;
// notify all session listeners about logout
for (SalesforceSessionListener listener : listeners) {
try {
listener.onLogout();
} catch (Throwable t) {
LOG.warn("Unexpected error from listener {}: {}", listener, t.getMessage());
}
}
}
}
use of org.apache.camel.component.salesforce.api.SalesforceException in project camel by apache.
the class SalesforceSession method parseLoginResponse.
/**
* Parses login response, allows SalesforceSecurityHandler to parse a login request for a failed authentication
* conversation.
*/
public synchronized void parseLoginResponse(ContentResponse loginResponse, String responseContent) throws SalesforceException {
final int responseStatus = loginResponse.getStatus();
try {
switch(responseStatus) {
case HttpStatus.OK_200:
// parse the response to get token
LoginToken token = objectMapper.readValue(responseContent, LoginToken.class);
// don't log token or instance URL for security reasons
LOG.info("Login successful");
accessToken = token.getAccessToken();
instanceUrl = token.getInstanceUrl();
// notify all session listeners
for (SalesforceSessionListener listener : listeners) {
try {
listener.onLogin(accessToken, instanceUrl);
} catch (Throwable t) {
LOG.warn("Unexpected error from listener {}: {}", listener, t.getMessage());
}
}
break;
case HttpStatus.BAD_REQUEST_400:
// parse the response to get error
final LoginError error = objectMapper.readValue(responseContent, LoginError.class);
final String msg = String.format("Login error code:[%s] description:[%s]", error.getError(), error.getErrorDescription());
final List<RestError> errors = new ArrayList<RestError>();
errors.add(new RestError(msg, error.getErrorDescription()));
throw new SalesforceException(errors, HttpStatus.BAD_REQUEST_400);
default:
throw new SalesforceException(String.format("Login error status:[%s] reason:[%s]", responseStatus, loginResponse.getReason()), responseStatus);
}
} catch (IOException e) {
String msg = "Login error: response parse exception " + e.getMessage();
throw new SalesforceException(msg, e);
}
}
use of org.apache.camel.component.salesforce.api.SalesforceException in project camel by apache.
the class DefaultAnalyticsApiClient method executeSyncReport.
@Override
public void executeSyncReport(String reportId, Boolean includeDetails, ReportMetadata reportMetadata, final ReportResultsResponseCallback callback) {
final boolean useGet = reportMetadata == null;
final Request request = getRequest(useGet ? HttpMethod.GET : HttpMethod.POST, reportsUrl(reportId, includeDetails));
// set POST data
if (!useGet) {
try {
// wrap reportMetadata in a map
final HashMap<String, Object> input = new HashMap<String, Object>();
input.put("reportMetadata", reportMetadata);
marshalRequest(input, request);
} catch (SalesforceException e) {
callback.onResponse(null, e);
return;
}
}
doHttpRequest(request, new ClientResponseCallback() {
@Override
public void onResponse(InputStream response, SalesforceException ex) {
SyncReportResults reportResults = null;
try {
reportResults = unmarshalResponse(response, request, SyncReportResults.class);
} catch (SalesforceException e) {
ex = e;
}
callback.onResponse(reportResults, ex);
}
});
}
use of org.apache.camel.component.salesforce.api.SalesforceException in project camel by apache.
the class DefaultAnalyticsApiClient method getReportDescription.
@Override
public void getReportDescription(String reportId, final ReportDescriptionResponseCallback callback) {
final Request request = getRequest(HttpMethod.GET, reportsDescribeUrl(reportId));
doHttpRequest(request, new ClientResponseCallback() {
@Override
public void onResponse(InputStream response, SalesforceException ex) {
ReportDescription reportDescription = null;
try {
reportDescription = unmarshalResponse(response, request, ReportDescription.class);
} catch (SalesforceException e) {
ex = e;
}
callback.onResponse(reportDescription, ex);
}
});
}
Aggregations