mirror of
https://github.com/spring-projects/spring-boot.git
synced 2026-09-17 12:09:16 +00:00
Merge branch '3.5.x' into 4.0.x
Closes gh-49646
This commit is contained in:
+44
@@ -59,6 +59,7 @@ import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.http.ResponseEntity.BodyBuilder;
|
||||
import org.springframework.http.server.reactive.ServerHttpResponse;
|
||||
import org.springframework.security.authorization.AuthorityAuthorizationManager;
|
||||
import org.springframework.security.authorization.AuthorizationResult;
|
||||
import org.springframework.security.core.Authentication;
|
||||
@@ -106,6 +107,8 @@ public abstract class AbstractWebFluxEndpointHandlerMapping extends RequestMappi
|
||||
|
||||
private final Method handleReadMethod = getHandleReadMethod();
|
||||
|
||||
private final Method handleCatchAllMethod = getCatchAllMethod();
|
||||
|
||||
private final boolean shouldRegisterLinksMapping;
|
||||
|
||||
/**
|
||||
@@ -141,6 +144,12 @@ public abstract class AbstractWebFluxEndpointHandlerMapping extends RequestMappi
|
||||
return method;
|
||||
}
|
||||
|
||||
private static Method getCatchAllMethod() {
|
||||
Method method = ReflectionUtils.findMethod(CatchAllHandler.class, "handle", ServerWebExchange.class);
|
||||
Assert.state(method != null, "'method' must not be null");
|
||||
return method;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void initHandlerMethods() {
|
||||
for (ExposableWebEndpoint endpoint : this.endpoints) {
|
||||
@@ -192,6 +201,17 @@ public abstract class AbstractWebFluxEndpointHandlerMapping extends RequestMappi
|
||||
return reactiveWebOperation;
|
||||
}
|
||||
|
||||
/**
|
||||
* Register a "catch all" handler for the rest of actuator namespace, ensuring that
|
||||
* all requests are handled by this handler mapping.
|
||||
* @param responseStatus the response status to use for handled requests
|
||||
*/
|
||||
protected void registerCatchAllMapping(HttpStatus responseStatus) {
|
||||
String subPath = this.endpointMapping.createSubPath("/**");
|
||||
registerMapping(RequestMappingInfo.paths(subPath).build(), new CatchAllHandler(responseStatus),
|
||||
this.handleCatchAllMethod);
|
||||
}
|
||||
|
||||
private RequestMappingInfo createRequestMappingInfo(WebOperation operation) {
|
||||
WebOperationRequestPredicate predicate = operation.getRequestPredicate();
|
||||
String path = this.endpointMapping.createSubPath(predicate.getPath());
|
||||
@@ -524,6 +544,30 @@ public abstract class AbstractWebFluxEndpointHandlerMapping extends RequestMappi
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Catch-all handler that always replies with a fixed HTTP status.
|
||||
*/
|
||||
private static final class CatchAllHandler {
|
||||
|
||||
private final HttpStatus responseStatus;
|
||||
|
||||
CatchAllHandler(HttpStatus responseStatus) {
|
||||
this.responseStatus = responseStatus;
|
||||
}
|
||||
|
||||
Mono<Void> handle(ServerWebExchange exchange) {
|
||||
ServerHttpResponse response = exchange.getResponse();
|
||||
response.setStatusCode(this.responseStatus);
|
||||
return response.setComplete();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Actuator catch-all endpoint";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private static class WebFluxEndpointHandlerMethod extends HandlerMethod {
|
||||
|
||||
WebFluxEndpointHandlerMethod(Object bean, Method method) {
|
||||
|
||||
Reference in New Issue
Block a user