use of org.apache.camel.impl.verifier.ResultErrorBuilder in project camel by apache.
the class TwitterComponentVerifier method verifyCredentials.
private void verifyCredentials(ResultBuilder builder, Map<String, Object> parameters) throws Exception {
try {
TwitterConfiguration configuration = setProperties(new TwitterConfiguration(), parameters);
Twitter twitter = configuration.getTwitter();
twitter.verifyCredentials();
} catch (TwitterException e) {
// verifyCredentials throws TwitterException when Twitter service or
// network is unavailable or if supplied credential is wrong
ResultErrorBuilder errorBuilder = ResultErrorBuilder.withHttpCodeAndText(e.getStatusCode(), e.getErrorMessage()).attribute("twitter.error.code", e.getErrorCode()).attribute("twitter.status.code", e.getStatusCode()).attribute("twitter.exception.code", e.getExceptionCode()).attribute("twitter.exception.message", e.getMessage()).attribute("twitter.exception.instance", e);
// https://dev.twitter.com/overview/api/response-codes
if (e.getErrorCode() == 89) {
errorBuilder.parameter("accessToken");
}
builder.error(errorBuilder.build());
}
}
use of org.apache.camel.impl.verifier.ResultErrorBuilder in project camel by apache.
the class ServiceNowComponentVerifier method verifyConnectivity.
// *********************************
// Connectivity validation
// *********************************
@Override
protected Result verifyConnectivity(Map<String, Object> parameters) {
// Default is success
ResultBuilder builder = ResultBuilder.withStatusAndScope(Result.Status.OK, Scope.CONNECTIVITY);
try {
// Load ServiceNow Configuration
ServiceNowConfiguration configuration = new ServiceNowConfiguration();
setProperties(configuration, parameters);
String instanceName = getMandatoryOption(parameters, "instanceName", String.class);
String tableName = configuration.getTable() != null ? configuration.getTable() : "incident";
// Configure Api and OAuthToken ULRs using instanceName
if (!configuration.hasApiUrl()) {
configuration.setApiUrl(String.format("https://%s.service-now.com/api", instanceName));
}
if (!configuration.hasOauthTokenUrl()) {
configuration.setOauthTokenUrl(String.format("https://%s.service-now.com/oauth_token.do", instanceName));
}
new ServiceNowClient(getCamelContext(), configuration).types(MediaType.APPLICATION_JSON_TYPE).path("now").path(configuration.getApiVersion()).path("table").path(tableName).query(ServiceNowParams.SYSPARM_LIMIT.getId(), 1L).invoke(HttpMethod.GET);
} catch (NoSuchOptionException e) {
builder.error(ResultErrorBuilder.withMissingOption(e.getOptionName()).build());
} catch (ServiceNowException e) {
ResultErrorBuilder errorBuilder = ResultErrorBuilder.withException(e).attribute(ComponentVerifier.HTTP_CODE, e.getCode()).attribute("servicenow.error.message", e.getMessage()).attribute("servicenow.error.status", e.getStatus()).attribute("servicenow.error.detail", e.getDetail()).attribute("servicenow.error.detail", e.getDetail());
if (e.getCode() == 401) {
errorBuilder.parameter("userName");
errorBuilder.parameter("password");
errorBuilder.parameter("oauthClientId");
errorBuilder.parameter("oauthClientSecret");
}
builder.error(errorBuilder.build());
} catch (Exception e) {
builder.error(ResultErrorBuilder.withException(e).build());
}
return builder.build();
}
Aggregations