Skip to content

Commit

Permalink
Merge pull request #43847 from phillip-kruger/rest-path-fix
Browse files Browse the repository at this point in the history
Fix rest-path in Not Found and Dev UI
  • Loading branch information
FroMage authored Oct 15, 2024
2 parents 9875631 + 47a921b commit e6dd595
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1358,7 +1358,7 @@ public void setupDeployment(BeanContainerBuildItem beanContainerBuildItem,
servletPresent = true;
}

RuntimeValue<Deployment> deployment = recorder.createDeployment(deploymentInfo,
RuntimeValue<Deployment> deployment = recorder.createDeployment(deploymentPath, deploymentInfo,
beanContainerBuildItem.getValue(), shutdownContext, vertxConfig,
requestContextFactoryBuildItem.map(RequestContextFactoryBuildItem::getFactory).orElse(null),
initClassFactory, launchModeBuildItem.getLaunchMode(), servletPresent);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public static Deployment getCurrentDeployment() {
return currentDeployment;
}

public RuntimeValue<Deployment> createDeployment(DeploymentInfo info,
public RuntimeValue<Deployment> createDeployment(String applicationPath, DeploymentInfo info,
BeanContainer beanContainer,
ShutdownContext shutdownContext, HttpBuildTimeConfig vertxConfig,
RequestContextFactory contextFactory,
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -374,10 +375,10 @@ public Boolean get() {
};
}

private List<RouteDescription> fromClassMappers(
private List<RouteDescription> fromClassMappers(String applicationPath,
List<RequestMapper.RequestPath<RestInitialHandler.InitialMatch>> classMappers) {
Map<String, RouteDescription> descriptions = new HashMap<>();
RuntimeResourceVisitor.visitRuntimeResources(classMappers, new RuntimeResourceVisitor() {
RuntimeResourceVisitor.visitRuntimeResources(applicationPath, classMappers, new RuntimeResourceVisitor() {

private RouteDescription description;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,12 @@ void routeNotFound(ResourceNotFoundRecorder recorder,
.filter(Objects::nonNull)
.collect(Collectors.toSet());

String baseUrl = getBaseUrl(launchMode);

// Additional endpoints
List<AdditionalRouteDescription> 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());

Expand All @@ -78,7 +80,7 @@ void routeNotFound(ResourceNotFoundRecorder recorder,
router.getMainRouter(),
router.getManagementRouter(),
beanContainer.getValue(),
getBaseUrl(launchMode),
baseUrl,
httpRoot.getRootPath(),
routes,
staticRoots,
Expand All @@ -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;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
`;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public default void visitEnd() {
public default void visitStart() {
}

public static void visitRuntimeResources(
public static void visitRuntimeResources(String applicationPath,
List<RequestMapper.RequestPath<RestInitialHandler.InitialMatch>> classMappers,
RuntimeResourceVisitor visitor) {
visitor.visitStart();
Expand Down Expand Up @@ -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);
}
Expand Down

0 comments on commit e6dd595

Please sign in to comment.