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 invalid webjar to show 404 #41018

Merged
merged 1 commit into from
Jun 6, 2024
Merged
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 @@ -2,6 +2,8 @@

import java.util.Map;

import org.jboss.logging.Logger;

import io.quarkus.runtime.annotations.Recorder;
import io.vertx.core.Handler;
import io.vertx.core.http.HttpHeaders;
Expand All @@ -11,30 +13,38 @@
@Recorder
public class WebDependencyLocatorRecorder {

private static final Logger LOG = Logger.getLogger(WebDependencyLocatorRecorder.class.getName());

public Handler<RoutingContext> getHandler(String webDependenciesRootUrl,
Map<String, String> webDependencyNameToVersionMap) {
return (event) -> {
String path = event.normalizedPath();
if (path.startsWith(webDependenciesRootUrl)) {
String rest = path.substring(webDependenciesRootUrl.length());
String webdep = rest.substring(0, rest.indexOf('/'));
if (webDependencyNameToVersionMap.containsKey(webdep)) {
// Check this is not the actual path (ex: /webjars/jquery/${jquery.version}/...
int endOfVersion = rest.indexOf('/', rest.indexOf('/') + 1);
if (endOfVersion == -1) {
endOfVersion = rest.length();
}
String nextPathEntry = rest.substring(rest.indexOf('/') + 1, endOfVersion);
if (webDependencyNameToVersionMap.get(webdep) == null
|| nextPathEntry.equals(webDependencyNameToVersionMap.get(webdep))) {
// go to the next handler (which should be the static resource handler, if one exists)
event.next();
try {
phillip-kruger marked this conversation as resolved.
Show resolved Hide resolved
String rest = path.substring(webDependenciesRootUrl.length());
String webdep = rest.substring(0, rest.indexOf('/'));
if (webDependencyNameToVersionMap.containsKey(webdep)) {
// Check this is not the actual path (ex: /webjars/jquery/${jquery.version}/...
int endOfVersion = rest.indexOf('/', rest.indexOf('/') + 1);
if (endOfVersion == -1) {
endOfVersion = rest.length();
}
String nextPathEntry = rest.substring(rest.indexOf('/') + 1, endOfVersion);
if (webDependencyNameToVersionMap.get(webdep) == null
|| nextPathEntry.equals(webDependencyNameToVersionMap.get(webdep))) {
// go to the next handler (which should be the static resource handler, if one exists)
event.next();
} else {
// reroute to the real resource
event.reroute(webDependenciesRootUrl + webdep + "/"
+ webDependencyNameToVersionMap.get(webdep) + rest.substring(rest.indexOf('/')));
}
} else {
// reroute to the real resource
event.reroute(webDependenciesRootUrl + webdep + "/"
+ webDependencyNameToVersionMap.get(webdep) + rest.substring(rest.indexOf('/')));
event.next();
}
} else {
} catch (Throwable t) {
LOG.debug("Error while locating web jar " + path);
// See if someone else can handle this.
event.next();
}
} else {
Expand Down