use of org.apache.camel.impl.verifier.ResultBuilder 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.impl.verifier.ResultBuilder in project camel by apache.
the class HttpComponentVerifier method verifyParameters.
// *********************************
// Parameters validation
// *********************************
@Override
protected Result verifyParameters(Map<String, Object> parameters) {
// The default is success
ResultBuilder builder = ResultBuilder.withStatusAndScope(Result.Status.OK, Scope.PARAMETERS);
// Validate using the catalog
super.verifyParametersAgainstCatalog(builder, parameters);
return builder.build();
}
use of org.apache.camel.impl.verifier.ResultBuilder in project camel by apache.
the class TwitterComponentVerifier method verifyParameters.
// *********************************
// Parameters validation
// *********************************
@Override
protected Result verifyParameters(Map<String, Object> parameters) {
ResultBuilder builder = ResultBuilder.withStatusAndScope(Result.Status.OK, Scope.PARAMETERS).error(ResultErrorHelper.requiresOption("accessToken", parameters)).error(ResultErrorHelper.requiresOption("accessTokenSecret", parameters)).error(ResultErrorHelper.requiresOption("consumerKey", parameters)).error(ResultErrorHelper.requiresOption("consumerSecret", parameters));
// Validate using the catalog
super.verifyParametersAgainstCatalog(builder, parameters);
return builder.build();
}
use of org.apache.camel.impl.verifier.ResultBuilder in project camel by apache.
the class SalesforceComponentVerifier method verifyParameters.
// *********************************
// Parameters validation
// *********************************
@Override
protected Result verifyParameters(Map<String, Object> parameters) {
// Validate mandatory component options, needed to be done here as these
// options are not properly marked as mandatory in the catalog.
ResultBuilder builder = ResultBuilder.withStatusAndScope(Result.Status.OK, Scope.PARAMETERS).error(ResultErrorHelper.requiresOption("clientId", parameters)).error(ResultErrorHelper.requiresOption("clientSecret", parameters)).error(ResultErrorHelper.requiresOption("userName", parameters)).error(ResultErrorHelper.requiresOption("password", parameters));
// Validate using the catalog
super.verifyParametersAgainstCatalog(builder, parameters);
return builder.build();
}
use of org.apache.camel.impl.verifier.ResultBuilder in project camel by apache.
the class HttpComponentVerifier method verifyParameters.
// *********************************
// Parameters validation
// *********************************
@Override
protected Result verifyParameters(Map<String, Object> parameters) {
// The default is success
ResultBuilder builder = ResultBuilder.withStatusAndScope(Result.Status.OK, Scope.PARAMETERS);
// Validate using the catalog
super.verifyParametersAgainstCatalog(builder, parameters);
// Validate if the auth/proxy combination is properly set-up
Optional<String> authMethod = getOption(parameters, "authMethod", String.class);
if (authMethod.isPresent()) {
// If auth method is set, username and password must be provided
builder.error(ResultErrorHelper.requiresOption("authUsername", parameters));
builder.error(ResultErrorHelper.requiresOption("authPassword", parameters));
// Check if the AuthMethod is known
AuthMethod auth = getCamelContext().getTypeConverter().convertTo(AuthMethod.class, authMethod.get());
if (auth != AuthMethod.Basic && auth != AuthMethod.Digest && auth != AuthMethod.NTLM) {
builder.error(ResultErrorBuilder.withIllegalOption("authMethod", authMethod.get()).build());
}
// If auth method is NTLM, authDomain is mandatory
if (auth == AuthMethod.NTLM) {
builder.error(ResultErrorHelper.requiresOption("authDomain", parameters));
}
}
return builder.build();
}
Aggregations