as I had the issues evaluating the ctx.pathParam("mypath")
inside of a before handler, I want to share my issue as well as my solution.
It seams to be not allowed to call ctx.pathParam("...")
inside of a before handler in javalin context.
It throws the following error:
java.lang.IllegalArgumentException: 'mypath' is not a valid path-param for '*'.
at io.javalin.http.servlet.JavalinServletContextKt.pathParamOrThrow(JavalinServletContext.kt:212)
at io.javalin.http.servlet.JavalinServletContext.pathParam(JavalinServletContext.kt:147)
at de.cryptosdk.mail.handler.MyHandler.lambda$static$0(MyHandler.java:31)
(javalin 6.3.0, java 21)
It seems to not be allowed to call ctx.pathParam("...")
inside of a before handler in a Javalin context.
My solution is to extract the path parameter using ctx.path()
Working solution:
String pathParam = ctx.path().replaceAll("/([0-9A-Za-z-]+)(/.*)?","$1");
(Javalin 6.3.0, Java 21)