Avoid creating JsonParser for VCAP_* parsing when running outside CF

Closes gh-13437
pull/13572/head
Andy Wilkinson 6 years ago
parent 8dbeb68afa
commit 9281e2a410

@ -101,8 +101,6 @@ public class CloudFoundryVcapEnvironmentPostProcessor
// Before ConfigFileApplicationListener so values there can use these ones // Before ConfigFileApplicationListener so values there can use these ones
private int order = ConfigFileApplicationListener.DEFAULT_ORDER - 1; private int order = ConfigFileApplicationListener.DEFAULT_ORDER - 1;
private final JsonParser parser = JsonParserFactory.getJsonParser();
public void setOrder(int order) { public void setOrder(int order) {
this.order = order; this.order = order;
} }
@ -117,9 +115,11 @@ public class CloudFoundryVcapEnvironmentPostProcessor
SpringApplication application) { SpringApplication application) {
if (CloudPlatform.CLOUD_FOUNDRY.isActive(environment)) { if (CloudPlatform.CLOUD_FOUNDRY.isActive(environment)) {
Properties properties = new Properties(); Properties properties = new Properties();
addWithPrefix(properties, getPropertiesFromApplication(environment), JsonParser jsonParser = JsonParserFactory.getJsonParser();
addWithPrefix(properties,
getPropertiesFromApplication(environment, jsonParser),
"vcap.application."); "vcap.application.");
addWithPrefix(properties, getPropertiesFromServices(environment), addWithPrefix(properties, getPropertiesFromServices(environment, jsonParser),
"vcap.services."); "vcap.services.");
MutablePropertySources propertySources = environment.getPropertySources(); MutablePropertySources propertySources = environment.getPropertySources();
if (propertySources.contains( if (propertySources.contains(
@ -142,11 +142,12 @@ public class CloudFoundryVcapEnvironmentPostProcessor
} }
} }
private Properties getPropertiesFromApplication(Environment environment) { private Properties getPropertiesFromApplication(Environment environment,
JsonParser parser) {
Properties properties = new Properties(); Properties properties = new Properties();
try { try {
String property = environment.getProperty(VCAP_APPLICATION, "{}"); String property = environment.getProperty(VCAP_APPLICATION, "{}");
Map<String, Object> map = this.parser.parseMap(property); Map<String, Object> map = parser.parseMap(property);
extractPropertiesFromApplication(properties, map); extractPropertiesFromApplication(properties, map);
} }
catch (Exception ex) { catch (Exception ex) {
@ -155,11 +156,12 @@ public class CloudFoundryVcapEnvironmentPostProcessor
return properties; return properties;
} }
private Properties getPropertiesFromServices(Environment environment) { private Properties getPropertiesFromServices(Environment environment,
JsonParser parser) {
Properties properties = new Properties(); Properties properties = new Properties();
try { try {
String property = environment.getProperty(VCAP_SERVICES, "{}"); String property = environment.getProperty(VCAP_SERVICES, "{}");
Map<String, Object> map = this.parser.parseMap(property); Map<String, Object> map = parser.parseMap(property);
extractPropertiesFromServices(properties, map); extractPropertiesFromServices(properties, map);
} }
catch (Exception ex) { catch (Exception ex) {

Loading…
Cancel
Save