Scalatra and jetty HTTP client blowing up

1-7 von 7 Nachrichten werden angezeigt
Scalatra and jetty HTTP client blowing up Toby Hobson 26.07.15 14:47
I'm trying to use Jetty's HttpClient in a Scalatra app but it's blowing up with a weird error.

This is the code I wrote:

import org.eclipse.jetty.client.HttpClient
...
get("/get-url/:url") {
val url = params("url")
val myResponse = new HttpClient().GET(url)
"done"
}

And this is the error:

org.fusesource.scalate.TemplateException: scala.tools.nsc.Global$gen$.mkBlock(Lscala/collection/immutable/List;)Lscala/reflect/internal/Trees$Tree;

I read that these errors are normally caused by mixing scala versions but I have only added a Java library? This is my build.scala:

val ScalaVersion = "2.11.7"
val ScalatraVersion = "2.4.0-RC2-2"
...
libraryDependencies ++= Seq(
"org.scalatra" %% "scalatra" % ScalatraVersion,
"org.scalatra" %% "scalatra-scalate" % ScalatraVersion,
"org.eclipse.jetty" % "jetty-client" % "9.2.10.v20150310", // Added by me
"org.scalatra" %% "scalatra-specs2" % ScalatraVersion % "test",
"ch.qos.logback" % "logback-classic" % "1.1.2" % "runtime",
"org.eclipse.jetty" % "jetty-webapp" % "9.2.10.v20150310" % "container",
"javax.servlet" % "javax.servlet-api" % "3.1.0" % "provided"
)

Does anyone have any idea what is happening here? Thanks!

Re: Scalatra and jetty HTTP client blowing up Toby Hobson 26.07.15 15:04
So I discovered that the exception was caused by my incorrect use of http client which generated a null pointer exception. But I would still be intererested to know why this manifested itself as

org.fusesource.scalate.TemplateException: scala.tools.nsc.Global$gen$.mkBlock(Lscala/collection/immutable/List;)Lscala/reflect/internal/Trees$Tree;
Re: [scalatra-user] Scalatra and jetty HTTP client blowing up Ross A. Baker 26.07.15 15:04
Scalate embeds the compiler, which is not binary compatible across Scala point releases.  Try depending explicitly on `"org.scala-lang" % "scala-compiler" % ScalaVersion`.

I prefer not to run a compiler in my applications, and precompile my templates.  This avoids this sort of issue at runtime, and avoids that first-page-is-slow hit in production.  Template precompilation is set up by default in the g8 template.



--
You received this message because you are subscribed to the Google Groups "scalatra-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to scalat...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Re: [scalatra-user] Scalatra and jetty HTTP client blowing up Toby Hobson 26.07.15 16:04
Thanks

To unsubscribe from this group and stop receiving emails from it, send an email to scalatra-use...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Re: [scalatra-user] Scalatra and jetty HTTP client blowing up Toby Hobson 26.07.15 18:41
So I added the dependency as you suggested and I'm using the G8 template with precompilation but I'm still seeing this. Any ideas? I don't know if it's significant but the embedded sbt wasn't working because sbt-launch.jar was corrupt (I believe this is a known issue) so I symlinked to the jar in my existing sbt installation


On Sunday, July 26, 2015 at 11:04:38 PM UTC+1, Ross A. Baker wrote:

To unsubscribe from this group and stop receiving emails from it, send an email to scalatra-use...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Re: [scalatra-user] Scalatra and jetty HTTP client blowing up Toby Hobson 26.07.15 18:54
It may be a coincidence but it worked when I added all three overrides:

dependencyOverrides := Set(
"org.scala-lang" % "scala-library" % ScalaVersion,
"org.scala-lang" % "scala-reflect" % ScalaVersion,

"org.scala-lang" % "scala-compiler" % ScalaVersion
),

It's quite possible that intellij didnt refresh correctly after the first attempt, anyway it's working now :)
Re: [scalatra-user] Scalatra and jetty HTTP client blowing up Stefan Ollinger 27.07.15 04:01

Hey,

this looks like a SBT issue (incremental compilation and scala-reflect), upgrading SBT to 0.13.8 should resolve it.

Regards, Stefan

To unsubscribe from this group and stop receiving emails from it, send an email to scalat...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.