Skip to content

Conversation

@hupender
Copy link
Contributor

@hupender hupender commented May 11, 2025

Provided feature for the issue #2364.
Example use case :

var app = Javalin
            .create(config -> {
                config.staticFiles.add(staticFileConfig -> {
                    staticFileConfig.hostedPath = "/";
                    staticFileConfig.directory = "/public";
                    staticFileConfig.location = Location.CLASSPATH;
                    staticFileConfig.roles = Set.of(Role.USER);
                });
            })
            .start();

@tipsy
Copy link
Member

tipsy commented May 11, 2025

Thanks @hupender - would be really great with some tests for this!

@tipsy
Copy link
Member

tipsy commented May 11, 2025

Seems the implementation is making some of the existing tests fail too - you can run these locally by doing ./mvnw test (or mvn test if you have maven installed).

@hupender
Copy link
Contributor Author

hupender commented May 12, 2025

@tipsy i have made the changes and added unit test cases but getting failure in javalin-osgi. It was already failing even in the master branch.

Details

 Tests run: 819, Failures: 0, Errors: 0, Skipped: 24 in javalin-parent

[INFO] Reactor Summary for Javalin (parent) 6.6.1-SNAPSHOT:
[INFO] 
[INFO] Javalin (parent) ................................... SUCCESS [  0.646 s]
[INFO] javalin ............................................ SUCCESS [ 32.890 s]
[INFO] javalin-utils ...................................... SUCCESS [  0.015 s]
[INFO] javalin-context-mock ............................... SUCCESS [  2.358 s]
[INFO] javalin-testtools .................................. SUCCESS [  3.094 s]
[INFO] javalin-micrometer ................................. SUCCESS [  2.332 s]
[INFO] javalin-bundle ..................................... SUCCESS [  0.077 s]
[INFO] javalin-rendering .................................. SUCCESS [  8.396 s]
[INFO] Javalin SSL Plugin ................................. SUCCESS [ 11.083 s]
[INFO] Jacoco Coverage Report ............................. SUCCESS [  0.038 s]
[INFO] javalin-osgi ....................................... FAILURE [  0.560 s]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  01:02 min
[INFO] Finished at: 2025-05-12T09:56:06+05:30
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-dependency-plugin:2.8:unpack-dependencies (unpack-everything) on project javalin-osgi: Artifact has not been packaged yet. When used on reactor artifact, unpack should be executed after packaging: see MDEP-98. -> [Help 1]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException
[ERROR] 
[ERROR] After correcting the problems, you can resume the build with the command
[ERROR]   mvn <args> -rf :javalin-osgi

@lazysegtree
Copy link

lazysegtree commented May 12, 2025

I can do a complete test run without errors.

mvn clean install

Details

[INFO]
[INFO] --- maven-bundle-plugin:5.1.9:install (default-install) @ javalin-osgi ---
[INFO] Installing io/javalin/javalin-osgi/6.6.1-SNAPSHOT/javalin-osgi-6.6.1-SNAPSHOT.jar
[INFO] Writing OBR metadata
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary for Javalin (parent) 6.6.1-SNAPSHOT:
[INFO]
[INFO] Javalin (parent) ................................... SUCCESS [  0.310 s]
[INFO] javalin ............................................ SUCCESS [ 52.688 s]
[INFO] javalin-utils ...................................... SUCCESS [  0.010 s]
[INFO] javalin-context-mock ............................... SUCCESS [  2.341 s]
[INFO] javalin-testtools .................................. SUCCESS [  2.219 s]
[INFO] javalin-micrometer ................................. SUCCESS [  1.547 s]
[INFO] javalin-bundle ..................................... SUCCESS [  0.036 s]
[INFO] javalin-rendering .................................. SUCCESS [  4.356 s]
[INFO] Javalin SSL Plugin ................................. SUCCESS [  8.240 s]
[INFO] Jacoco Coverage Report ............................. SUCCESS [  0.630 s]
[INFO] javalin-osgi ....................................... SUCCESS [  1.445 s]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  01:14 min
[INFO] Finished at: 2025-05-12T15:02:09+05:30
[INFO] ------------------------------------------------------------------------
➜  ~/Workspace/Other_proj/hupender/javalin git:(static_roles) [3:02:11] mvn clean install; say done
➜  ~/Workspace/Other_proj/hupender/javalin git:(static_roles) [3:02:13] git log --oneline | head -n 4
0c85e806 unit test cases added and bug fixes
61ee16ef feat: Add route roles for static files
bbe45ad9 [context] Add disableCompression() to disable response compression per request
1177ba2f [loom] Fix virtual threads bug for GraalVM (#2361)
➜  ~/Workspace/Other_proj/hupender/javalin git:(static_roles)

@tipsy
Copy link
Member

tipsy commented May 12, 2025

@hupender
Copy link
Contributor Author

hupender commented May 13, 2025

@tipsy
Copy link
Member

tipsy commented May 14, 2025

Thanks - running again !

@codecov
Copy link

codecov bot commented May 14, 2025

Codecov Report

Attention: Patch coverage is 94.73684% with 1 line in your changes missing coverage. Please review.

Project coverage is 87.21%. Comparing base (93aafbc) to head (931baec).
Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
...main/java/io/javalin/jetty/JettyResourceHandler.kt 88.88% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##             master    #2403      +/-   ##
============================================
+ Coverage     87.20%   87.21%   +0.01%     
- Complexity     1334     1340       +6     
============================================
  Files           148      148              
  Lines          4493     4506      +13     
  Branches        513      516       +3     
============================================
+ Hits           3918     3930      +12     
- Misses          363      364       +1     
  Partials        212      212              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@lazysegtree
Copy link

Project coverage is 0.00%.

@tipsy Something is wrong with codecov.
Even master's coverage is shown as 0%

https://app.codecov.io/gh/javalin/javalin
image

@lazysegtree
Copy link

Could be due to these commits

image

@tipsy
Copy link
Member

tipsy commented May 16, 2025

Thanks guys - I'll have a look to see what's happened here on sunday.

@tipsy
Copy link
Member

tipsy commented May 18, 2025

Codecov is fixed - I rebased the PR too. Will have a look now.

Comment on lines 28 to 35
val willMatch by javalinLazy {
var routeRoles: Set<RouteRole> = servlet.matchedRoles(ctx, requestUri)
if (httpHandlerOrNull == null && (ctx.method() == HEAD || ctx.method() == GET)) {
routeRoles = servlet.cfg.pvt.resourceHandler?.getResourceRouteRoles(ctx) ?: emptySet()
}
ctx.setRouteRoles(routeRoles) // set roles for the matched handler
servlet.willMatch(ctx, requestUri)
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
val willMatch by javalinLazy {
var routeRoles: Set<RouteRole> = servlet.matchedRoles(ctx, requestUri)
if (httpHandlerOrNull == null && (ctx.method() == HEAD || ctx.method() == GET)) {
routeRoles = servlet.cfg.pvt.resourceHandler?.getResourceRouteRoles(ctx) ?: emptySet()
}
ctx.setRouteRoles(routeRoles) // set roles for the matched handler
servlet.willMatch(ctx, requestUri)
}
val isResourceHandler = httpHandlerOrNull == null && ctx.method() in setOf(HEAD, GET)
val matchedRouteRoles by javalinLazy { servlet.matchedRoles(ctx, requestUri) }
val resourceRouteRoles by javalinLazy { servlet.cfg.pvt.resourceHandler?.getResourceRouteRoles(ctx) ?: emptySet() }
val willMatch by javalinLazy {
ctx.setRouteRoles(if (isResourceHandler) resourceRouteRoles else matchedRouteRoles)
servlet.willMatch(ctx, requestUri)
}


override fun getResourceRouteRoles(ctx: Context): Set<RouteRole> {
nonSkippedHandlers(ctx.jettyReq()).forEach { handler ->
val target = ctx.target
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this use url decoder too?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tipsy, yes we have to use decoder here as well and I have done all the suggested changes.

@tipsy
Copy link
Member

tipsy commented May 24, 2025

Thanks guys - sorry this is taking some time, I am in the process of moving houses.

@tipsy
Copy link
Member

tipsy commented Jun 15, 2025

Thanks @hupender, this looks really great. Sorry again about the long wait, I just got my home office up and running.

@tipsy tipsy merged commit 7a6256a into javalin:master Jun 15, 2025
15 checks passed
@tipsy tipsy mentioned this pull request Jun 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants