Search in sources :

Example 1 with NoSuchOptionException

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();
}
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 NoSuchOptionException

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();
}
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)

Aggregations

NoSuchOptionException (org.apache.camel.NoSuchOptionException)2 ResultBuilder (org.apache.camel.impl.verifier.ResultBuilder)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