@@ -36,8 +36,9 @@ public class Configuration {
36
36
private static final Map <String ,YAMLData > YAML_DATA = new ConcurrentHashMap <>();
37
37
38
38
private static final String ENV_REPLACE_STRING = "{env}" ;
39
-
40
- private static Properties appProps = new Properties ();
39
+ private static final String ENV = "env" ;
40
+
41
+ private static final Properties appProps = new Properties ();
41
42
42
43
private static ConfigurationData sentinelConfigurations = null ;
43
44
@@ -79,8 +80,8 @@ private static String getOrCreateConfigurationData(String configurationKey) {
79
80
throw new FileException (errorMessage , e , CONFIGURATION_FILE );
80
81
}
81
82
}
82
-
83
- return sentinelConfigurations .getConfigurationValue (environment (), configurationKey );
83
+
84
+ return sentinelConfigurations .getConfigurationValue (environment (), configurationKey );
84
85
}
85
86
86
87
/**
@@ -100,20 +101,25 @@ private static String getOrCreateConfigurationData(String configurationKey) {
100
101
public static String toString (String property ) {
101
102
String propertyValue = appProps .getProperty (property );
102
103
104
+ if (propertyValue == null )
105
+ propertyValue = System .getProperty (property );
106
+
103
107
if (propertyValue == null ) {
104
108
try {
105
- propertyValue = System .getProperty (property );
106
- if (propertyValue == null ) {
107
- propertyValue = getOrCreateConfigurationData (property );
109
+ if (property .contentEquals (ENV )) {
110
+ String warningMessage = "Configuration value 'env' not found in runtime or command-line configuration. Default value will be used." ;
111
+ log .warn (warningMessage );
112
+ return null ;
108
113
}
109
- appProps .setProperty (property , propertyValue );
110
- return propertyValue ;
114
+ propertyValue = getOrCreateConfigurationData (property );
111
115
} catch (FileException e ) {
112
- log .trace (e .getMessage (),Arrays .toString (e .getStackTrace ()));
116
+ log .trace (e .getMessage (), Arrays .toString (e .getStackTrace ()));
113
117
return null ;
114
118
}
115
119
}
116
-
120
+
121
+ if (propertyValue != null )
122
+ appProps .setProperty (property , propertyValue );
117
123
return propertyValue ;
118
124
}
119
125
@@ -136,11 +142,10 @@ public static String toString(String property, String defaultValue) {
136
142
String propertyValue = toString (property );
137
143
if (propertyValue == null ) {
138
144
appProps .setProperty (property , defaultValue );
139
- if (property .contentEquals ("env" )) {
140
- String warningMessage = SentinelStringUtils .format ("localhost env being used by default. {}" ,
141
- Configuration .configurationNotFoundErrorMessage ("env" ));
142
- log .warn (warningMessage );
143
- }
145
+ String warningMessage = SentinelStringUtils .format ("{} being used by default for configuration property {}. {}" ,
146
+ defaultValue , property , Configuration .configurationNotFoundErrorMessage (property ));
147
+ log .warn (warningMessage );
148
+
144
149
return defaultValue ;
145
150
}
146
151
return propertyValue ;
@@ -166,6 +171,11 @@ public static void update(String property, String value) {
166
171
public static void clear (String property ) {
167
172
appProps .remove (property );
168
173
}
174
+
175
+ /**
176
+ * Clears all configuration values that have been set since runtime started.
177
+ */
178
+ public static void clearAllSessionAppProps () { appProps .clear (); }
169
179
170
180
/**
171
181
* Returns the given configuration value stored in the passed property as a Double, or 0.0 if nothing is
@@ -251,7 +261,7 @@ public static void update(String property, long value) {
251
261
* @return String text of system env info
252
262
*/
253
263
public static String environment () {
254
- return toString ("env" , "localhost" );
264
+ return toString (ENV , "localhost" );
255
265
}
256
266
257
267
/**
@@ -547,7 +557,12 @@ public static String[] getPageParts(String pageName) {
547
557
* @return String the formatted error message
548
558
*/
549
559
private static String configurationNotFoundErrorMessage (String configurtaionValue ) {
550
- return SentinelStringUtils .format ("No {} property set. This can be set in the sentinel.yml config file with a '{}=' property or on the command line with the switch '-D{}='." , configurtaionValue , configurtaionValue , configurtaionValue );
560
+ if (configurtaionValue .equalsIgnoreCase (ENV ))
561
+ return SentinelStringUtils .format ("No {} property set. This can be set on the command line with the switch '-D{}='." ,
562
+ configurtaionValue );
563
+ else
564
+ return SentinelStringUtils .format ("No {} property set. This can be set in the sentinel.yml config file with a '{}=' property or on the command line with the switch '-D{}='." ,
565
+ configurtaionValue , configurtaionValue , configurtaionValue );
551
566
}
552
567
553
568
/**
0 commit comments