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();
}
use of org.apache.camel.impl.verifier.ResultBuilder in project camel by apache.
the class HttpComponentVerifier method verifyConnectivity.
// *********************************
// Connectivity validation
// *********************************
@Override
protected Result verifyConnectivity(Map<String, Object> parameters) {
// Default is success
ResultBuilder builder = ResultBuilder.withStatusAndScope(Result.Status.OK, Scope.CONNECTIVITY);
Optional<String> uri = getOption(parameters, "httpUri", String.class);
if (!uri.isPresent()) {
// lack of httpUri is a blocking issue
builder.error(ResultErrorHelper.requiresOption("httpUri", parameters));
} else {
builder.error(parameters, this::verifyHttpConnectivity);
}
return builder.build();
}
use of org.apache.camel.impl.verifier.ResultBuilder 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();
}
use of org.apache.camel.impl.verifier.ResultBuilder in project camel by apache.
the class ServiceNowComponentVerifier method verifyParameters.
// *********************************
// Parameters validation
// *********************************
@Override
protected Result verifyParameters(Map<String, Object> parameters) {
ResultBuilder builder = ResultBuilder.withStatusAndScope(Result.Status.OK, Scope.PARAMETERS);
// Validate using the catalog
super.verifyParametersAgainstCatalog(builder, parameters);
return builder.build();
}
Aggregations