Skip to content

Commit 818d3bd

Browse files
nebhalephilwebb
authored andcommitted
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 spring-projectsgh-3237
1 parent 75ffd1b commit 818d3bd

File tree

2 files changed

+6
-0
lines changed

2 files changed

+6
-0
lines changed

spring-boot/src/main/java/org/springframework/boot/cloudfoundry/VcapApplicationListener.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,9 @@ private void flatten(Properties properties, Map<String, Object> input, String pa
211211
else if (value instanceof Number) {
212212
properties.put(key, value.toString());
213213
}
214+
else if (value instanceof Boolean) {
215+
properties.put(key, value.toString());
216+
}
214217
else if (value instanceof Map) {
215218
// Need a compound key
216219
@SuppressWarnings("unchecked")

spring-boot/src/test/java/org/springframework/boot/cloudfoundry/VcapApplicationListenerTests.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,12 +111,15 @@ public void testServiceProperties() {
111111
+ "\"plan\":\"10mb\",\"credentials\":{"
112112
+ "\"name\":\"d04fb13d27d964c62b267bbba1cffb9da\","
113113
+ "\"hostname\":\"mysql-service-public.clqg2e2w3ecf.us-east-1.rds.amazonaws.com\","
114+
+ "\"ssl\":true,\"location\":null,"
114115
+ "\"host\":\"mysql-service-public.clqg2e2w3ecf.us-east-1.rds.amazonaws.com\","
115116
+ "\"port\":3306,\"user\":\"urpRuqTf8Cpe6\",\"username\":"
116117
+ "\"urpRuqTf8Cpe6\",\"password\":\"pxLsGVpsC9A5S\"}}]}");
117118
this.initializer.onApplicationEvent(this.event);
118119
assertEquals("mysql", getProperty("vcap.services.mysql.name"));
119120
assertEquals("3306", getProperty("vcap.services.mysql.credentials.port"));
121+
assertEquals("true", getProperty("vcap.services.mysql.credentials.ssl"));
122+
assertEquals("", getProperty("vcap.services.mysql.credentials.location"));
120123
}
121124

122125
@Test

0 commit comments

Comments
 (0)