Actual behavior (the bug)
I'm trying to use a groovy script to bootstrap and use Javalin in the most basic of use cases. In the following script, I'm simply trying to serve back a string at the root context.
@Grapes([
@Grab(group='io.javalin', module='javalin', version='3.10.1'),
@Grab(group='org.slf4j', module='slf4j-simple', version='1.8.0-beta4'),
])
import io.javalin.Javalin
def app = Javalin.create().start(9999)
app.get("/", ctx -> ctx.result("Hello World"))
The environment I'm trying to run this in is the following:
➜ ~ groovy -version
Groovy Version: 3.0.5 JVM: 14.0.1 Vendor: Oracle Corporation OS: Mac OS X
➜ ~ java -version
openjdk version "11.0.8" 2020-07-14
OpenJDK Runtime Environment AdoptOpenJDK (build 11.0.8+10)
OpenJDK 64-Bit Server VM AdoptOpenJDK (build 11.0.8+10, mixed mode)
The server starts up normally:
➜ ~ groovy javalin_test.groovy
[main] INFO io.javalin.Javalin -
__ __ _
/ /____ _ _ __ ____ _ / /(_)____
__ / // __ `/| | / // __ `// // // __ \
/ /_/ // /_/ / | |/ // /_/ // // // / / /
\____/ \__,_/ |___/ \__,_//_//_//_/ /_/
https://javalin.io/documentation
[main] INFO org.eclipse.jetty.util.log - Logging initialized @1823ms to org.eclipse.jetty.util.log.Slf4jLog
[main] INFO io.javalin.Javalin - Starting Javalin ...
[main] INFO io.javalin.Javalin - Listening on http://localhost:9999/
[main] INFO io.javalin.Javalin - Javalin started in 166ms \o/
````
Then a request issued against the server with curl:
➜ ~ curl -v localhost:9999
GET / HTTP/1.1
Host: localhost:9999
User-Agent: curl/7.64.1
Accept: /< HTTP/1.1 500 Server Error
< Date: Thu, 10 Sep 2020 02:16:05 GMT
< Content-Length: 0
< Server: Jetty(9.4.31.v20200723)
<
- Connection #0 to host localhost left intact
- Closing connection 0
...renders:
[qtp578102596-27] ERROR io.javalin.Javalin - Exception occurred while servicing http-request
java.lang.NoSuchMethodError: 'long io.javalin.http.CachedRequestWrapper.getContentLengthLong()'
at io.javalin.http.CachedRequestWrapper.
at io.javalin.http.JavalinServlet.service(JavalinServlet.kt:32)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:770)
at io.javalin.websocket.JavalinWsServlet.service(JavalinWsServlet.kt:51)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:770)
at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:763)
at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:569)
at org.eclipse.jetty.server.handler.ScopedHandler.nextHandle(ScopedHandler.java:233)
at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:1610)
at org.eclipse.jetty.server.handler.ScopedHandler.nextHandle(ScopedHandler.java:233)
at io.javalin.core.JavalinServer$start$wsAndHttpHandler$1.doHandle(JavalinServer.kt:49)
at org.eclipse.jetty.server.handler.ScopedHandler.nextScope(ScopedHandler.java:188)
at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:507)
at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:1580)
at org.eclipse.jetty.server.handler.ScopedHandler.nextScope(ScopedHandler.java:186)
at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1292)
at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:141)
at org.eclipse.jetty.server.handler.StatisticsHandler.handle(StatisticsHandler.java:173)
at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:127)
at org.eclipse.jetty.server.Server.handle(Server.java:501)
at org.eclipse.jetty.server.HttpChannel.lambda$handle$1(HttpChannel.java:383)
at org.eclipse.jetty.server.HttpChannel.dispatch(HttpChannel.java:556)
at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:375)
at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:273)
at org.eclipse.jetty.io.AbstractConnection$ReadCallback.succeeded(AbstractConnection.java:311)
at org.eclipse.jetty.io.FillInterest.fillable(FillInterest.java:105)
at org.eclipse.jetty.io.ChannelEndPoint$1.run(ChannelEndPoint.java:104)
at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:806)
at org.eclipse.jetty.util.thread.QueuedThreadPool$Runner.run(QueuedThreadPool.java:938)
at java.base/java.lang.Thread.run(Thread.java:832)
**Expected behavior**
Request should return `Hello World`.
**To Reproduce**
Install the JDK and Groovy versions listed above and run the script.
**Additional context**
Based on the limited information about using this with Groovy, I've tried various permutations of tinkering with the maven imports for the Groovy script (handled by Grape declarations):
```groovy
@Grapes([
@Grab(group='io.javalin', module='javalin', version='3.10.1'),
@Grab(group='org.slf4j', module='slf4j-simple', version='1.8.0-beta4'),
@GrabExclude("javax.servlet:servlet-api")
//@Grab(group='javax.servlet', module='javax.servlet-api', version='3.1.0', scope='provided'),
//@GrabConfig(systemClassLoader= true)
])
...without success.
Duplicate of https://github.com/tipsy/javalin/issues/515
Groovy apparently comes bundled with some 3rd party libs, and it looks like Groovy is well known(https://issues.apache.org/jira/browse/GROOVY-5727) for not shipping with the newest servlet-api which I'm guessing Javalin relies on. I do not have any Groovy-experience to know if it's even possible to override/exclude the bundled version.
Yeah it has something to do with the dependency resolution with grapes. It works fine in a gradle project / app.
This works, perfecto.
Most helpful comment
Duplicate of https://github.com/tipsy/javalin/issues/515
Groovy apparently comes bundled with some 3rd party libs, and it looks like Groovy is well known(https://issues.apache.org/jira/browse/GROOVY-5727) for not shipping with the newest servlet-api which I'm guessing Javalin relies on. I do not have any Groovy-experience to know if it's even possible to override/exclude the bundled version.