Scalatra shutting down system - "No Such Method Error" - scala

I have some code in Scalatra using Atmosphere framework that keeps causing the system to crash after a web request is made. The console shows the data being sent from server to client, but straight after it the following error always appears:
Uncaught error from thread [default-akka.actor.default-dispatcher-11] shutting down JVM since 'akka.jvm-exit-on-fatal-error' is enabled for ActorSystem[default]
java.lang.NoSuchMethodError: akka.actor.ActorSystem.dispatcher()Lakka/dispatch/MessageDispatcher;
at org.scalatra.atmosphere.package$.jucFuture2akkaFuture(package.scala:29)
at org.scalatra.atmosphere.ScalatraBroadcaster.broadcast(ScalatraBroadcaster.scala:19)
I am using dispatch to make the web requests inside m actors. But I got the same message when I was using spray.
Here is how I make the web request:
Http(Req(_.setUrl(fullUrl))) map {response =>
But the error happens after data has been sent to the client (as you can see the call to "broadcast" in the stack trace. So I don't think it is the web request.
My project build file:
lazy val project = Project (
"",
file("."),
settings = Defaults.defaultSettings ++ ScalatraPlugin.scalatraWithJRebel ++ scalateSettings ++ assemblySettings ++ Seq(
organization := Organization,
name := Name,
version := Version,
scalaVersion := ScalaVersion,
resolvers += Classpaths.typesafeReleases,
test in assembly := {},
jarName in assembly := "",
mergeStrategy in assembly <<= (mergeStrategy in assembly) { (old) =>
{
case PathList(xs) if xs.equals("about.html") => MergeStrategy.first
case x => old(x)
}
},
libraryDependencies ++= Seq(
"org.scalatra" %% "scalatra" % ScalatraVersion,
"org.scalatra" %% "scalatra-scalate" % ScalatraVersion,
"org.scalatra" %% "scalatra-specs2" % ScalatraVersion % "test",
"ch.qos.logback" % "logback-classic" % "1.0.6" % "runtime",
"org.eclipse.jetty" % "jetty-webapp" % "8.1.8.v20121106" % "container;compile",
"org.eclipse.jetty.orbit" % "javax.servlet" % "3.0.0.v201112011016" % "container;provided;test;compile" artifacts (Artifact("javax.servlet", "jar", "jar")),
"org.scalatra" %% "scalatra-atmosphere" % "2.2.1",
"org.scalatra" %% "scalatra-json" % "2.2.1",
"org.json4s" %% "json4s-jackson" % "3.2.4",
"org.eclipse.jetty" % "jetty-websocket" % "8.1.10.v20130312" % "container;compile",
"org.scalatest" % "scalatest_2.10" % "2.0.M6-SNAP17",
"com.typesafe.akka" % "akka-testkit_2.10" % "2.2.0",
"joda-time" % "joda-time" % "2.3",
"com.github.nscala-time" %% "nscala-time" % "0.6.0",
"com.cloudphysics" % "jerkson_2.10" % "0.6.3",
"net.databinder.dispatch" %% "dispatch-core" % "0.11.0"
I looked at the source code of scalatra and it appears that it is code inside the future that is blowing up. I am using the following execution context, which may be relevant:
implicit val ec: ExecutionContext = context.dispatcher

I'm going to take a guess here and say that you are pulling in two versions of the akka-actor jar. You explicitly referencing akka-testkit is going to pull in the akka-actor 2.2.0 jar. I'm guessing that something else (maybe scalatra atmosphere) is also pulling in akka-actor and not the 2.2.0 version. You should check your classpath and see if you indeed to have two versions of akka-actor

Related

Jetty-webapp unknown artifact in sbt

I created Scalatara application to build a web service. It uses Jetty server and it was included in the build.sbt file when I created the project itself.
But when I try to start the jetty server using the command - jetty:start, it shows me an error message "not a valid key: jetty". Then when I checked the build file, it shows a warning message as "unknown artifact in sbt" for the below dependency.
"org.eclipse.jetty" % "jetty-webapp" % "9.4.6.v20170531" % "container"
I used the latest dependency from the MVN Repository but still, it shows the same error. Is there anything else I have to do here?
How did you create the project? Is there a way you can tell me so I can reproduce it. Will be much easier to figure out. Anyways, you can try to add a resolver first to your build.sbt :
resolvers += "Jetty" at "https://mvnrepository.com/artifact/org.eclipse.jetty/jetty-webapp"
Kindly compare the code of build.sbt file shown below and if anything missing you should update in you build.st file.
import org.scalatra.sbt._
import org.scalatra.sbt.PluginKeys._
import ScalateKeys._
val ScalatraVersion = "2.5.1"
ScalatraPlugin.scalatraSettings
scalateSettings
organization := "com.github.karthikeyana"
name := "My Scalatra Web App"
version := "0.1.0-SNAPSHOT"
scalaVersion := "2.12.3"
resolvers += Classpaths.typesafeReleases
libraryDependencies ++= Seq(
"org.scalatra" %% "scalatra" % ScalatraVersion,
"org.scalatra" %% "scalatra-scalate" % ScalatraVersion,
"org.scalatra" %% "scalatra-specs2" % ScalatraVersion % "test",
"ch.qos.logback" % "logback-classic" % "1.1.5" % "runtime",
"org.eclipse.jetty" % "jetty-webapp" % "9.2.15.v20160210" % "container",
"javax.servlet" % "javax.servlet-api" % "3.1.0" % "provided",
"org.mongodb" %% "casbah" % "3.1.1"
)
scalateTemplateConfig in Compile := {
val base = (sourceDirectory in Compile).value
Seq(
TemplateConfig(
base / "webapp" / "WEB-INF" / "templates",
Seq.empty, /* default imports should be added here */
Seq(
Binding("context", "_root_.org.scalatra.scalate.ScalatraRenderContext", importMembers = true, isImplicit = true)
), /* add extra bindings here */
Some("templates")
)
)
}
enablePlugins(JettyPlugin)

sbt not setting javaOptions in a forked setting

I'm trying to instrument my server with Kamon, which requires Aspectj weaver. I'm using sbt 0.13.8
However, the options aren't being passed to the forked process.
I've looked here:
https://github.com/eigengo/activator-akka-aspectj/blob/master/build.sbt
and here:
http://www.scala-sbt.org/0.13/docs/Forking.html
And this is my build.sbt:
import sbt.Keys._
name := """myApp"""
version := "0.0.1"
lazy val root = (project in file(".")).enablePlugins(PlayScala)
scalaVersion := "2.11.6"
libraryDependencies ++= Seq(
//jdbc, don not enable this when using slick
cache,
ws,
specs2 % Test,
"com.typesafe.akka" %% "akka-contrib" % "2.4.+",
"org.scalatest" % "scalatest_2.11" % "2.2.4" % "test",
"org.scalatestplus" %% "play" % "1.4.0-M3" % "test",
"com.github.seratch" %% "awscala" % "0.5.+",
"com.typesafe.play" %% "play-slick" % "1.1.1",
"com.typesafe.play" %% "play-slick-evolutions" % "1.1.1",
"mysql" % "mysql-connector-java" % "5.1.+",
"commons-net" % "commons-net" % "3.3",
"net.sourceforge.htmlcleaner" % "htmlcleaner" % "2.15",
"io.strongtyped" %% "active-slick" % "0.3.3",
"org.aspectj" % "aspectjweaver" % "1.8.8",
"org.aspectj" % "aspectjrt" % "1.8.8",
"io.kamon" %% "kamon-core" % "0.5.+",
// "io.kamon" %% "kkamon-system-metrics" % "0.5.+",
"io.kamon" %% "kamon-scala" % "0.5.+",
// "io.kamon" %% "kamon-akka" % "0.5.+",
"io.kamon" %% "kamon-datadog" % "0.5.+"
)
resolvers ++= Seq(
"scalaz-bintray" at "http://dl.bintray.com/scalaz/releases"
)
// Play provides two styles of routers, one expects its actions to be injected, the
// other, legacy style, accesses its actions statically.
routesGenerator := InjectedRoutesGenerator
javaOptions in run += "-javaagent:" + System.getProperty("user.home") + "/.ivy2/cache/org.aspectj/aspectjweaver/jars/aspectjweaver-1.8.8.jar -Xmx:2G"
fork in run := true
connectInput in run := true
I've tried running the app using ./activator start as well as ./activator stage and then running the script.
What am I doing wrong?
Thanks!
The production application should be configurable during deployment. This is my example of start script:
PARAMETERS="-Dconfig.file=conf/production.conf -Dlogger.file=conf/prod-logger.xml"
PARAMETERS="$PARAMETERS -Dhttp.port=9000"
PARAMETERS="$PARAMETERS -J-Xmx8g -J-Xms8g -J-server -J-verbose:gc -J-Xloggc:../logs/portal/gc.log -J-XX:+PrintGCDateStamps"
nohup bin/myApp $PARAMETERS &
For more details see Production Configuration

Spray microservice assembly deduplicate

I'm using this template to develop a microservice:
http://www.typesafe.com/activator/template/activator-service-container-tutorial
My sbt file is like this:
import sbt._
import Keys._
name := "activator-service-container-tutorial"
version := "1.0.1"
scalaVersion := "2.11.6"
crossScalaVersions := Seq("2.10.5", "2.11.6")
resolvers += "Scalaz Bintray Repo" at "https://dl.bintray.com/scalaz/releases"
libraryDependencies ++= {
val containerVersion = "1.0.1"
val configVersion = "1.2.1"
val akkaVersion = "2.3.9"
val liftVersion = "2.6.2"
val sprayVersion = "1.3.3"
Seq(
"com.github.vonnagy" %% "service-container" % containerVersion,
"com.github.vonnagy" %% "service-container-metrics-reporting" % containerVersion,
"com.typesafe" % "config" % configVersion,
"com.typesafe.akka" %% "akka-actor" % akkaVersion exclude ("org.scala-lang" , "scala-library"),
"com.typesafe.akka" %% "akka-slf4j" % akkaVersion exclude ("org.slf4j", "slf4j-api") exclude ("org.scala-lang" , "scala-library"),
"ch.qos.logback" % "logback-classic" % "1.1.3",
"io.spray" %% "spray-can" % sprayVersion,
"io.spray" %% "spray-routing" % sprayVersion,
"net.liftweb" %% "lift-json" % liftVersion,
"com.typesafe.akka" %% "akka-testkit" % akkaVersion % "test",
"io.spray" %% "spray-testkit" % sprayVersion % "test",
"junit" % "junit" % "4.12" % "test",
"org.scalaz.stream" %% "scalaz-stream" % "0.7a" % "test",
"org.specs2" %% "specs2-core" % "3.5" % "test",
"org.specs2" %% "specs2-mock" % "3.5" % "test",
"com.twitter" %% "finagle-http" % "6.25.0",
"com.twitter" %% "bijection-util" % "0.7.2"
)
}
scalacOptions ++= Seq(
"-unchecked",
"-deprecation",
"-Xlint",
"-Ywarn-dead-code",
"-language:_",
"-target:jvm-1.7",
"-encoding", "UTF-8"
)
crossPaths := false
parallelExecution in Test := false
assemblyJarName in assembly := "santo.jar"
mainClass in assembly := Some("Service")
The project compiles fine!
But when I run assembly, the terminal show me this:
[error] (*:assembly) deduplicate: different file contents found in the following:
[error] /path/.ivy2/cache/io.dropwizard.metrics/metrics-core/bundles/metrics-core-3.1.1.jar:com/codahale/metrics/ConsoleReporter$1.class
[error] /path/.ivy2/cache/com.codahale.metrics/metrics-core/bundles/metrics-core-3.0.1.jar:com/codahale/metrics/ConsoleReporter$1.class
What options do I have to fix it?
Thanks
The issue as it seems transitive dependency of the dependency is resulting with two different versions of metrics-core. The best thing to do would be to used the right library dependency so that you end up with a single version of this library. Please use https://github.com/jrudolph/sbt-dependency-graph , if it is difficult to figure out dependencies.
If it is not possible to get to a single version then you would most likely to go down exclude route . I assume, this only work, if there is compatibility between the all required versions.

Play Specs2 test: ReactiveMongoPlugin Error

I'm using Play Framework, Akka Persistent actors and MongoDB.
When I run my Specs2 Test with FakeApplication, java.lang.ExceptionInInitializerError is thrown and the cause is the following:
Caused by: #6md6ke2n9: ReactiveMongoPlugin Error
at play.modules.reactivemongo.ReactiveMongoPlugin$.current(ReactiveMongoPlugin.scala:83)
at play.modules.reactivemongo.ReactiveMongoPlugin$.db(ReactiveMongoPlugin.scala:78)
at models.daos.TaskDAO$.<init>(TaskDAO.scala:25)
at models.daos.TaskDAO$.<clinit>(TaskDAO.scala)
This occurs when ReactiveMongoPlugin.db is invoked.
def db: reactivemongo.api.DB = ReactiveMongoPlugin.db
val futureCollection: Future[JSONCollection] = {
val db = ReactiveMongoPlugin.db
// ...
}
This problem has occurred since I started using PersistentActor. I don't know if there is some conflict between akka-persistence and reactive-mongo dependencies. The following is my build.sbt:
name := "fmcloud"
version := "0.1"
scalaVersion := "2.11.6"
lazy val root = (project in file(".")).enablePlugins(PlayScala)
resolvers := ("Atlassian Releases" at "https://maven.atlassian.com/public/") +: resolvers.value
resolvers += Resolver.sonatypeRepo("snapshots")
resolvers += "Sonatype OSS Snapshots" at "https://oss.sonatype.org/content/repositories/releases"
libraryDependencies ++= Seq(
"javax.inject" % "javax.inject" % "1",
"org.reactivemongo" %% "play2-reactivemongo" % "0.10.5.0.akka23",
"net.codingwell" %% "scala-guice" % "4.0.0-beta5",
"org.webjars" % "bootstrap" % "3.3.1",
"org.webjars" % "angularjs" % "1.3.8",
"org.webjars" % "angular-ui-bootstrap" % "0.12.0",
"org.mockito" % "mockito-core" % "1.10.17" % "test",
"com.mohiva" %% "play-silhouette-testkit" % "2.0" % "test",
"com.mohiva" %% "play-silhouette" % "2.0",
"org.json" % "json" % "20141113",
"javax.websocket" % "javax.websocket-client-api" % "1.1",
"org.glassfish.tyrus" % "tyrus-container-grizzly-client" % "1.4",
"com.typesafe.akka" % "akka-testkit_2.11" % "2.3.10",
"com.typesafe.akka" % "akka-persistence-experimental_2.11" % "2.3.10",
"com.github.ironfish" %% "akka-persistence-mongo-casbah" % "0.7.5" % "compile"
)
EDIT: Proably this was an IntelliJ IDEA issue. I updated both IntelliJ and Scala plugin and now there is no ReactiveMongoPlugin Error. Unfortunately now all test-cases work except one (which involves the PersistentActor).
It is still thrown java.lang.ExceptionInInitializerError but the cause is different:
Caused by: java.lang.RuntimeException: There is no started application
at scala.sys.package$.error(package.scala:27)
at play.api.Play$$anonfun$current$1.apply(Play.scala:71)
at play.api.Play$$anonfun$current$1.apply(Play.scala:71)
at scala.Option.getOrElse(Option.scala:121)
at play.api.Play$.current(Play.scala:71)
at models.daos.TaskDAO$.<init>(TaskDAO.scala:26)
at models.daos.TaskDAO$.<clinit>(TaskDAO.scala)
... 19 more
EDIT2: I noticed that this error occurs only when I use TestActorRef of my persistent actor.

sbt gen-idea scala version error

I receive the following error when running sbt gen-idea:
[error] {file:/home/jem/projects/app/}default-0df603/*:
update-classifiers: Version specified for dependency
org.scala-lang#scalap;2.10.0 differs from Scala version in project (2.10.1).
Despite this the idea files are still created and seem to work. But I worry that they may be incomplete somehow.
Here is my build.sbt:
import com.typesafe.startscript.StartScriptPlugin
organization := "com.github.synesso"
name := "app"
version := "0.1"
scalaVersion := "2.10.1"
seq(webSettings :_*)
classpathTypes ~= (_ + "orbit")
libraryDependencies ++= Seq(
"org.scalatra" % "scalatra_2.10" % "2.2.1",
"org.scalatra" % "scalatra-scalate_2.10" % "2.2.1",
"org.scalatra" % "scalatra-json_2.10" % "2.2.1",
"org.eclipse.jetty" % "jetty-server" % "9.0.1.v20130408",
"org.eclipse.jetty" % "jetty-server" % "9.0.1.v20130408" % "container",
"org.eclipse.jetty" % "jetty-webapp" % "9.0.1.v20130408",
"org.eclipse.jetty" % "jetty-webapp" % "9.0.1.v20130408" % "container",
"org.eclipse.jetty" % "jetty-webapp" % "8.1.7.v20120910" % "container,compile",
"org.eclipse.jetty.orbit" % "javax.servlet" % "3.0.0.v201112011016" % "container,compile" artifacts Artifact("javax.servlet", "jar", "jar"),
"org.json4s" % "json4s-jackson_2.10" % "3.2.4",
"org.slf4j" % "slf4j-simple" % "1.7.5",
"ch.qos.logback" % "logback-classic" % "1.0.11" % "runtime",
"com.google.api-client" % "google-api-client" % "1.14.1-beta",
"com.google.apis" % "google-api-services-plus" % "v1-rev62-1.14.1-beta",
"com.google.apis" % "google-api-services-oauth2" % "v1-rev33-1.14.1-beta",
"com.google.http-client" % "google-http-client-jackson2" % "1.14.1-beta"
)
resolvers += "Sonatype OSS Releases" at "http://oss.sonatype.org/content/repositories/releases/"
seq(StartScriptPlugin.startScriptForClassesSettings: _*)
I've tried mucking around with different versions of scala and the dependencies, but to no avail. What is going on here? Do I need to fix it? If so, how?
This is controlled by the checkExplicit value of the ivyScala setting. You can disable it with:
ivyScala ~= { (is: Option[IvyScala]) =>
for(i <- is) yield
i.copy(checkExplicit = false)
}
I'm surprised that is an error, since I'd normally expect it to be a warning. Also, this check is no longer on by default in 0.13.