Search in sources :

Example 1 with ResultBuilder

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();
}
Also used : ResultBuilder(org.apache.camel.impl.verifier.ResultBuilder) SalesforceException(org.apache.camel.component.salesforce.api.SalesforceException) SslContextFactory(org.eclipse.jetty.util.ssl.SslContextFactory) NoSuchOptionException(org.apache.camel.NoSuchOptionException) SalesforceSession(org.apache.camel.component.salesforce.internal.SalesforceSession) DefaultRestClient(org.apache.camel.component.salesforce.internal.client.DefaultRestClient) URISyntaxException(java.net.URISyntaxException) NoSuchOptionException(org.apache.camel.NoSuchOptionException) SalesforceException(org.apache.camel.component.salesforce.api.SalesforceException) SSLContextParameters(org.apache.camel.util.jsse.SSLContextParameters)

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

Example 3 with ResultBuilder

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

Example 4 with ResultBuilder

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

Example 5 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)

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