'Blocking Spring MVC equivalent of Webflux ServerWebExchange for making changes to an actuator request

Due to firewall/proxy configuration (outside of the spring application), I have created an actuator endpoint that simply forwards all requests to it to another endpoint with Webflux. The class looks like this:

@Component
@RestControllerEndpoint(id = "my-proxy", enableByDefault = true)
class ApiProxyEndpoint {

    @Value("\${management.endpoints.web.base-path}")
    lateinit var managementPath: String

    @Autowired
    lateinit var webHandler: WebHandler

    @RequestMapping("**") 
    fun myProxyEndpoint(exchange: ServerWebExchange): Mono<Void> {
        val originalPath = exchange.request.path.toString()
        val pathToUse = originalPath.substringAfter(managementPath)
        val updatedRequest = exchange.request.mutate().contextPath("/").path(pathToUse)
                                     .header("someheader", "some value").build()
        val updatedExchange = exchange.mutate().request(updatedRequest).build()

        return webHandler.handle(updatedExchange)
    }
}

This works great when using webflux. However, I want to do exactly the same for a non-webflux (i.e. blocking) Spring Boot MVC application. How can I do this? What (I think) I'm looking for is the equalivant of ServerWebExchange and WebHandler but for non-webflux applications. Or is there another way to do it? Note that it's important that this endpoint is only available from the "management api" (actuator).

I'm using Spring Boot 2.6.7 if that matters.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source