javaee / grizzly

Writing scalable server applications in the Java™ programming language has always been difficult. Before the advent of the Java New I/O API (NIO), thread management issues made it impossible for a server to scale to thousands of users. The Grizzly NIO framework has been designed to help developers to take advantage of the Java™ NIO API.
https://javaee.github.io/grizzly/
Other
222 stars 60 forks source link

Trailing slash required on static content handlers, 2.4.1+ #1970

Closed jcalcote closed 6 years ago

jcalcote commented 6 years ago

Please see my comment on https://github.com/javaee/grizzly/issues/1823 (closed). Wanted to make sure this issue got seen, so I opened a new one. Sorry if that's not the proper procedure.

rlubke commented 6 years ago

@jcalcote The fix implemented in #1823 hasn't changed. I've performed a simple test here and it appears to be working as expected.

Can you provide a small maven-based test case showing the issue?

jcalcote commented 6 years ago

Sorry it took so long to get back to you @rlubke. I think I know what's causing the problem. First, here's my sample application - it's just a maven project using the jersey-quickstart-grizzly2 archetype (for jersey 2.26).

The ONLY change I made was to replaced the last line in main as follows:

        HttpServer server = GrizzlyHttpServerFactory.createHttpServer(URI.create(BASE_URI), rc);

        ClassLoader loader = Main.class.getClassLoader();
        CLStaticHttpHandler docsHandler = new CLStaticHttpHandler(loader, "html/");
        docsHandler.setFileCacheEnabled(false);
        server.getServerConfiguration().addHttpHandler(docsHandler, "/docs");

        return server;

Then I added a resource: /resources/html/index.html:

<!DOCTYPE html>
<html lang="en">
<head><meta charset="UTF-8"></head>
<body>Hi there!</body>
</html>

Hitting http://localhost:8080/myapp/myresource returns "Got it!"

Hitting http://localhost:8080/docs returns a grizzly error banner - black and yellow - "Not Found" in the title, "Resource identified by path '/docs', does not exist.", footer contains Grizzly 2.4.0.

Hitting http://localhost;8080/docs/ returns "Hi there!" - the content of the index.html page.

--John

rlubke commented 6 years ago

Though the end result is the same, this is a different issue. The issue appears to be within the Mapper which is a picky code path. This will require a bit of time.

jcalcote commented 6 years ago

Thanks for looking into it - I have a work around for the moment - I really wanted my swagger docs to be at the root resource, so I just added a root resource in jersey that redirects to /docs/ - as long as people hit the root instead of the /docs path, they'll land in the right place.

glassfishrobot commented 6 years ago

Closing this as this issue is migrated to https://github.com/eclipse-ee4j/grizzly/issues/1970