Search in sources :

Example 1 with HopConfigException

use of org.apache.hop.core.exception.HopConfigException in project hop by apache.

the class NeoConnection method getDriver.

public Driver getDriver(ILogChannel log, IVariables variables) throws HopConfigException {
    try {
        List<URI> uris = getURIs(variables);
        String realUsername = variables.resolve(username);
        String realPassword = Encr.decryptPasswordOptionallyEncrypted(variables.resolve(password));
        Config.ConfigBuilder configBuilder;
        if (!isAutomatic(variables)) {
            if (encryptionVariableSet(variables) || usingEncryption) {
                configBuilder = Config.builder().withEncryption();
                if (trustAllCertificatesVariableSet(variables) || trustAllCertificates) {
                    configBuilder = configBuilder.withTrustStrategy(Config.TrustStrategy.trustAllCertificates());
                }
            } else {
                configBuilder = Config.builder().withoutEncryption();
            }
        } else {
            configBuilder = Config.builder();
        }
        if (StringUtils.isNotEmpty(connectionLivenessCheckTimeout)) {
            long seconds = Const.toLong(variables.resolve(connectionLivenessCheckTimeout), -1L);
            if (seconds > 0) {
                configBuilder = configBuilder.withConnectionLivenessCheckTimeout(seconds, TimeUnit.MILLISECONDS);
            }
        }
        if (StringUtils.isNotEmpty(maxConnectionLifetime)) {
            long seconds = Const.toLong(variables.resolve(maxConnectionLifetime), -1L);
            if (seconds > 0) {
                configBuilder = configBuilder.withMaxConnectionLifetime(seconds, TimeUnit.MILLISECONDS);
            }
        }
        if (StringUtils.isNotEmpty(maxConnectionPoolSize)) {
            int size = Const.toInt(variables.resolve(maxConnectionPoolSize), -1);
            if (size > 0) {
                configBuilder = configBuilder.withMaxConnectionPoolSize(size);
            }
        }
        if (StringUtils.isNotEmpty(connectionAcquisitionTimeout)) {
            long seconds = Const.toLong(variables.resolve(connectionAcquisitionTimeout), -1L);
            if (seconds > 0) {
                configBuilder = configBuilder.withConnectionAcquisitionTimeout(seconds, TimeUnit.MILLISECONDS);
            }
        }
        if (StringUtils.isNotEmpty(connectionTimeout)) {
            long seconds = Const.toLong(variables.resolve(connectionTimeout), -1L);
            if (seconds > 0) {
                configBuilder = configBuilder.withConnectionTimeout(seconds, TimeUnit.MILLISECONDS);
            }
        }
        if (StringUtils.isNotEmpty(maxTransactionRetryTime)) {
            long seconds = Const.toLong(variables.resolve(maxTransactionRetryTime), -1L);
            if (seconds >= 0) {
                configBuilder = configBuilder.withMaxTransactionRetryTime(seconds, TimeUnit.MILLISECONDS);
            }
        }
        // Disable info messages: only warnings and above...
        // 
        configBuilder = configBuilder.withLogging(Logging.javaUtilLogging(Level.WARNING));
        Config config = configBuilder.build();
        if (isUsingRouting(variables)) {
            return GraphDatabase.routingDriver(uris, AuthTokens.basic(realUsername, realPassword), config);
        } else {
            return GraphDatabase.driver(uris.get(0), AuthTokens.basic(realUsername, realPassword), config);
        }
    } catch (URISyntaxException e) {
        throw new HopConfigException("URI syntax problem, check your settings, hostnames especially.  For routing use comma separated server values.", e);
    }
}
Also used : HopConfigException(org.apache.hop.core.exception.HopConfigException) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI)

Aggregations

URI (java.net.URI)1 URISyntaxException (java.net.URISyntaxException)1 HopConfigException (org.apache.hop.core.exception.HopConfigException)1