diff --git a/src/main/java/software/amazon/nio/spi/s3/config/S3NioSpiConfiguration.java b/src/main/java/software/amazon/nio/spi/s3/config/S3NioSpiConfiguration.java index 0804befa..caebd21e 100644 --- a/src/main/java/software/amazon/nio/spi/s3/config/S3NioSpiConfiguration.java +++ b/src/main/java/software/amazon/nio/spi/s3/config/S3NioSpiConfiguration.java @@ -65,6 +65,10 @@ public class S3NioSpiConfiguration extends HashMap { * The name of the force path style property */ public static final String S3_SPI_FORCE_PATH_STYLE_PROPERTY = "s3.spi.force-path-style"; + /** + * The default value of the force path style property + */ + public static final boolean S3_SPI_FORCE_PATH_STYLE_DEFAULT = false; /** * The default value of the credentials property */ @@ -98,6 +102,7 @@ public S3NioSpiConfiguration(Map overrides) { put(S3_SPI_READ_MAX_FRAGMENT_NUMBER_PROPERTY, String.valueOf(S3_SPI_READ_MAX_FRAGMENT_NUMBER_DEFAULT)); put(S3_SPI_READ_MAX_FRAGMENT_SIZE_PROPERTY, String.valueOf(S3_SPI_READ_MAX_FRAGMENT_SIZE_DEFAULT)); put(S3_SPI_ENDPOINT_PROTOCOL_PROPERTY, S3_SPI_ENDPOINT_PROTOCOL_DEFAULT); + put(S3_SPI_FORCE_PATH_STYLE_PROPERTY, String.valueOf(S3_SPI_FORCE_PATH_STYLE_DEFAULT)); // // With the below we pick existing environment variables and system @@ -286,7 +291,7 @@ public S3NioSpiConfiguration withForcePathStyle(Boolean forcePathStyle) { if (forcePathStyle == null) { remove(S3_SPI_FORCE_PATH_STYLE_PROPERTY); } else { - put(S3_SPI_FORCE_PATH_STYLE_PROPERTY, forcePathStyle); + put(S3_SPI_FORCE_PATH_STYLE_PROPERTY, String.valueOf(forcePathStyle)); } return this; @@ -387,7 +392,8 @@ public String getBucketName() { } public boolean getForcePathStyle() { - return (boolean) getOrDefault(S3_SPI_FORCE_PATH_STYLE_PROPERTY, false); + return Boolean.parseBoolean((String) getOrDefault(S3_SPI_FORCE_PATH_STYLE_PROPERTY, + String.valueOf(S3_SPI_FORCE_PATH_STYLE_DEFAULT))); } /** diff --git a/src/test/java/software/amazon/nio/spi/s3/config/S3NioSpiConfigurationTest.java b/src/test/java/software/amazon/nio/spi/s3/config/S3NioSpiConfigurationTest.java index 0f354c74..3bc65f8e 100644 --- a/src/test/java/software/amazon/nio/spi/s3/config/S3NioSpiConfigurationTest.java +++ b/src/test/java/software/amazon/nio/spi/s3/config/S3NioSpiConfigurationTest.java @@ -234,15 +234,15 @@ public void withAndGetBucketName() { @Test public void withAndGetForcePathStyle() { - then(config).doesNotContainKey(S3_SPI_FORCE_PATH_STYLE_PROPERTY); + then(config).contains(entry(S3_SPI_FORCE_PATH_STYLE_PROPERTY, "false")); then(config.withForcePathStyle(true)).isSameAs(config); - then(config).contains(entry(S3_SPI_FORCE_PATH_STYLE_PROPERTY, true)); + then(config).contains(entry(S3_SPI_FORCE_PATH_STYLE_PROPERTY, "true")); then(config.getForcePathStyle()).isTrue(); then(config.withForcePathStyle(false).getForcePathStyle()).isFalse(); Map map = new HashMap<>(); config = new S3NioSpiConfiguration(map); then(config.getForcePathStyle()).isFalse(); - map.put(S3_SPI_FORCE_PATH_STYLE_PROPERTY, true); config = new S3NioSpiConfiguration(map); + map.put(S3_SPI_FORCE_PATH_STYLE_PROPERTY, "true"); config = new S3NioSpiConfiguration(map); then(config .getForcePathStyle()).isTrue(); map.remove(S3_SPI_FORCE_PATH_STYLE_PROPERTY); // same S3NioSpiConfiguration on purpose then(config.getForcePathStyle()).isTrue();