Commit 6009f417 authored by Phillip Webb's avatar Phillip Webb

Polish

parent 7e842aee
...@@ -52,7 +52,6 @@ import org.springframework.expression.spel.standard.SpelExpressionParser; ...@@ -52,7 +52,6 @@ import org.springframework.expression.spel.standard.SpelExpressionParser;
import org.springframework.expression.spel.support.StandardEvaluationContext; import org.springframework.expression.spel.support.StandardEvaluationContext;
import org.springframework.util.PropertyPlaceholderHelper; import org.springframework.util.PropertyPlaceholderHelper;
import org.springframework.util.PropertyPlaceholderHelper.PlaceholderResolver; import org.springframework.util.PropertyPlaceholderHelper.PlaceholderResolver;
import org.springframework.web.bind.ServletRequestUtils;
import org.springframework.web.servlet.DispatcherServlet; import org.springframework.web.servlet.DispatcherServlet;
import org.springframework.web.servlet.View; import org.springframework.web.servlet.View;
import org.springframework.web.servlet.view.BeanNameViewResolver; import org.springframework.web.servlet.view.BeanNameViewResolver;
...@@ -107,7 +106,7 @@ public class ErrorMvcAutoConfiguration implements EmbeddedServletContainerCustom ...@@ -107,7 +106,7 @@ public class ErrorMvcAutoConfiguration implements EmbeddedServletContainerCustom
+ "<p>This application has no explicit mapping for /error, so you are seeing this as a fallback.</p>" + "<p>This application has no explicit mapping for /error, so you are seeing this as a fallback.</p>"
+ "<div id='created'>${timestamp}</div>" + "<div id='created'>${timestamp}</div>"
+ "<div>There was an unexpected error (type=${error}, status=${status}).</div>" + "<div>There was an unexpected error (type=${error}, status=${status}).</div>"
+ "<div>${message}</div>" + "</body></html>"); + "<div>${message}</div></body></html>");
@Bean(name = "error") @Bean(name = "error")
@ConditionalOnMissingBean(name = "error") @ConditionalOnMissingBean(name = "error")
...@@ -157,8 +156,6 @@ public class ErrorMvcAutoConfiguration implements EmbeddedServletContainerCustom ...@@ -157,8 +156,6 @@ public class ErrorMvcAutoConfiguration implements EmbeddedServletContainerCustom
private final String template; private final String template;
private final SpelExpressionParser parser = new SpelExpressionParser();
private final StandardEvaluationContext context = new StandardEvaluationContext(); private final StandardEvaluationContext context = new StandardEvaluationContext();
private PropertyPlaceholderHelper helper; private PropertyPlaceholderHelper helper;
...@@ -169,19 +166,7 @@ public class ErrorMvcAutoConfiguration implements EmbeddedServletContainerCustom ...@@ -169,19 +166,7 @@ public class ErrorMvcAutoConfiguration implements EmbeddedServletContainerCustom
this.template = template; this.template = template;
this.context.addPropertyAccessor(new MapAccessor()); this.context.addPropertyAccessor(new MapAccessor());
this.helper = new PropertyPlaceholderHelper("${", "}"); this.helper = new PropertyPlaceholderHelper("${", "}");
this.resolver = new PlaceholderResolver() { this.resolver = new SpelPlaceholderResolver(this.context);
@Override
public String resolvePlaceholder(String name) {
Expression expression = SpelView.this.parser.parseExpression(name);
try {
Object value = expression.getValue(SpelView.this.context);
return (value == null ? null : HtmlUtils.htmlEscape(value.toString()));
}
catch (Exception ex) {
return null;
}
}
};
} }
@Override @Override
...@@ -204,4 +189,31 @@ public class ErrorMvcAutoConfiguration implements EmbeddedServletContainerCustom ...@@ -204,4 +189,31 @@ public class ErrorMvcAutoConfiguration implements EmbeddedServletContainerCustom
} }
/**
* SpEL based {@link PlaceholderResolver}.
*/
private static class SpelPlaceholderResolver implements PlaceholderResolver {
private final SpelExpressionParser parser = new SpelExpressionParser();
private final StandardEvaluationContext context;
public SpelPlaceholderResolver(StandardEvaluationContext context) {
this.context = context;
}
@Override
public String resolvePlaceholder(String name) {
Expression expression = this.parser.parseExpression(name);
try {
Object value = expression.getValue(this.context);
return HtmlUtils.htmlEscape(value == null ? null : value.toString());
}
catch (Exception ex) {
return null;
}
}
}
} }
...@@ -222,18 +222,21 @@ public class LoggingApplicationListener implements SmartApplicationListener { ...@@ -222,18 +222,21 @@ public class LoggingApplicationListener implements SmartApplicationListener {
Map<String, Object> levels = new RelaxedPropertyResolver(environment) Map<String, Object> levels = new RelaxedPropertyResolver(environment)
.getSubProperties("logging.level."); .getSubProperties("logging.level.");
for (Entry<String, Object> entry : levels.entrySet()) { for (Entry<String, Object> entry : levels.entrySet()) {
String name = entry.getKey(); setLogLevel(system, environment, entry.getKey(), entry.getValue().toString());
try { }
LogLevel level = LogLevel.valueOf(environment.resolvePlaceholders(entry.getValue().toString())); }
if (name.equalsIgnoreCase("root")) {
name = null; private void setLogLevel(LoggingSystem system, Environment environment, String name,
} String level) {
system.setLogLevel(name, level); try {
} if (name.equalsIgnoreCase("root")) {
catch (RuntimeException e) { name = null;
this.logger.error("Cannot set level: " + entry.getValue() + " for '"
+ name + "'");
} }
level = environment.resolvePlaceholders(level);
system.setLogLevel(name, LogLevel.valueOf(level));
}
catch (RuntimeException ex) {
this.logger.error("Cannot set level: " + level + " for '" + name + "'");
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment