Skip to content

Commit

Permalink
Always produce management router
Browse files Browse the repository at this point in the history
... and decide in the recorder whether we will actually keep that management router or not.
  • Loading branch information
marko-bekhta committed Jun 25, 2024
1 parent 30bedeb commit a9f6135
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -265,16 +265,14 @@ VertxWebRouterBuildItem initializeRouter(VertxHttpRecorder recorder,
List<RouteBuildItem> redirectRoutes = new ArrayList<>();
boolean frameworkRouterCreated = false;
boolean mainRouterCreated = false;
boolean managementRouterCreated = false;

boolean isManagementInterfaceEnabled = managementBuildTimeConfig.enabled;
if (isManagementInterfaceEnabled) {
managementRouter = recorder.initializeRouter(vertx.getVertx());
}

for (RouteBuildItem route : routes) {
if (route.isManagement() && isManagementInterfaceEnabled) {
if (!managementRouterCreated) {
managementRouter = recorder.initializeRouter(vertx.getVertx());
managementRouterCreated = true;
}
recorder.addRoute(managementRouter, route.getRouteFunction(), route.getHandler(), route.getType());
} else if (nonApplicationRootPath.isDedicatedRouterRequired() && route.isRouterFramework()) {
// Non-application endpoints on a separate path
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -526,6 +526,7 @@ public void handle(RoutingContext event) {
if (managementRouter != null && managementRouter.getValue() != null) {
// Add body handler and cors handler
var mr = managementRouter.getValue();
boolean hasManagementRoutes = !mr.getRoutes().isEmpty();

addHotReplacementHandlerIfNeeded(mr);

Expand All @@ -548,16 +549,25 @@ public void handle(RoutingContext event) {
Handler<HttpServerRequest> handler = HttpServerCommonHandlers.enforceDuplicatedContext(mr);
handler = HttpServerCommonHandlers.applyProxy(managementConfiguration.getValue().proxy, handler, vertx);

event.select(ManagementInterface.class).fire(new ManagementInterfaceImpl(managementRouter.getValue()));

VertxHttpRecorder.managementRouterDelegate = handler;
if (VertxHttpRecorder.managementRouter == null) {
VertxHttpRecorder.managementRouter = new Handler<HttpServerRequest>() {
@Override
public void handle(HttpServerRequest event) {
VertxHttpRecorder.managementRouterDelegate.handle(event);
}
};
int routesBeforeMiEvent = mr.getRoutes().size();
event.select(ManagementInterface.class).fire(new ManagementInterfaceImpl(mr));

// It may be that no build steps produced any management routes.
// But we still want to give a chance to the "ManagementInterface event" to collect any
// routes that users may have provided through observing this event.
//
// Hence, we only initialize the `managementRouter` router when we either had some routes from extensions (`hasManagementRoutes`)
// or if the event collected some routes (`routesBeforeMiEvent < routesAfterMiEvent`)
if (hasManagementRoutes || routesBeforeMiEvent < mr.getRoutes().size()) {
VertxHttpRecorder.managementRouterDelegate = handler;
if (VertxHttpRecorder.managementRouter == null) {
VertxHttpRecorder.managementRouter = new Handler<HttpServerRequest>() {
@Override
public void handle(HttpServerRequest event) {
VertxHttpRecorder.managementRouterDelegate.handle(event);
}
};
}
}
}
}
Expand Down Expand Up @@ -1577,7 +1587,7 @@ public HotReplacementRoutingContextHandler(ClassLoader currentCl) {

@Override
public void handle(RoutingContext event) {
Thread.currentThread().setContextClassLoader( currentCl );
Thread.currentThread().setContextClassLoader(currentCl);
hotReplacementHandler.handle(event);
}
}
Expand Down

0 comments on commit a9f6135

Please sign in to comment.