From 47a921b168ae24ddef6ed5c5123e4be3cd902a8d Mon Sep 17 00:00:00 2001 From: Phillip Kruger Date: Tue, 15 Oct 2024 18:06:08 +1100 Subject: [PATCH] Fix rest-path in Not Found and Dev UI Signed-off-by: Phillip Kruger --- .../deployment/ResteasyReactiveProcessor.java | 2 +- .../runtime/ResteasyReactiveRecorder.java | 11 +++++----- .../deployment/devmode/NotFoundProcessor.java | 22 +++++++++++++++++-- .../resources/dev-ui/qwc/qwc-endpoints.js | 2 +- .../server/util/RuntimeResourceVisitor.java | 7 +++++- 5 files changed, 34 insertions(+), 10 deletions(-) diff --git a/extensions/resteasy-reactive/rest/deployment/src/main/java/io/quarkus/resteasy/reactive/server/deployment/ResteasyReactiveProcessor.java b/extensions/resteasy-reactive/rest/deployment/src/main/java/io/quarkus/resteasy/reactive/server/deployment/ResteasyReactiveProcessor.java index f88f3ae231d14..d9fe9f478b498 100644 --- a/extensions/resteasy-reactive/rest/deployment/src/main/java/io/quarkus/resteasy/reactive/server/deployment/ResteasyReactiveProcessor.java +++ b/extensions/resteasy-reactive/rest/deployment/src/main/java/io/quarkus/resteasy/reactive/server/deployment/ResteasyReactiveProcessor.java @@ -1358,7 +1358,7 @@ public void setupDeployment(BeanContainerBuildItem beanContainerBuildItem, servletPresent = true; } - RuntimeValue deployment = recorder.createDeployment(deploymentInfo, + RuntimeValue deployment = recorder.createDeployment(deploymentPath, deploymentInfo, beanContainerBuildItem.getValue(), shutdownContext, vertxConfig, requestContextFactoryBuildItem.map(RequestContextFactoryBuildItem::getFactory).orElse(null), initClassFactory, launchModeBuildItem.getLaunchMode(), servletPresent); diff --git a/extensions/resteasy-reactive/rest/runtime/src/main/java/io/quarkus/resteasy/reactive/server/runtime/ResteasyReactiveRecorder.java b/extensions/resteasy-reactive/rest/runtime/src/main/java/io/quarkus/resteasy/reactive/server/runtime/ResteasyReactiveRecorder.java index fc52b7a35c0e6..0d28c5159b7ed 100644 --- a/extensions/resteasy-reactive/rest/runtime/src/main/java/io/quarkus/resteasy/reactive/server/runtime/ResteasyReactiveRecorder.java +++ b/extensions/resteasy-reactive/rest/runtime/src/main/java/io/quarkus/resteasy/reactive/server/runtime/ResteasyReactiveRecorder.java @@ -103,7 +103,7 @@ public static Deployment getCurrentDeployment() { return currentDeployment; } - public RuntimeValue createDeployment(DeploymentInfo info, + public RuntimeValue createDeployment(String applicationPath, DeploymentInfo info, BeanContainer beanContainer, ShutdownContext shutdownContext, HttpBuildTimeConfig vertxConfig, RequestContextFactory contextFactory, @@ -158,9 +158,10 @@ closeTaskHandler, contextFactory, new ArcThreadSetupAction(beanContainer.request if (LaunchMode.current() == LaunchMode.DEVELOPMENT) { // For Not Found Screen - ResourceNotFoundData.setRuntimeRoutes(fromClassMappers(deployment.getClassMappers())); + ResourceNotFoundData.setRuntimeRoutes(fromClassMappers(applicationPath, deployment.getClassMappers())); // For Dev UI Screen - RuntimeResourceVisitor.visitRuntimeResources(deployment.getClassMappers(), ScoreSystem.ScoreVisitor); + RuntimeResourceVisitor.visitRuntimeResources(applicationPath, deployment.getClassMappers(), + ScoreSystem.ScoreVisitor); } return new RuntimeValue<>(deployment); } @@ -374,10 +375,10 @@ public Boolean get() { }; } - private List fromClassMappers( + private List fromClassMappers(String applicationPath, List> classMappers) { Map descriptions = new HashMap<>(); - RuntimeResourceVisitor.visitRuntimeResources(classMappers, new RuntimeResourceVisitor() { + RuntimeResourceVisitor.visitRuntimeResources(applicationPath, classMappers, new RuntimeResourceVisitor() { private RouteDescription description; diff --git a/extensions/vertx-http/deployment/src/main/java/io/quarkus/vertx/http/deployment/devmode/NotFoundProcessor.java b/extensions/vertx-http/deployment/src/main/java/io/quarkus/vertx/http/deployment/devmode/NotFoundProcessor.java index 787b570fa123d..b8eeff64add21 100644 --- a/extensions/vertx-http/deployment/src/main/java/io/quarkus/vertx/http/deployment/devmode/NotFoundProcessor.java +++ b/extensions/vertx-http/deployment/src/main/java/io/quarkus/vertx/http/deployment/devmode/NotFoundProcessor.java @@ -65,10 +65,12 @@ void routeNotFound(ResourceNotFoundRecorder recorder, .filter(Objects::nonNull) .collect(Collectors.toSet()); + String baseUrl = getBaseUrl(launchMode); + // Additional endpoints List endpoints = additionalEndpoints .stream() - .map(v -> new AdditionalRouteDescription(v.getEndpoint(httpRoot), v.getDescription())) + .map(v -> new AdditionalRouteDescription(concatenateUrl(baseUrl, v.getEndpoint(httpRoot)), v.getDescription())) .sorted() .collect(Collectors.toList()); @@ -78,7 +80,7 @@ void routeNotFound(ResourceNotFoundRecorder recorder, router.getMainRouter(), router.getManagementRouter(), beanContainer.getValue(), - getBaseUrl(launchMode), + baseUrl, httpRoot.getRootPath(), routes, staticRoots, @@ -97,4 +99,20 @@ private String getBaseUrl(LaunchModeBuildItem launchMode) { return null; } } + + private String concatenateUrl(String part1, String part2) { + if (part1 == null && part2 == null) + return null; + if (part1 == null && part2 != null) + return part2; + if (part1 != null && part2 == null) + return part1; + if (part1.endsWith("/") && part2.startsWith("/")) { + return part1.substring(0, part1.length() - 1) + part2; + } else if (!part1.endsWith("/") && !part2.startsWith("/")) { + return part1 + "/" + part2; + } else { + return part1 + part2; + } + } } diff --git a/extensions/vertx-http/dev-ui-resources/src/main/resources/dev-ui/qwc/qwc-endpoints.js b/extensions/vertx-http/dev-ui-resources/src/main/resources/dev-ui/qwc/qwc-endpoints.js index efe3b43c30a22..fd0479db7311b 100644 --- a/extensions/vertx-http/dev-ui-resources/src/main/resources/dev-ui/qwc/qwc-endpoints.js +++ b/extensions/vertx-http/dev-ui-resources/src/main/resources/dev-ui/qwc/qwc-endpoints.js @@ -32,7 +32,7 @@ export class QwcEndpoints extends LitElement { color: var(--lumo-body-text-color); } a:hover { - color: var(--quarkus-red); + color: var(--quarkus-blue); } `; diff --git a/independent-projects/resteasy-reactive/server/runtime/src/main/java/org/jboss/resteasy/reactive/server/util/RuntimeResourceVisitor.java b/independent-projects/resteasy-reactive/server/runtime/src/main/java/org/jboss/resteasy/reactive/server/util/RuntimeResourceVisitor.java index 5746334a40581..5bf847459f91d 100644 --- a/independent-projects/resteasy-reactive/server/runtime/src/main/java/org/jboss/resteasy/reactive/server/util/RuntimeResourceVisitor.java +++ b/independent-projects/resteasy-reactive/server/runtime/src/main/java/org/jboss/resteasy/reactive/server/util/RuntimeResourceVisitor.java @@ -23,7 +23,7 @@ public default void visitEnd() { public default void visitStart() { } - public static void visitRuntimeResources( + public static void visitRuntimeResources(String applicationPath, List> classMappers, RuntimeResourceVisitor visitor) { visitor.visitStart(); @@ -66,6 +66,11 @@ public static void visitRuntimeResources( fullPath = basePath + "/" + subPath; } } + + if (applicationPath != null && !applicationPath.isBlank() && !applicationPath.equals("/")) { + fullPath = applicationPath + fullPath; + } + RuntimeResource runtimeResource = methodTemplate.value; visitor.visitRuntimeResource(httpMethod, fullPath, runtimeResource); }