Browse Source

Correctly format class name in default package

Closes gh-27247
pull/27386/head
Rossen Stoyanchev 4 years ago
parent
commit
b6037d0d07
  1. 12
      spring-messaging/src/main/java/org/springframework/messaging/handler/invocation/AbstractMethodMessageHandler.java
  2. 12
      spring-messaging/src/main/java/org/springframework/messaging/handler/invocation/reactive/AbstractMethodMessageHandler.java
  3. 10
      spring-webflux/src/main/java/org/springframework/web/reactive/result/method/AbstractHandlerMethodMapping.java
  4. 10
      spring-webmvc/src/main/java/org/springframework/web/servlet/handler/AbstractHandlerMethodMapping.java

12
spring-messaging/src/main/java/org/springframework/messaging/handler/invocation/AbstractMethodMessageHandler.java

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2020 the original author or authors. * Copyright 2002-2021 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -53,6 +53,7 @@ import org.springframework.util.ClassUtils;
import org.springframework.util.CollectionUtils; import org.springframework.util.CollectionUtils;
import org.springframework.util.LinkedMultiValueMap; import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap; import org.springframework.util.MultiValueMap;
import org.springframework.util.StringUtils;
import org.springframework.util.concurrent.ListenableFuture; import org.springframework.util.concurrent.ListenableFuture;
import org.springframework.util.concurrent.ListenableFutureCallback; import org.springframework.util.concurrent.ListenableFutureCallback;
@ -319,9 +320,12 @@ public abstract class AbstractMethodMessageHandler<T>
} }
private String formatMappings(Class<?> userType, Map<Method, T> methods) { private String formatMappings(Class<?> userType, Map<Method, T> methods) {
String formattedType = Arrays.stream(ClassUtils.getPackageName(userType).split("\\.")) String packageName = ClassUtils.getPackageName(userType);
.map(p -> p.substring(0, 1)) String formattedType = (StringUtils.hasText(packageName) ?
.collect(Collectors.joining(".", "", "." + userType.getSimpleName())); Arrays.stream(packageName.split("\\."))
.map(packageSegment -> packageSegment.substring(0, 1))
.collect(Collectors.joining(".", "", "." + userType.getSimpleName())) :
userType.getSimpleName());
Function<Method, String> methodFormatter = method -> Arrays.stream(method.getParameterTypes()) Function<Method, String> methodFormatter = method -> Arrays.stream(method.getParameterTypes())
.map(Class::getSimpleName) .map(Class::getSimpleName)
.collect(Collectors.joining(",", "(", ")")); .collect(Collectors.joining(",", "(", ")"));

12
spring-messaging/src/main/java/org/springframework/messaging/handler/invocation/reactive/AbstractMethodMessageHandler.java

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2020 the original author or authors. * Copyright 2002-2021 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -54,6 +54,7 @@ import org.springframework.util.CollectionUtils;
import org.springframework.util.MultiValueMap; import org.springframework.util.MultiValueMap;
import org.springframework.util.ObjectUtils; import org.springframework.util.ObjectUtils;
import org.springframework.util.RouteMatcher; import org.springframework.util.RouteMatcher;
import org.springframework.util.StringUtils;
/** /**
* Abstract base class for reactive HandlerMethod-based message handling. * Abstract base class for reactive HandlerMethod-based message handling.
@ -341,9 +342,12 @@ public abstract class AbstractMethodMessageHandler<T>
} }
private String formatMappings(Class<?> userType, Map<Method, T> methods) { private String formatMappings(Class<?> userType, Map<Method, T> methods) {
String formattedType = Arrays.stream(ClassUtils.getPackageName(userType).split("\\.")) String packageName = ClassUtils.getPackageName(userType);
.map(p -> p.substring(0, 1)) String formattedType = (StringUtils.hasText(packageName) ?
.collect(Collectors.joining(".", "", "." + userType.getSimpleName())); Arrays.stream(packageName.split("\\."))
.map(packageSegment -> packageSegment.substring(0, 1))
.collect(Collectors.joining(".", "", "." + userType.getSimpleName())) :
userType.getSimpleName());
Function<Method, String> methodFormatter = method -> Arrays.stream(method.getParameterTypes()) Function<Method, String> methodFormatter = method -> Arrays.stream(method.getParameterTypes())
.map(Class::getSimpleName) .map(Class::getSimpleName)
.collect(Collectors.joining(",", "(", ")")); .collect(Collectors.joining(",", "(", ")"));

10
spring-webflux/src/main/java/org/springframework/web/reactive/result/method/AbstractHandlerMethodMapping.java

@ -42,6 +42,7 @@ import org.springframework.util.Assert;
import org.springframework.util.ClassUtils; import org.springframework.util.ClassUtils;
import org.springframework.util.LinkedMultiValueMap; import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap; import org.springframework.util.MultiValueMap;
import org.springframework.util.StringUtils;
import org.springframework.web.cors.CorsConfiguration; import org.springframework.web.cors.CorsConfiguration;
import org.springframework.web.cors.reactive.CorsUtils; import org.springframework.web.cors.reactive.CorsUtils;
import org.springframework.web.method.HandlerMethod; import org.springframework.web.method.HandlerMethod;
@ -222,9 +223,12 @@ public abstract class AbstractHandlerMethodMapping<T> extends AbstractHandlerMap
} }
private String formatMappings(Class<?> userType, Map<Method, T> methods) { private String formatMappings(Class<?> userType, Map<Method, T> methods) {
String formattedType = Arrays.stream(ClassUtils.getPackageName(userType).split("\\.")) String packageName = ClassUtils.getPackageName(userType);
.map(p -> p.substring(0, 1)) String formattedType = (StringUtils.hasText(packageName) ?
.collect(Collectors.joining(".", "", "." + userType.getSimpleName())); Arrays.stream(packageName.split("\\."))
.map(packageSegment -> packageSegment.substring(0, 1))
.collect(Collectors.joining(".", "", "." + userType.getSimpleName())) :
userType.getSimpleName());
Function<Method, String> methodFormatter = method -> Arrays.stream(method.getParameterTypes()) Function<Method, String> methodFormatter = method -> Arrays.stream(method.getParameterTypes())
.map(Class::getSimpleName) .map(Class::getSimpleName)
.collect(Collectors.joining(",", "(", ")")); .collect(Collectors.joining(",", "(", ")"));

10
spring-webmvc/src/main/java/org/springframework/web/servlet/handler/AbstractHandlerMethodMapping.java

@ -44,6 +44,7 @@ import org.springframework.util.Assert;
import org.springframework.util.ClassUtils; import org.springframework.util.ClassUtils;
import org.springframework.util.LinkedMultiValueMap; import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap; import org.springframework.util.MultiValueMap;
import org.springframework.util.StringUtils;
import org.springframework.web.cors.CorsConfiguration; import org.springframework.web.cors.CorsConfiguration;
import org.springframework.web.cors.CorsUtils; import org.springframework.web.cors.CorsUtils;
import org.springframework.web.method.HandlerMethod; import org.springframework.web.method.HandlerMethod;
@ -301,9 +302,12 @@ public abstract class AbstractHandlerMethodMapping<T> extends AbstractHandlerMap
} }
private String formatMappings(Class<?> userType, Map<Method, T> methods) { private String formatMappings(Class<?> userType, Map<Method, T> methods) {
String formattedType = Arrays.stream(ClassUtils.getPackageName(userType).split("\\.")) String packageName = ClassUtils.getPackageName(userType);
.map(p -> p.substring(0, 1)) String formattedType = (StringUtils.hasText(packageName) ?
.collect(Collectors.joining(".", "", "." + userType.getSimpleName())); Arrays.stream(packageName.split("\\."))
.map(packageSegment -> packageSegment.substring(0, 1))
.collect(Collectors.joining(".", "", "." + userType.getSimpleName())) :
userType.getSimpleName());
Function<Method, String> methodFormatter = method -> Arrays.stream(method.getParameterTypes()) Function<Method, String> methodFormatter = method -> Arrays.stream(method.getParameterTypes())
.map(Class::getSimpleName) .map(Class::getSimpleName)
.collect(Collectors.joining(",", "(", ")")); .collect(Collectors.joining(",", "(", ")"));

Loading…
Cancel
Save