Separate logging from getUrlMappings()

Closes gh-13710
This commit is contained in:
Johnny Lim 2018-07-10 01:04:52 +09:00 committed by Stephane Nicoll
parent 57e2bb9c6a
commit 0de8317979
1 changed files with 13 additions and 9 deletions

View File

@ -16,6 +16,7 @@
package org.springframework.boot.actuate.endpoint.web;
import java.util.Arrays;
import java.util.Collection;
import java.util.LinkedHashSet;
import java.util.Set;
@ -76,18 +77,21 @@ public class ServletEndpointRegistrar implements ServletContextInitializer {
EndpointServlet endpointServlet = endpoint.getEndpointServlet();
Dynamic registration = servletContext.addServlet(name,
endpointServlet.getServlet());
registration.addMapping(getUrlMappings(endpoint.getRootPath(), name));
String[] urlMappings = getUrlMappings(endpoint.getRootPath());
registration.addMapping(urlMappings);
if (logger.isInfoEnabled()) {
Arrays.stream(urlMappings).forEach(
(mapping) -> logger.info("Registered '" + mapping + "' to " + name));
}
registration.setInitParameters(endpointServlet.getInitParameters());
}
private String[] getUrlMappings(String endpointPath, String name) {
return this.basePaths
.stream().map((basePath) -> (basePath != null
? basePath + "/" + endpointPath : "/" + endpointPath))
.distinct().map((path) -> {
logger.info("Registered '" + path + "' to " + name);
return (path.endsWith("/") ? path + "*" : path + "/*");
}).toArray(String[]::new);
private String[] getUrlMappings(String endpointPath) {
return this.basePaths.stream()
.map((basePath) -> (basePath != null ? basePath + "/" + endpointPath
: "/" + endpointPath))
.distinct().map((path) -> (path.endsWith("/") ? path + "*" : path + "/*"))
.toArray(String[]::new);
}
}