Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix rest-path in Not Found and Dev UI #43847

Merged
merged 1 commit into from
Oct 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading