Description
STS team attempts to find a spot in the source code that declares routes using functional style using the JSON data from the Actuator.
Source code example:
public class VetsRouter {
@Bean
public RouterFunction<ServerResponse> route(VetsHandler vetsHandler) {
return RouterFunctions
.route(RequestPredicates.GET("/vets").and(RequestPredicates.accept(MediaType.TEXT_PLAIN)), vetsHandler::vets)
.andRoute(RequestPredicates.GET("/vets.html"), vetsHandler::vetsHtml);
}
@Bean
public RouterFunction<ServerResponse> moreRoute(VetsHandler vetsHandler) {
return RouterFunctions
.route(RequestPredicates.GET("/new-vets").and(RequestPredicates.accept(MediaType.TEXT_PLAIN)), vetsHandler::vets)
.andRoute(RequestPredicates.GET("/new-vets.html"), vetsHandler::vetsHtml);
}
}
The JSON data from the Actuator for /vets
route:
{
"predicate": "((GET && /vets) && Accept: [text/plain])",
"handler": "org.springframework.samples.petclinic.deviations.VetsRouter$$Lambda$868/443912630@369564bd",
"details": {
"handlerFunction": {
"className": "org.springframework.samples.petclinic.deviations.VetsRouter$$Lambda$868/443912630"
}
}
},
There are two pieces of data to help matching are predicate and handler
The handler data should be most helpful in matching the proper place in the source. The matching place in the source code we think should be the route
method declaration. Based on the handler's data we cannot match the route
method unfortunately. The lambda with magic numbers is useless in this case.
It'd be great if the details
object had something helpful to find the route
method. Either method signature or perhaps the id of the corresponding RouterFunction
bean. Seemed like getting the bean id into the JSON is doable (ApplicationContext.getBeansOfType(RouterFunction.class, true, true)
gives an id -> bean object map, given a RouterFunction object should be easy to get the corresponding id ). Therefore the JSON would look like:
{
"predicate": "((GET && /vets) && Accept: [text/plain])",
"handler": "org.springframework.samples.petclinic.deviations.VetsRouter$$Lambda$868/443912630@369564bd",
"details": {
"handlerFunction": {
"className": "org.springframework.samples.petclinic.deviations.VetsRouter$$Lambda$868/443912630"
},
"bean": "route"
}
},