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

Polish

parent 8ad9bfe2
......@@ -112,12 +112,7 @@ public class AppOpticsMetricsExportAutoConfigurationTests {
@Bean
public AppOpticsConfig customConfig() {
return (key) -> {
if ("appoptics.apiToken".equals(key)) {
return "abcde";
}
return null;
};
return (key) -> "appoptics.apiToken".equals(key) ? "abcde" : null;
}
}
......
......@@ -324,7 +324,6 @@ public class FlywayAutoConfiguration {
public FlywayInitializerJdbcOperationsDependencyConfiguration() {
super("flywayInitializer");
}
}
......
......@@ -138,8 +138,8 @@ public class ValidatorAdapter implements SmartValidator, ApplicationContextAware
private static Validator create() {
OptionalValidatorFactoryBean validator = new OptionalValidatorFactoryBean();
try {
validator
.setMessageInterpolator(new MessageInterpolatorFactory().getObject());
MessageInterpolatorFactory factory = new MessageInterpolatorFactory();
validator.setMessageInterpolator(factory.getObject());
}
catch (ValidationException ex) {
// Ignore
......
......@@ -16,7 +16,6 @@
package org.springframework.boot.autoconfigure.web.reactive.error;
import java.util.Arrays;
import java.util.Collections;
import java.util.Date;
import java.util.HashSet;
......@@ -63,9 +62,15 @@ public abstract class AbstractErrorWebExceptionHandler
/**
* Currently duplicated from Spring WebFlux HttpWebHandlerAdapter.
*/
private static final Set<String> DISCONNECTED_CLIENT_EXCEPTIONS = new HashSet<>(
Arrays.asList("AbortedException", "ClientAbortException", "EOFException",
"EofException"));
private static final Set<String> DISCONNECTED_CLIENT_EXCEPTIONS;
static {
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
.forLogName(AbstractErrorWebExceptionHandler.class);
......@@ -268,15 +273,15 @@ public abstract class AbstractErrorWebExceptionHandler
}
private boolean isDisconnectedClientError(Throwable ex) {
String message = NestedExceptionUtils.getMostSpecificCause(ex).getMessage();
if (message != null) {
String text = message.toLowerCase();
if (text.contains("broken pipe")
|| text.contains("connection reset by peer")) {
return true;
return DISCONNECTED_CLIENT_EXCEPTIONS.contains(ex.getClass().getSimpleName())
|| isDisconnectedClientErrorMessage(
NestedExceptionUtils.getMostSpecificCause(ex).getMessage());
}
}
return DISCONNECTED_CLIENT_EXCEPTIONS.contains(ex.getClass().getSimpleName());
private boolean isDisconnectedClientErrorMessage(String message) {
message = message != null ? message.toLowerCase() : "";
return (message.contains("broken pipe")
|| message.contains("connection reset by peer"));
}
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 {
}
private static final Map<LogLevel, List<String>> LOG_LEVEL_LOGGERS;
static {
MultiValueMap<LogLevel, String> loggers = new LinkedMultiValueMap<>();
loggers.add(LogLevel.DEBUG, "sql");
......@@ -320,10 +319,17 @@ public class LoggingApplicationListener implements GenericApplicationListener {
}
protected void initializeLogLevel(LoggingSystem system, LogLevel level) {
LOG_LEVEL_LOGGERS.getOrDefault(level, Collections.emptyList()).stream()
.flatMap((logger) -> DEFAULT_GROUP_LOGGERS
.getOrDefault(logger, Collections.singletonList(logger)).stream())
.forEach((logger) -> system.setLogLevel(logger, level));
LOG_LEVEL_LOGGERS.getOrDefault(level, Collections.emptyList())
.forEach((logger) -> initializeLogLevel(system, level, logger));
}
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) {
......
......@@ -263,7 +263,7 @@ public class LoggingApplicationListenerTests {
}
@Test
public void parseDebugArgExpandGroups() {
public void parseDebugArgExpandsGroups() {
TestPropertySourceUtils.addInlinedPropertiesToEnvironment(this.context, "debug");
this.initializer.initialize(this.context.getEnvironment(),
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