Skip to content
This repository was archived by the owner on Jul 14, 2026. It is now read-only.

Commit e43d4ff

Browse files
authored
Merge pull request #82 from bright-room/claude/issue-66-20260310-0310
Close #66: Add functional endpoint custom error handling to WebMVC error-handling example
2 parents b2c8dd8 + 5b3f421 commit e43d4ff

4 files changed

Lines changed: 96 additions & 0 deletions

File tree

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package net.brightroom.example.errorhandling;
2+
3+
import net.brightroom.endpointgate.core.exception.EndpointGateAccessDeniedException;
4+
import net.brightroom.endpointgate.spring.webmvc.resolution.handlerfilter.AccessDeniedHandlerFilterResolution;
5+
import org.springframework.context.annotation.Profile;
6+
import org.springframework.http.HttpStatus;
7+
import org.springframework.http.MediaType;
8+
import org.springframework.stereotype.Component;
9+
import org.springframework.web.servlet.function.ServerRequest;
10+
import org.springframework.web.servlet.function.ServerResponse;
11+
12+
/**
13+
* C-3: Custom AccessDeniedHandlerFilterResolution for Functional Endpoint path.
14+
*
15+
* <p>Replaces the default bean via @ConditionalOnMissingBean. Returns a custom JSON error response
16+
* when an endpoint gate denies access through functional endpoints.
17+
*/
18+
@Component
19+
@Profile("functional-error")
20+
public class CustomAccessDeniedHandlerFilterResolution
21+
implements AccessDeniedHandlerFilterResolution {
22+
23+
@Override
24+
public ServerResponse resolve(ServerRequest request, EndpointGateAccessDeniedException e) {
25+
String body =
26+
String.format(
27+
"{\"error\":\"access_denied\",\"gate\":\"%s\",\"path\":\"%s\"}",
28+
e.gateId(), request.path());
29+
ServerResponse.BodyBuilder builder =
30+
ServerResponse.status(HttpStatus.FORBIDDEN).contentType(MediaType.APPLICATION_JSON);
31+
return builder.body(body);
32+
}
33+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package net.brightroom.example.errorhandling;
2+
3+
import org.springframework.context.annotation.Profile;
4+
import org.springframework.stereotype.Component;
5+
import org.springframework.web.servlet.function.ServerRequest;
6+
import org.springframework.web.servlet.function.ServerResponse;
7+
8+
/** Handler for functional endpoint requests. */
9+
@Component
10+
@Profile("functional-error")
11+
public class ErrorHandlingHandler {
12+
13+
/**
14+
* Handles the gated endpoint request.
15+
*
16+
* @param request the server request
17+
* @return the server response
18+
*/
19+
public ServerResponse gated(ServerRequest request) {
20+
return ServerResponse.ok().body("Functional endpoint data");
21+
}
22+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package net.brightroom.example.errorhandling;
2+
3+
import net.brightroom.endpointgate.spring.webmvc.filter.EndpointGateHandlerFilterFunction;
4+
import org.springframework.context.annotation.Bean;
5+
import org.springframework.context.annotation.Configuration;
6+
import org.springframework.context.annotation.Profile;
7+
import org.springframework.web.servlet.function.RouterFunction;
8+
import org.springframework.web.servlet.function.RouterFunctions;
9+
import org.springframework.web.servlet.function.ServerResponse;
10+
11+
/**
12+
* Functional endpoint routing configuration demonstrating custom
13+
* AccessDeniedHandlerFilterResolution.
14+
*
15+
* <p>When the endpoint gate is disabled, the custom resolution bean provides the denied response
16+
* instead of the default. Note: @ControllerAdvice is NOT used for functional endpoints.
17+
*/
18+
@Configuration
19+
@Profile("functional-error")
20+
public class ErrorHandlingRouter {
21+
22+
/**
23+
* Registers functional endpoint routes with endpoint gate filter.
24+
*
25+
* @param handler the request handler
26+
* @param endpointGateFilter the endpoint gate filter function factory
27+
* @return the router function
28+
*/
29+
@Bean
30+
public RouterFunction<ServerResponse> errorHandlingRoutes(
31+
ErrorHandlingHandler handler, EndpointGateHandlerFilterFunction endpointGateFilter) {
32+
return RouterFunctions.route()
33+
.GET("/api/functional/gated", handler::gated)
34+
.filter(endpointGateFilter.of("functional-gated"))
35+
.build();
36+
}
37+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
endpoint-gate:
2+
gates:
3+
functional-gated:
4+
enabled: false

0 commit comments

Comments
 (0)