use of org.apache.camel.NoSuchOptionException in project camel by apache.
the class SalesforceComponentVerifier 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 {
SalesforceEndpointConfig configuration = new SalesforceEndpointConfig();
setProperties(configuration, parameters);
SalesforceLoginConfig loginConfig = new SalesforceLoginConfig();
setProperties(loginConfig, parameters);
// Create a dummy SslContextFactory which is needed by SalesforceHttpClient
// or the underlying jetty client fails with a NPE
SSLContextParameters contextParameters = new SSLContextParameters();
SslContextFactory sslContextFactory = new SslContextFactory();
sslContextFactory.setSslContext(contextParameters.createSSLContext(getCamelContext()));
SalesforceHttpClient httpClient = new SalesforceHttpClient(sslContextFactory);
httpClient.setConnectTimeout(SalesforceComponent.CONNECTION_TIMEOUT);
configureHttpProxy(httpClient, parameters);
SalesforceSession session = new SalesforceSession(getCamelContext(), httpClient, httpClient.getTimeout(), loginConfig);
DefaultRestClient client = new DefaultRestClient(httpClient, configuration.getApiVersion(), configuration.getFormat(), session);
httpClient.setSession(session);
httpClient.start();
// For authentication check is is enough to use
session.start();
client.start();
client.getVersions((response, exception) -> processSalesforceException(builder, Optional.ofNullable(exception)));
client.stop();
session.stop();
httpClient.stop();
httpClient.destroy();
} catch (NoSuchOptionException e) {
builder.error(ResultErrorBuilder.withMissingOption(e.getOptionName()).build());
} catch (SalesforceException e) {
processSalesforceException(builder, Optional.of(e));
} catch (Exception e) {
builder.error(ResultErrorBuilder.withException(e).build());
throw new RuntimeException(e);
}
return builder.build();
}
use of org.apache.camel.NoSuchOptionException 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