diff --git a/CHANGES.txt b/CHANGES.txt index 903c933255..862419bb13 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -1,6 +1,7 @@ 2.0.7-SNAPSHOT -------------- o Fixes issue where session.loadAll would sort by ids instead of by the sort order specified. Fixes #302. +o Expose connection.liveness.check.timeout driver property to fix connection problems with firewalls. See #358. 2.0.6 diff --git a/api/src/main/java/org/neo4j/ogm/config/DriverConfiguration.java b/api/src/main/java/org/neo4j/ogm/config/DriverConfiguration.java index c24f1b6666..90dd54bc5d 100644 --- a/api/src/main/java/org/neo4j/ogm/config/DriverConfiguration.java +++ b/api/src/main/java/org/neo4j/ogm/config/DriverConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2002-2016 "Neo Technology," + * Copyright (c) 2002-2017 "Neo Technology," * Network Engine for Objects in Lund AB [http://neotechnology.com] * * This product is licensed to you under the Apache License, Version 2.0 (the "License"). @@ -13,11 +13,11 @@ package org.neo4j.ogm.config; +import java.net.URI; + import org.neo4j.ogm.authentication.Credentials; import org.neo4j.ogm.authentication.UsernamePasswordCredentials; -import java.net.URI; - /** * * A wrapper class for a generic {@link Configuration} that exposes the configuration for a Driver via @@ -34,6 +34,7 @@ public class DriverConfiguration { public static final String[] PASSWORD = {"neo4j.ogm.password", "spring.data.neo4j.password", "password"}; public static final String[] CONNECTION_POOL_SIZE = {"connection.pool.size"}; + public static final String[] CONNECTION_LIVENESS_CHECK_TIMEOUT = {"connection.liveness.check.timeout"}; public static final String[] ENCRYPTION_LEVEL = {"encryption.level"}; public static final String[] TRUST_STRATEGY = {"trust.strategy"}; public static final String[] TRUST_CERT_FILE = {"trust.certificate.file"}; @@ -85,6 +86,11 @@ public DriverConfiguration setConnectionPoolSize(Integer sessionPoolSize) { return this; } + public DriverConfiguration setConnectionLivenessCheckTimeout(Integer timeoutInMs) { + configuration.set(CONNECTION_LIVENESS_CHECK_TIMEOUT[0], timeoutInMs.toString()); + return this; + } + public DriverConfiguration setEncryptionLevel(String encryptionLevel) { configuration.set(ENCRYPTION_LEVEL[0], encryptionLevel); return this; @@ -140,6 +146,13 @@ public Integer getConnectionPoolSize() { return CONNECTION_POOL_SIZE_DEFAULT; } + public Integer getConnectionLivenessCheckTimeout() { + if (configuration.get(CONNECTION_LIVENESS_CHECK_TIMEOUT) != null) { + return Integer.valueOf((String)configuration.get(CONNECTION_LIVENESS_CHECK_TIMEOUT)); + } + return null; + } + public String getEncryptionLevel() { if (configuration.get(ENCRYPTION_LEVEL) != null) { return (String)configuration.get(ENCRYPTION_LEVEL); diff --git a/bolt-driver/src/main/java/org/neo4j/ogm/drivers/bolt/driver/BoltDriver.java b/bolt-driver/src/main/java/org/neo4j/ogm/drivers/bolt/driver/BoltDriver.java index a0dde8e1e2..3c7df5dbd4 100644 --- a/bolt-driver/src/main/java/org/neo4j/ogm/drivers/bolt/driver/BoltDriver.java +++ b/bolt-driver/src/main/java/org/neo4j/ogm/drivers/bolt/driver/BoltDriver.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2002-2016 "Neo Technology," + * Copyright (c) 2002-2017 "Neo Technology," * Network Engine for Objects in Lund AB [http://neotechnology.com] * * This product is licensed to you under the Apache License, Version 2.0 (the "License"). @@ -13,6 +13,9 @@ package org.neo4j.ogm.drivers.bolt.driver; +import java.io.File; +import java.net.URI; + import org.neo4j.driver.v1.*; import org.neo4j.driver.v1.exceptions.ClientException; import org.neo4j.ogm.authentication.UsernamePasswordCredentials; @@ -26,9 +29,6 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.io.File; -import java.net.URI; - /** * @author vince * @author Luanne Misquitta @@ -150,6 +150,10 @@ private BoltConfig getBoltConfiguration(DriverConfiguration driverConfiguration) boltConfig.trustCertFile = driverConfiguration.getTrustCertFile(); } + if (driverConfiguration.getConnectionLivenessCheckTimeout() != null) { + boltConfig.connectionLivenessCheckTimeout = driverConfiguration.getConnectionLivenessCheckTimeout(); + } + return boltConfig; } @@ -159,6 +163,10 @@ private Config buildDriverConfig(DriverConfiguration driverConfig) { Config.ConfigBuilder configBuilder = Config.build(); configBuilder.withMaxSessions(boltConfig.sessionPoolSize); configBuilder.withEncryptionLevel(boltConfig.encryptionLevel); + if (boltConfig.connectionLivenessCheckTimeout != null) { + // deprecated in driver 1.1 +, replaced by ConnectionLivenessCheckTimeout + configBuilder.withSessionLivenessCheckTimeout(boltConfig.connectionLivenessCheckTimeout); + } if (boltConfig.trustStrategy != null) { if (boltConfig.trustCertFile == null) { throw new IllegalArgumentException("Missing configuration value for trust.certificate.file"); @@ -184,5 +192,6 @@ class BoltConfig { int sessionPoolSize = DEFAULT_SESSION_POOL_SIZE; Config.TrustStrategy.Strategy trustStrategy; String trustCertFile; + Integer connectionLivenessCheckTimeout; } } \ No newline at end of file diff --git a/core/src/test/resources/ogm-bolt.properties b/core/src/test/resources/ogm-bolt.properties index 30592d6b30..a2a9bb9c21 100644 --- a/core/src/test/resources/ogm-bolt.properties +++ b/core/src/test/resources/ogm-bolt.properties @@ -1,5 +1,5 @@ # -# Copyright (c) 2002-2016 "Neo Technology," +# Copyright (c) 2002-2017 "Neo Technology," # Network Engine for Objects in Lund AB [http://neotechnology.com] # # This product is licensed to you under the Apache License, Version 2.0 (the "License"). @@ -18,3 +18,6 @@ URI=bolt://localhost #Do not set the pool size to < 150 otherwise tests that spawn 100 concurrent requests will fail connection.pool.size=150 encryption.level=NONE +# stale connections test interval in milliseconds +# please see official driver documentation before activating this +#connection.liveness.check.timeout=100 \ No newline at end of file diff --git a/pom.xml b/pom.xml index 3d49c1c196..ba1047f488 100644 --- a/pom.xml +++ b/pom.xml @@ -1,7 +1,7 @@