Skip to content

Commit 6653966

Browse files
committed
Refactor improvements
1 parent f190e1e commit 6653966

4 files changed

Lines changed: 13 additions & 3 deletions

File tree

microprofile/src/main/java/io/smallrye/stork/microprofile/MicroProfileConfigProvider.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,12 @@ public MicroProfileConfigProvider() {
3535
for (String propertyName : config.getPropertyNames()) {
3636
if (propertyName.startsWith(Stork.STORK + ".")) {
3737
config.getOptionalValue(propertyName, String.class)
38+
.map(String::trim)
39+
.filter(value -> !value.isEmpty())
3840
.ifPresentOrElse(
3941
value -> StorkConfigUtils.computeServiceProperty(propertiesByServiceName,
4042
propertyName, value),
41-
() -> log.debug("Ignoring empty Stork config property: {}", propertyName));
43+
() -> log.debug("Ignoring empty stork config property: {}", propertyName));
4244
}
4345
}
4446

microprofile/src/test/java/io/smallrye/stork/microprofile/MicroProfileConfigProviderTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,7 @@ void shouldFilterNonStorkPropertiesAndIgnoreEmptyValues() {
239239
properties.put("stork." + FIRST_SERVICE + ".service-discovery", "test-sd-1");
240240
properties.put("stork." + FIRST_SERVICE + ".service-discovery.one", "http://localhost:8080");
241241
properties.put("stork." + FIRST_SERVICE + ".service-discovery.two", "");
242+
properties.put("stork." + FIRST_SERVICE + ".service-discovery.three", " ");
242243
properties.put("user.script", "");
243244
properties.put("some.other.property", "");
244245
properties.put("non.stork.property", "some-value");

spring-boot/src/main/java/io/smallrye/stork/springboot/SpringBootConfigProvider.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
import java.util.List;
66
import java.util.Map;
77

8+
import org.slf4j.Logger;
9+
import org.slf4j.LoggerFactory;
810
import org.springframework.context.ApplicationContext;
911
import org.springframework.core.env.ConfigurableEnvironment;
1012
import org.springframework.core.env.EnumerablePropertySource;
@@ -18,6 +20,8 @@
1820

1921
public class SpringBootConfigProvider implements ConfigProvider {
2022

23+
private static final Logger log = LoggerFactory.getLogger(SpringBootConfigProvider.class);
24+
2125
private final List<ServiceConfig> serviceConfigs = new ArrayList<>();
2226

2327
public SpringBootConfigProvider() {
@@ -29,8 +33,10 @@ public SpringBootConfigProvider() {
2933
for (String propertyName : getPropertyNames(environment)) {
3034
if (propertyName.startsWith(Stork.STORK + ".")) {
3135
String value = environment.getProperty(propertyName);
32-
if (value != null && !value.isEmpty()) {
33-
StorkConfigUtils.computeServiceProperty(propertiesByServiceName, propertyName, value);
36+
if (value != null && !value.trim().isEmpty()) {
37+
StorkConfigUtils.computeServiceProperty(propertiesByServiceName, propertyName, value.trim());
38+
} else {
39+
log.debug("Ignoring empty stork config property: {}", propertyName);
3440
}
3541
}
3642
}

spring-boot/src/test/java/io/smallrye/stork/microprofile/SpringBootConfigProviderTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,7 @@ void shouldFilterNonStorkPropertiesAndIgnoreEmptyValues() {
243243
properties.put("stork." + FIRST_SERVICE + ".service-discovery", "test-sd-1");
244244
properties.put("stork." + FIRST_SERVICE + ".service-discovery.one", "http://localhost:8080");
245245
properties.put("stork." + FIRST_SERVICE + ".service-discovery.two", "");
246+
properties.put("stork." + FIRST_SERVICE + ".service-discovery.three", " ");
246247
properties.put("user.script", "");
247248
properties.put("some.other.property", "");
248249
properties.put("non.stork.property", "some-value");

0 commit comments

Comments
 (0)