Avoid creation of unnecessary logger instances in web request abstraction

Closes gh-25900
This commit is contained in:
Juergen Hoeller
2020-10-13 00:06:38 +02:00
parent 37e35b37d4
commit 1b63c31722
6 changed files with 14 additions and 29 deletions

View File

@@ -22,11 +22,8 @@ import java.net.URLDecoder;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.apache.commons.logging.Log;
import org.springframework.http.HttpCookie;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpLogging;
import org.springframework.http.server.RequestPath;
import org.springframework.lang.Nullable;
import org.springframework.util.CollectionUtils;
@@ -46,8 +43,6 @@ public abstract class AbstractServerHttpRequest implements ServerHttpRequest {
private static final Pattern QUERY_PATTERN = Pattern.compile("([^&=]+)(=?)([^&]+)?");
protected final Log logger = HttpLogging.forLogName(getClass());
private final URI uri;
private final RequestPath path;
@@ -156,10 +151,7 @@ public abstract class AbstractServerHttpRequest implements ServerHttpRequest {
return URLDecoder.decode(value, "UTF-8");
}
catch (UnsupportedEncodingException ex) {
if (logger.isWarnEnabled()) {
logger.warn(getLogPrefix() + "Could not decode query value [" + value + "] as 'UTF-8'. " +
"Falling back on default encoding: " + ex.getMessage());
}
// Should never happen but we got a platform default fallback anyway.
return URLDecoder.decode(value);
}
}

View File

@@ -21,7 +21,6 @@ import java.util.List;
import java.util.concurrent.atomic.AtomicReference;
import java.util.function.Supplier;
import org.apache.commons.logging.Log;
import org.reactivestreams.Publisher;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
@@ -31,7 +30,6 @@ import org.springframework.core.io.buffer.DataBufferFactory;
import org.springframework.core.io.buffer.DataBufferUtils;
import org.springframework.core.io.buffer.PooledDataBuffer;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpLogging;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseCookie;
import org.springframework.lang.Nullable;
@@ -59,8 +57,6 @@ public abstract class AbstractServerHttpResponse implements ServerHttpResponse {
*/
private enum State {NEW, COMMITTING, COMMIT_ACTION_FAILED, COMMITTED}
protected final Log logger = HttpLogging.forLogName(getClass());
private final DataBufferFactory dataBufferFactory;

View File

@@ -359,10 +359,7 @@ class ServletServerHttpResponse extends AbstractListenerServerHttpResponse {
if (ready && remaining > 0) {
// In case of IOException, onError handling should call discardData(DataBuffer)..
int written = writeToOutputStream(dataBuffer);
if (logger.isTraceEnabled()) {
logger.trace(getLogPrefix() + "Wrote " + written + " of " + remaining + " bytes");
}
else if (rsWriteLogger.isTraceEnabled()) {
if (rsWriteLogger.isTraceEnabled()) {
rsWriteLogger.trace(getLogPrefix() + "Wrote " + written + " of " + remaining + " bytes");
}
if (written == remaining) {

View File

@@ -205,10 +205,7 @@ class UndertowServerHttpResponse extends AbstractListenerServerHttpResponse impl
int total = buffer.remaining();
int written = writeByteBuffer(buffer);
if (logger.isTraceEnabled()) {
logger.trace(getLogPrefix() + "Wrote " + written + " of " + total + " bytes");
}
else if (rsWriteLogger.isTraceEnabled()) {
if (rsWriteLogger.isTraceEnabled()) {
rsWriteLogger.trace(getLogPrefix() + "Wrote " + written + " of " + total + " bytes");
}
if (written != total) {

View File

@@ -35,6 +35,7 @@ import org.springframework.core.ResolvableType;
import org.springframework.core.annotation.AnnotatedElementUtils;
import org.springframework.core.annotation.SynthesizingMethodParameter;
import org.springframework.http.HttpStatus;
import org.springframework.lang.NonNull;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
import org.springframework.util.ClassUtils;
@@ -62,7 +63,7 @@ import org.springframework.web.bind.annotation.ResponseStatus;
public class HandlerMethod {
/** Logger that is available to subclasses. */
protected final Log logger = LogFactory.getLog(getClass());
protected static final Log logger = LogFactory.getLog(HandlerMethod.class);
private final Object bean;
@@ -473,6 +474,12 @@ public class HandlerMethod {
super(original);
}
@Override
@NonNull
public Method getMethod() {
return HandlerMethod.this.bridgedMethod;
}
@Override
public Class<?> getContainingClass() {
return HandlerMethod.this.getBeanType();

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2018 the original author or authors.
* Copyright 2002-2020 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.
@@ -20,15 +20,13 @@ import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.core.MethodParameter;
import org.springframework.lang.Nullable;
import org.springframework.web.context.request.NativeWebRequest;
/**
* Handles method return values by delegating to a list of registered {@link HandlerMethodReturnValueHandler HandlerMethodReturnValueHandlers}.
* Handles method return values by delegating to a list of registered
* {@link HandlerMethodReturnValueHandler HandlerMethodReturnValueHandlers}.
* Previously resolved return types are cached for faster lookups.
*
* @author Rossen Stoyanchev
@@ -36,8 +34,6 @@ import org.springframework.web.context.request.NativeWebRequest;
*/
public class HandlerMethodReturnValueHandlerComposite implements HandlerMethodReturnValueHandler {
protected final Log logger = LogFactory.getLog(getClass());
private final List<HandlerMethodReturnValueHandler> returnValueHandlers = new ArrayList<>();