You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I've been using webflux in Spring Boot 3.2.x and I've implemented a custom actuator endpoint like this:
@Component
@RestControllerEndpoint(id ="api", enableByDefault =true)
classApiProxyEndpoint {
@Value("\${management.endpoints.web.base-path}")
lateinitvar managementPath:String
@Autowired
lateinitvar webHandler:WebHandler
@RequestMapping("**") // Match all path segments under <management-path>/api/ until the end of the pathfunapiProxyEndpoint(exchange:ServerWebExchange): Mono<Void> {
val originalPath = exchange.request.path.toString()
val apiPathWithoutManagementPath = originalPath.substringAfter(managementPath)
val updatedRequest = exchange.request.mutate().contextPath("/").path(apiPathWithoutManagementPath).header("X-Api-RootPath" managementPath).build()
val updatedExchange = exchange.mutate().request(updatedRequest).build()
return webHandler.handle(updatedExchange)
}
}
The reason for doing this is that I want to expose the hal-browser as an actuator endpoint (so that I can browse the API from using the hal-browser from the actuator). What's happening is that when the hal-browser calls a URI (by calling the "api" endpoint in actuator) I redirect all requests to the actual api endpoint (not behind actuator). This endpoint acts as a proxy, just forwarding all requests made to "api" to somewhere else. This has worked great for several years, but since Spring Boot 3.3.0, the RestControllerEndpoint has been deprecated and I can't find a way to replace it. I've tried this:
@Component
@WebEndpoint(id ="api", enableByDefault =true)
classApiProxyEndpoint {
@Value("\${management.endpoints.web.base-path}")
lateinitvar managementPath:String
@Autowired
lateinitvar webHandler:WebHandler
@WriteOperation
@ReadOperation
@DeleteOperation
funapiProxyEndpoint(exchange:ServerWebExchange): Mono<Void> {
val originalPath = exchange.request.path.toString()
val apiPathWithoutManagementPath = originalPath.substringAfter(managementPath)
val updatedRequest = exchange.request.mutate().contextPath("/").path(apiPathWithoutManagementPath).header("X-Api-RootPath" managementPath).build()
val updatedExchange = exchange.mutate().request(updatedRequest).build()
return webHandler.handle(updatedExchange)
}
}
but this doesn't work. The example above will show me this error in the HAL browser:
@wilkinsona Of course, I searched in the issues before posting this one but I couldn't find anything similar. So thanks for the pointer and sorry for the separate issue.
I've been using webflux in Spring Boot 3.2.x and I've implemented a custom actuator endpoint like this:
The reason for doing this is that I want to expose the hal-browser as an actuator endpoint (so that I can browse the API from using the hal-browser from the actuator). What's happening is that when the hal-browser calls a URI (by calling the "api" endpoint in actuator) I redirect all requests to the actual api endpoint (not behind actuator). This endpoint acts as a proxy, just forwarding all requests made to "api" to somewhere else. This has worked great for several years, but since Spring Boot 3.3.0, the
RestControllerEndpoint
has been deprecated and I can't find a way to replace it. I've tried this:but this doesn't work. The example above will show me this error in the HAL browser:
How can I achieve the same thing (i.e. proxying) in Spring Boot 3.3.0 without using the deprecated
RestControllerEndpoint
?The text was updated successfully, but these errors were encountered: