Skip to content

Commit dce21fa

Browse files
requested changes
1 parent 2d53423 commit dce21fa

5 files changed

Lines changed: 14 additions & 19 deletions

File tree

annot/src/main/java/com/predic8/membrane/annot/yaml/YamlParsingUtils.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
import com.networknt.schema.SchemaRegistry;
2323
import com.predic8.membrane.annot.Grammar;
2424
import com.predic8.membrane.annot.beanregistry.BeanRegistryAware;
25-
import com.predic8.membrane.annot.yaml.spel.SpELContext;
2625
import jakarta.annotation.PostConstruct;
2726
import jakarta.annotation.PreDestroy;
2827
import org.jetbrains.annotations.NotNull;

annot/src/main/java/com/predic8/membrane/annot/yaml/spel/EnvPropertyAccessor.java

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,23 @@
11
package com.predic8.membrane.annot.yaml.spel;
22

33
import org.jetbrains.annotations.NotNull;
4+
import org.slf4j.Logger;
5+
import org.slf4j.LoggerFactory;
46
import org.springframework.expression.AccessException;
57
import org.springframework.expression.EvaluationContext;
68
import org.springframework.expression.PropertyAccessor;
79
import org.springframework.expression.TypedValue;
810

911
import static com.predic8.membrane.annot.yaml.spel.EnvPropertyAccessor.EnvVariables.INSTANCE;
1012
import static java.lang.System.getenv;
11-
import static java.util.Locale.ROOT;
1213

1314
public final class EnvPropertyAccessor implements PropertyAccessor {
1415

16+
private static final Logger LOG = LoggerFactory.getLogger(EnvPropertyAccessor.class);
17+
1518
@Override
1619
public Class<?>[] getSpecificTargetClasses() {
17-
return new Class<?>[] { SpELContext.class, EnvVariables.class };
20+
return new Class<?>[]{SpELContext.class, EnvVariables.class};
1821
}
1922

2023
@Override
@@ -29,7 +32,11 @@ public boolean canRead(@NotNull EvaluationContext context, Object target, @NotNu
2932
return new TypedValue(INSTANCE);
3033
}
3134
if (target instanceof EnvVariables) {
32-
return new TypedValue(getenv(name.toUpperCase(ROOT)));
35+
String value = getenv(name);
36+
if (value == null) {
37+
LOG.warn("Environment variable '{}' not found. Note: env lookups are case-sensitive.", name);
38+
}
39+
return new TypedValue(value);
3340
}
3441
throw new AccessException("Unsupported target: " + target);
3542
}

annot/src/main/java/com/predic8/membrane/annot/yaml/spel/SpELContext.java

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,4 @@
22

33
public class SpELContext {
44

5-
@SuppressWarnings("unused")
6-
public String env(String key) {
7-
return System.getenv(key);
8-
}
9-
10-
@SuppressWarnings("unused")
11-
public String env(String key, String defaultValue) {
12-
String v = System.getenv(key);
13-
return v != null ? v : defaultValue;
14-
}
15-
165
}

annot/src/test/java/com/predic8/membrane/annot/YAMLParsingTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -613,7 +613,7 @@ public class DemoElement {
613613
assertCompilerResult(true, result);
614614

615615
BeanRegistry br = parseYAML(result, """
616-
root: "#{env('MEMBRANE_SPEL_TEST') ?: '42'}"
616+
root: "#{env.MEMBRANE_SPEL_TEST ?: '42'}"
617617
""");
618618

619619
assertStructure(br,
@@ -641,7 +641,7 @@ public class DemoElement {
641641

642642
BeanRegistry br = parseYAML(result, """
643643
root:
644-
msg: "prefix-#{env('MEMBRANE_SPEL_TEST') ?: 'X'}-suffix"
644+
msg: "prefix-#{env.MEMBRANE_SPEL_TEST ?: 'X'}-suffix"
645645
""");
646646

647647
assertStructure(br,

distribution/tutorials/advanced/90-Environment-Variables.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# yaml-language-server: $schema=https://www.membrane-api.io/v7.0.6.json
22
#
3-
# Tutorial: Environment Variables via SpEL (#{env(...)})
3+
# Tutorial: Environment Variables via SpEL (#{env.})
44
#
55
# This tutorial shows how to use environment variables in YAML using SpEL templates:
66
# - #{env.port} reads the environment variable PORT
@@ -11,7 +11,7 @@
1111
# Windows PowerShell: $env:PORT="3000"
1212
# Windows CMD: set PORT=3000
1313
#
14-
# 2) Start membrane from the same terminal
14+
# 2) Start membrane from the same terminal so the env var is available
1515
#
1616
# 3) Try:
1717
# curl -v http://localhost:2000/

0 commit comments

Comments
 (0)