@ -27,6 +27,7 @@ import java.util.Set;
import org.springframework.boot.actuate.endpoint.Endpoint ;
import org.springframework.context.ApplicationContext ;
import org.springframework.util.Assert ;
import org.springframework.util.ObjectUtils ;
import org.springframework.util.StringUtils ;
import org.springframework.web.cors.CorsConfiguration ;
import org.springframework.web.servlet.HandlerMapping ;
@ -114,33 +115,44 @@ public class EndpointHandlerMapping extends RequestMappingHandlerMapping {
return ;
}
String [ ] patterns = getPatterns ( handler , mapping ) ;
super . registerHandlerMethod ( handler , method , withNewPatterns ( mapping , patterns ) ) ;
if ( ! ObjectUtils . isEmpty ( patterns ) ) {
super . registerHandlerMethod ( handler , method ,
withNewPatterns ( mapping , patterns ) ) ;
}
}
private String [ ] getPatterns ( Object handler , RequestMappingInfo mapping ) {
String path = getPath ( handler ) ;
String prefix = StringUtils . hasText ( this . prefix ) ? this . prefix + path : path ;
if ( handler instanceof String ) {
handler = getApplicationContext ( ) . getBean ( ( String ) handler ) ;
}
Assert . state ( handler instanceof MvcEndpoint , "Only MvcEndpoints are supported" ) ;
String path = getPath ( ( MvcEndpoint ) handler ) ;
return ( path = = null ? null : getEndpointPatterns ( path , mapping ) ) ;
}
/ * *
* Return the path that should be used to map the given { @link MvcEndpoint } .
* @param endpoint the endpoint to map
* @return the path to use for the endpoint or { @code null } if no mapping is required
* /
protected String getPath ( MvcEndpoint endpoint ) {
return endpoint . getPath ( ) ;
}
private String [ ] getEndpointPatterns ( String path , RequestMappingInfo mapping ) {
String patternPrefix = StringUtils . hasText ( this . prefix ) ? this . prefix + path
: path ;
Set < String > defaultPatterns = mapping . getPatternsCondition ( ) . getPatterns ( ) ;
if ( defaultPatterns . isEmpty ( ) ) {
return new String [ ] { prefix , prefix + ".json" } ;
return new String [ ] { p atternP refix, p atternP refix + ".json" } ;
}
List < String > patterns = new ArrayList < String > ( defaultPatterns ) ;
for ( int i = 0 ; i < patterns . size ( ) ; i + + ) {
patterns . set ( i , prefix + patterns . get ( i ) ) ;
patterns . set ( i , p atternP refix + patterns . get ( i ) ) ;
}
return patterns . toArray ( new String [ patterns . size ( ) ] ) ;
}
private String getPath ( Object handler ) {
if ( handler instanceof String ) {
handler = getApplicationContext ( ) . getBean ( ( String ) handler ) ;
}
if ( handler instanceof MvcEndpoint ) {
return ( ( MvcEndpoint ) handler ) . getPath ( ) ;
}
return "" ;
}
private RequestMappingInfo withNewPatterns ( RequestMappingInfo mapping ,
String [ ] patternStrings ) {
PatternsRequestCondition patterns = new PatternsRequestCondition ( patternStrings ,