From 818d3bd230c5ea22b72e1a2d5b4361b5918d101c Mon Sep 17 00:00:00 2001 From: Ben Hale Date: Mon, 15 Jun 2015 16:02:16 +0100 Subject: [PATCH] VcapApplicationListener Boolean Credentials Previously, the VcapApplicationListener would discard any service credential value that wasn't a String, Number, Map, Collection, or null. This was particularly a problem for services that exposed a value as a JSON boolean. This change takes booleans in the credential payload into account, converting them to Strings so that they will pass through the properties system properly. There's no real downside to this as Spring will coerce them back into Booleans if needed, by the application. Fixes gh-3237 --- .../boot/cloudfoundry/VcapApplicationListener.java | 3 +++ .../boot/cloudfoundry/VcapApplicationListenerTests.java | 3 +++ 2 files changed, 6 insertions(+) diff --git a/spring-boot/src/main/java/org/springframework/boot/cloudfoundry/VcapApplicationListener.java b/spring-boot/src/main/java/org/springframework/boot/cloudfoundry/VcapApplicationListener.java index 116d5f54cf9..58fc2b0844e 100644 --- a/spring-boot/src/main/java/org/springframework/boot/cloudfoundry/VcapApplicationListener.java +++ b/spring-boot/src/main/java/org/springframework/boot/cloudfoundry/VcapApplicationListener.java @@ -211,6 +211,9 @@ public class VcapApplicationListener implements else if (value instanceof Number) { properties.put(key, value.toString()); } + else if (value instanceof Boolean) { + properties.put(key, value.toString()); + } else if (value instanceof Map) { // Need a compound key @SuppressWarnings("unchecked") diff --git a/spring-boot/src/test/java/org/springframework/boot/cloudfoundry/VcapApplicationListenerTests.java b/spring-boot/src/test/java/org/springframework/boot/cloudfoundry/VcapApplicationListenerTests.java index 6e1e9986d24..74b9a75c2f5 100644 --- a/spring-boot/src/test/java/org/springframework/boot/cloudfoundry/VcapApplicationListenerTests.java +++ b/spring-boot/src/test/java/org/springframework/boot/cloudfoundry/VcapApplicationListenerTests.java @@ -111,12 +111,15 @@ public class VcapApplicationListenerTests { + "\"plan\":\"10mb\",\"credentials\":{" + "\"name\":\"d04fb13d27d964c62b267bbba1cffb9da\"," + "\"hostname\":\"mysql-service-public.clqg2e2w3ecf.us-east-1.rds.amazonaws.com\"," + + "\"ssl\":true,\"location\":null," + "\"host\":\"mysql-service-public.clqg2e2w3ecf.us-east-1.rds.amazonaws.com\"," + "\"port\":3306,\"user\":\"urpRuqTf8Cpe6\",\"username\":" + "\"urpRuqTf8Cpe6\",\"password\":\"pxLsGVpsC9A5S\"}}]}"); this.initializer.onApplicationEvent(this.event); assertEquals("mysql", getProperty("vcap.services.mysql.name")); assertEquals("3306", getProperty("vcap.services.mysql.credentials.port")); + assertEquals("true", getProperty("vcap.services.mysql.credentials.ssl")); + assertEquals("", getProperty("vcap.services.mysql.credentials.location")); } @Test