Commit 34fee1ad authored by Phillip Webb's avatar Phillip Webb

Polish

parent 8ad9bfe2
...@@ -112,12 +112,7 @@ public class AppOpticsMetricsExportAutoConfigurationTests { ...@@ -112,12 +112,7 @@ public class AppOpticsMetricsExportAutoConfigurationTests {
@Bean @Bean
public AppOpticsConfig customConfig() { public AppOpticsConfig customConfig() {
return (key) -> { return (key) -> "appoptics.apiToken".equals(key) ? "abcde" : null;
if ("appoptics.apiToken".equals(key)) {
return "abcde";
}
return null;
};
} }
} }
......
...@@ -324,7 +324,6 @@ public class FlywayAutoConfiguration { ...@@ -324,7 +324,6 @@ public class FlywayAutoConfiguration {
public FlywayInitializerJdbcOperationsDependencyConfiguration() { public FlywayInitializerJdbcOperationsDependencyConfiguration() {
super("flywayInitializer"); super("flywayInitializer");
} }
} }
......
...@@ -138,8 +138,8 @@ public class ValidatorAdapter implements SmartValidator, ApplicationContextAware ...@@ -138,8 +138,8 @@ public class ValidatorAdapter implements SmartValidator, ApplicationContextAware
private static Validator create() { private static Validator create() {
OptionalValidatorFactoryBean validator = new OptionalValidatorFactoryBean(); OptionalValidatorFactoryBean validator = new OptionalValidatorFactoryBean();
try { try {
validator MessageInterpolatorFactory factory = new MessageInterpolatorFactory();
.setMessageInterpolator(new MessageInterpolatorFactory().getObject()); validator.setMessageInterpolator(factory.getObject());
} }
catch (ValidationException ex) { catch (ValidationException ex) {
// Ignore // Ignore
......
...@@ -16,7 +16,6 @@ ...@@ -16,7 +16,6 @@
package org.springframework.boot.autoconfigure.web.reactive.error; package org.springframework.boot.autoconfigure.web.reactive.error;
import java.util.Arrays;
import java.util.Collections; import java.util.Collections;
import java.util.Date; import java.util.Date;
import java.util.HashSet; import java.util.HashSet;
...@@ -63,9 +62,15 @@ public abstract class AbstractErrorWebExceptionHandler ...@@ -63,9 +62,15 @@ public abstract class AbstractErrorWebExceptionHandler
/** /**
* Currently duplicated from Spring WebFlux HttpWebHandlerAdapter. * Currently duplicated from Spring WebFlux HttpWebHandlerAdapter.
*/ */
private static final Set<String> DISCONNECTED_CLIENT_EXCEPTIONS = new HashSet<>( private static final Set<String> DISCONNECTED_CLIENT_EXCEPTIONS;
Arrays.asList("AbortedException", "ClientAbortException", "EOFException", static {
"EofException")); Set<String> exceptions = new HashSet<>();
exceptions.add("AbortedException");
exceptions.add("ClientAbortException");
exceptions.add("EOFException");
exceptions.add("EofException");
DISCONNECTED_CLIENT_EXCEPTIONS = Collections.unmodifiableSet(exceptions);
}
private static final Log logger = HttpLogging private static final Log logger = HttpLogging
.forLogName(AbstractErrorWebExceptionHandler.class); .forLogName(AbstractErrorWebExceptionHandler.class);
...@@ -268,15 +273,15 @@ public abstract class AbstractErrorWebExceptionHandler ...@@ -268,15 +273,15 @@ public abstract class AbstractErrorWebExceptionHandler
} }
private boolean isDisconnectedClientError(Throwable ex) { private boolean isDisconnectedClientError(Throwable ex) {
String message = NestedExceptionUtils.getMostSpecificCause(ex).getMessage(); return DISCONNECTED_CLIENT_EXCEPTIONS.contains(ex.getClass().getSimpleName())
if (message != null) { || isDisconnectedClientErrorMessage(
String text = message.toLowerCase(); NestedExceptionUtils.getMostSpecificCause(ex).getMessage());
if (text.contains("broken pipe") }
|| text.contains("connection reset by peer")) {
return true; private boolean isDisconnectedClientErrorMessage(String message) {
} message = message != null ? message.toLowerCase() : "";
} return (message.contains("broken pipe")
return DISCONNECTED_CLIENT_EXCEPTIONS.contains(ex.getClass().getSimpleName()); || message.contains("connection reset by peer"));
} }
private void logError(ServerRequest request, ServerResponse response, private void logError(ServerRequest request, ServerResponse response,
......
/*
* Copyright 2012-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.boot.autoconfigure.web.reactive.error;
import org.junit.Test;
import org.springframework.test.util.ReflectionTestUtils;
import org.springframework.web.server.adapter.HttpWebHandlerAdapter;
import static org.assertj.core.api.Assertions.assertThat;
/**
* Tests for {@link AbstractErrorWebExceptionHandler}.
*
* @author Phillip Webb
*/
public class DefaultErrorWebExceptionHandlerTests {
@Test
public void disconnectedClientExceptionsMatchesFramework() {
Object errorHandlers = ReflectionTestUtils.getField(
AbstractErrorWebExceptionHandler.class, "DISCONNECTED_CLIENT_EXCEPTIONS");
Object webHandlers = ReflectionTestUtils.getField(HttpWebHandlerAdapter.class,
"DISCONNECTED_CLIENT_EXCEPTIONS");
assertThat(errorHandlers).isNotNull().isEqualTo(webHandlers);
}
}
...@@ -139,7 +139,6 @@ public class LoggingApplicationListener implements GenericApplicationListener { ...@@ -139,7 +139,6 @@ public class LoggingApplicationListener implements GenericApplicationListener {
} }
private static final Map<LogLevel, List<String>> LOG_LEVEL_LOGGERS; private static final Map<LogLevel, List<String>> LOG_LEVEL_LOGGERS;
static { static {
MultiValueMap<LogLevel, String> loggers = new LinkedMultiValueMap<>(); MultiValueMap<LogLevel, String> loggers = new LinkedMultiValueMap<>();
loggers.add(LogLevel.DEBUG, "sql"); loggers.add(LogLevel.DEBUG, "sql");
...@@ -320,10 +319,17 @@ public class LoggingApplicationListener implements GenericApplicationListener { ...@@ -320,10 +319,17 @@ public class LoggingApplicationListener implements GenericApplicationListener {
} }
protected void initializeLogLevel(LoggingSystem system, LogLevel level) { protected void initializeLogLevel(LoggingSystem system, LogLevel level) {
LOG_LEVEL_LOGGERS.getOrDefault(level, Collections.emptyList()).stream() LOG_LEVEL_LOGGERS.getOrDefault(level, Collections.emptyList())
.flatMap((logger) -> DEFAULT_GROUP_LOGGERS .forEach((logger) -> initializeLogLevel(system, level, logger));
.getOrDefault(logger, Collections.singletonList(logger)).stream()) }
.forEach((logger) -> system.setLogLevel(logger, level));
private void initializeLogLevel(LoggingSystem system, LogLevel level, String logger) {
List<String> groupLoggers = DEFAULT_GROUP_LOGGERS.get(logger);
if (groupLoggers == null) {
system.setLogLevel(logger, level);
return;
}
groupLoggers.forEach((groupLogger) -> system.setLogLevel(groupLogger, level));
} }
protected void setLogLevels(LoggingSystem system, Environment environment) { protected void setLogLevels(LoggingSystem system, Environment environment) {
......
...@@ -263,7 +263,7 @@ public class LoggingApplicationListenerTests { ...@@ -263,7 +263,7 @@ public class LoggingApplicationListenerTests {
} }
@Test @Test
public void parseDebugArgExpandGroups() { public void parseDebugArgExpandsGroups() {
TestPropertySourceUtils.addInlinedPropertiesToEnvironment(this.context, "debug"); TestPropertySourceUtils.addInlinedPropertiesToEnvironment(this.context, "debug");
this.initializer.initialize(this.context.getEnvironment(), this.initializer.initialize(this.context.getEnvironment(),
this.context.getClassLoader()); this.context.getClassLoader());
......
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