Skip to content

Commit

Permalink
Polish
Browse files Browse the repository at this point in the history
  • Loading branch information
philwebb committed Apr 3, 2019
1 parent 8ad9bfe commit 34fee1a
Show file tree
Hide file tree
Showing 7 changed files with 75 additions and 28 deletions.
Expand Up @@ -112,12 +112,7 @@ static class CustomConfigConfiguration {

@Bean
public AppOpticsConfig customConfig() {
return (key) -> {
if ("appoptics.apiToken".equals(key)) {
return "abcde";
}
return null;
};
return (key) -> "appoptics.apiToken".equals(key) ? "abcde" : null;
}

}
Expand Down
Expand Up @@ -324,7 +324,6 @@ protected static class FlywayInitializerJdbcOperationsDependencyConfiguration

public FlywayInitializerJdbcOperationsDependencyConfiguration() {
super("flywayInitializer");

}

}
Expand Down
Expand Up @@ -138,8 +138,8 @@ private static Validator getExisting(ApplicationContext applicationContext) {
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
Expand Down
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -268,15 +273,15 @@ public Mono<Void> handle(ServerWebExchange exchange, Throwable throwable) {
}

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());
return DISCONNECTED_CLIENT_EXCEPTIONS.contains(ex.getClass().getSimpleName())
|| isDisconnectedClientErrorMessage(
NestedExceptionUtils.getMostSpecificCause(ex).getMessage());
}

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,
Expand Down
@@ -0,0 +1,42 @@
/*
* 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);
}

}
Expand Up @@ -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");
Expand Down Expand Up @@ -320,10 +319,17 @@ private void initializeFinalLoggingLevels(ConfigurableEnvironment environment,
}

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) {
Expand Down
Expand Up @@ -263,7 +263,7 @@ public void parseDebugArg() {
}

@Test
public void parseDebugArgExpandGroups() {
public void parseDebugArgExpandsGroups() {
TestPropertySourceUtils.addInlinedPropertiesToEnvironment(this.context, "debug");
this.initializer.initialize(this.context.getEnvironment(),
this.context.getClassLoader());
Expand Down

0 comments on commit 34fee1a

Please sign in to comment.