Search in sources :

Example 6 with ResultBuilder

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();
}
Also used : ResultBuilder(org.apache.camel.impl.verifier.ResultBuilder)

Example 7 with ResultBuilder

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();
}
Also used : ResultBuilder(org.apache.camel.impl.verifier.ResultBuilder)

Example 8 with ResultBuilder

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();
}
Also used : ResultBuilder(org.apache.camel.impl.verifier.ResultBuilder) NoSuchOptionException(org.apache.camel.NoSuchOptionException) ResultErrorBuilder(org.apache.camel.impl.verifier.ResultErrorBuilder) NoSuchOptionException(org.apache.camel.NoSuchOptionException)

Example 9 with ResultBuilder

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();
}
Also used : ResultBuilder(org.apache.camel.impl.verifier.ResultBuilder)

Aggregations

ResultBuilder (org.apache.camel.impl.verifier.ResultBuilder)9 NoSuchOptionException (org.apache.camel.NoSuchOptionException)2 URISyntaxException (java.net.URISyntaxException)1 SalesforceException (org.apache.camel.component.salesforce.api.SalesforceException)1 SalesforceSession (org.apache.camel.component.salesforce.internal.SalesforceSession)1 DefaultRestClient (org.apache.camel.component.salesforce.internal.client.DefaultRestClient)1 ResultErrorBuilder (org.apache.camel.impl.verifier.ResultErrorBuilder)1 SSLContextParameters (org.apache.camel.util.jsse.SSLContextParameters)1 SslContextFactory (org.eclipse.jetty.util.ssl.SslContextFactory)1