Improved logging for @MessageMapping methods
Closes gh-20564
This commit is contained in:
parent
b88aad6b39
commit
19c024f91f
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2018 the original author or authors.
|
||||
* Copyright 2002-2019 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.
|
||||
|
@ -18,6 +18,7 @@ package org.springframework.messaging.handler.invocation;
|
|||
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
|
@ -26,6 +27,8 @@ import java.util.List;
|
|||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
@ -309,12 +312,27 @@ public abstract class AbstractMethodMessageHandler<T>
|
|||
Map<Method, T> methods = MethodIntrospector.selectMethods(userType,
|
||||
(MethodIntrospector.MetadataLookup<T>) method -> getMappingForMethod(method, userType));
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug(methods.size() + " message handler methods found on " + userType + ": " + methods);
|
||||
logger.debug(formatMappings(userType, methods));
|
||||
}
|
||||
methods.forEach((key, value) -> registerHandlerMethod(handler, key, value));
|
||||
}
|
||||
}
|
||||
|
||||
private String formatMappings(Class<?> userType, Map<Method, T> methods) {
|
||||
String formattedType = Arrays.stream(ClassUtils.getPackageName(userType).split("\\."))
|
||||
.map(p -> p.substring(0, 1))
|
||||
.collect(Collectors.joining(".", "", "." + userType.getSimpleName()));
|
||||
Function<Method, String> methodFormatter = method -> Arrays.stream(method.getParameterTypes())
|
||||
.map(Class::getSimpleName)
|
||||
.collect(Collectors.joining(",", "(", ")"));
|
||||
return methods.entrySet().stream()
|
||||
.map(e -> {
|
||||
Method method = e.getKey();
|
||||
return e.getValue() + ": " + method.getName() + methodFormatter.apply(method);
|
||||
})
|
||||
.collect(Collectors.joining("\n\t", "\n\t" + formattedType + ":" + "\n\t", ""));
|
||||
}
|
||||
|
||||
/**
|
||||
* Provide the mapping for a handler method.
|
||||
* @param method the method to provide a mapping for
|
||||
|
@ -344,9 +362,6 @@ public abstract class AbstractMethodMessageHandler<T>
|
|||
}
|
||||
|
||||
this.handlerMethods.put(mapping, newHandlerMethod);
|
||||
if (logger.isTraceEnabled()) {
|
||||
logger.trace("Mapped \"" + mapping + "\" onto " + newHandlerMethod);
|
||||
}
|
||||
|
||||
for (String pattern : getDirectLookupDestinations(mapping)) {
|
||||
this.destinationLookup.add(pattern, mapping);
|
||||
|
|
|
@ -18,6 +18,7 @@ package org.springframework.messaging.handler.invocation.reactive;
|
|||
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
|
@ -25,7 +26,9 @@ import java.util.LinkedHashMap;
|
|||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.Predicate;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
@ -284,12 +287,27 @@ public abstract class AbstractMethodMessageHandler<T>
|
|||
Map<Method, T> methods = MethodIntrospector.selectMethods(userType,
|
||||
(MethodIntrospector.MetadataLookup<T>) method -> getMappingForMethod(method, userType));
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug(methods.size() + " message handler methods found on " + userType + ": " + methods);
|
||||
logger.debug(formatMappings(userType, methods));
|
||||
}
|
||||
methods.forEach((key, value) -> registerHandlerMethod(handler, key, value));
|
||||
}
|
||||
}
|
||||
|
||||
private String formatMappings(Class<?> userType, Map<Method, T> methods) {
|
||||
String formattedType = Arrays.stream(ClassUtils.getPackageName(userType).split("\\."))
|
||||
.map(p -> p.substring(0, 1))
|
||||
.collect(Collectors.joining(".", "", "." + userType.getSimpleName()));
|
||||
Function<Method, String> methodFormatter = method -> Arrays.stream(method.getParameterTypes())
|
||||
.map(Class::getSimpleName)
|
||||
.collect(Collectors.joining(",", "(", ")"));
|
||||
return methods.entrySet().stream()
|
||||
.map(e -> {
|
||||
Method method = e.getKey();
|
||||
return e.getValue() + ": " + method.getName() + methodFormatter.apply(method);
|
||||
})
|
||||
.collect(Collectors.joining("\n\t", "\n\t" + formattedType + ":" + "\n\t", ""));
|
||||
}
|
||||
|
||||
/**
|
||||
* Obtain the mapping for the given method, if any.
|
||||
* @param method the method to check
|
||||
|
@ -322,9 +340,6 @@ public abstract class AbstractMethodMessageHandler<T>
|
|||
}
|
||||
|
||||
this.handlerMethods.put(mapping, newHandlerMethod);
|
||||
if (logger.isTraceEnabled()) {
|
||||
logger.trace("Mapped \"" + mapping + "\" onto " + newHandlerMethod);
|
||||
}
|
||||
|
||||
for (String pattern : getDirectLookupMappings(mapping)) {
|
||||
this.destinationLookup.add(pattern, mapping);
|
||||
|
|
Loading…
Reference in New Issue