'Quarkus Reactive Routes: different behaviour in uber jar

Following this guide, I have configured my Quarkus application to return a custom error page when a file is not found in META-INF/resources/.

@ApplicationScoped
public class FileNotFoundHandler {

    @Route(methods = Route.HttpMethod.GET, regex = "^/.+")
    void activate404Intercepting(RoutingContext rc) {
        ((RoutingContextImpl) rc).currentRouter()
                .errorHandler(404, errorContext -> errorContext.response()
                        .sendFile("notfoundpage.html")
                );
        rc.next();
    }

}

This works perfectly fine when I run my code locally with Quarkus in development mode. However when I build an uber jar, the behavior is different: I get a timeout when I try to visit an unknown path.

Why does my uber jar behaves different and how can I fix this? Any help would be greatly appreciated.



Solution 1:[1]

After some debugging, I found out that activate404Intercepting was invoked in the uber jar, but the notfoundpage.html was not found by the relative path because it was at another location.

My solution:

@ApplicationScoped
public class FileNotFoundHandler {

    private static final String INDEX_FILE_LOCATION = getPathToIndexFile();

    private static String getPathToIndexFile(){
        return Objects.nonNull(FileNotFoundHandler.class.getClassLoader().getResource("notfoundpage.html")) ?
            "notfoundpage.html" : "META-INF/resources/notfoundpage.html";
    }

    @Route(methods = Route.HttpMethod.GET, regex = "^/.+")
    void activate404Intercepting(RoutingContext rc) {
        ((RoutingContextImpl) rc).currentRouter()
                .errorHandler(404, errorContext -> errorContext.response()
                        .sendFile(INDEX_FILE_LOCATION)
                );
        rc.next();
    }

}

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1