From 4a20940e99bc5b08d67dad3dae1907a20a257be9 Mon Sep 17 00:00:00 2001 From: Naoki Takezoe Date: Thu, 12 Oct 2023 00:37:22 +0900 Subject: [PATCH] Minor fixes for Scalatra 3.0 examples (#86) --- 3.0/async/pekko-examples/build.sbt | 16 ++++++++-------- .../scala/com/example/app/FutureController.scala | 6 ++++-- 3.0/persistence/scalatra-slick/build.sbt | 10 +++++----- 3.0/persistence/scalatra-squeryl/build.sbt | 4 ++-- .../src/main/scala/ScalatraBootstrap.scala | 2 +- .../src/main/scala/ScalatraBootstrap.scala | 2 +- 6 files changed, 21 insertions(+), 19 deletions(-) diff --git a/3.0/async/pekko-examples/build.sbt b/3.0/async/pekko-examples/build.sbt index 8b5dbd8..8fdebe0 100644 --- a/3.0/async/pekko-examples/build.sbt +++ b/3.0/async/pekko-examples/build.sbt @@ -6,14 +6,14 @@ scalaVersion := "3.3.1" val ScalatraVersion = "3.0.0" libraryDependencies ++= Seq( - "org.apache.pekko" %% "pekko-actor" % "1.0.0" cross(CrossVersion.for3Use2_13), - "org.apache.pekko" %% "pekko-http" % "1.0.0" cross(CrossVersion.for3Use2_13), - "org.scalaj" %% "scalaj-http" % "2.4.2" cross(CrossVersion.for3Use2_13), - "ch.qos.logback" % "logback-classic" % "1.4.11" % Provided, - "org.scalatra" %% "scalatra-jakarta" % ScalatraVersion, - "org.scalatra" %% "scalatra-specs2-jakarta" % ScalatraVersion % "test", - "org.eclipse.jetty" % "jetty-webapp" % "11.0.15" % "provided", - "jakarta.servlet" % "jakarta.servlet-api" % "5.0.0" % "provided" + "org.apache.pekko" %% "pekko-actor" % "1.0.0" cross(CrossVersion.for3Use2_13), + "org.apache.pekko" %% "pekko-http" % "1.0.0" cross(CrossVersion.for3Use2_13), + "com.softwaremill.sttp.client3" %% "core" % "3.9.0", + "org.scalatra" %% "scalatra-jakarta" % ScalatraVersion, + "org.scalatra" %% "scalatra-specs2-jakarta" % ScalatraVersion % Test, + "ch.qos.logback" % "logback-classic" % "1.4.11" % Provided, + "org.eclipse.jetty" % "jetty-webapp" % "11.0.15" % Provided, + "jakarta.servlet" % "jakarta.servlet-api" % "5.0.0" % Provided ) enablePlugins(JettyPlugin) diff --git a/3.0/async/pekko-examples/src/main/scala/com/example/app/FutureController.scala b/3.0/async/pekko-examples/src/main/scala/com/example/app/FutureController.scala index bd3e0d0..6227127 100644 --- a/3.0/async/pekko-examples/src/main/scala/com/example/app/FutureController.scala +++ b/3.0/async/pekko-examples/src/main/scala/com/example/app/FutureController.scala @@ -1,7 +1,7 @@ package com.example.app import org.apache.pekko.actor.ActorSystem -import scalaj.http.{Http => SJHttp} +import sttp.client3._ import org.scalatra._ @@ -23,7 +23,9 @@ class FutureController(system: ActorSystem) extends ScalatraServlet with FutureS object HttpClient { def retrievePage()(implicit ctx: ExecutionContext): Future[String] = { Future { - val response = SJHttp("https://scalatra.org/").asString + val backend = HttpClientSyncBackend() + val request = basicRequest.get(uri"https://scalatra.org/").response(asStringAlways) + val response = request.send(backend) response.body } } diff --git a/3.0/persistence/scalatra-slick/build.sbt b/3.0/persistence/scalatra-slick/build.sbt index 33882da..219ef58 100644 --- a/3.0/persistence/scalatra-slick/build.sbt +++ b/3.0/persistence/scalatra-slick/build.sbt @@ -6,14 +6,14 @@ scalaVersion := "3.3.1" val ScalatraVersion = "3.0.0" libraryDependencies ++= Seq( - "org.scalatra" %% "scalatra-jakarta" % ScalatraVersion, - "org.scalatra" %% "scalatra-specs2-jakarta" % ScalatraVersion % "test", "com.typesafe.slick" %% "slick" % "3.5.0-M4", "com.h2database" % "h2" % "1.4.200", "com.mchange" % "c3p0" % "0.9.5.5", - "ch.qos.logback" % "logback-classic" % "1.4.11" % "provided", - "org.eclipse.jetty" % "jetty-webapp" % "11.0.15" % "provided", - "jakarta.servlet" % "jakarta.servlet-api" % "5.0.0" % "provided" + "org.scalatra" %% "scalatra-jakarta" % ScalatraVersion, + "org.scalatra" %% "scalatra-specs2-jakarta" % ScalatraVersion % Test, + "ch.qos.logback" % "logback-classic" % "1.4.11" % Provided, + "org.eclipse.jetty" % "jetty-webapp" % "11.0.15" % Provided, + "jakarta.servlet" % "jakarta.servlet-api" % "5.0.0" % Provided ) enablePlugins(JettyPlugin) diff --git a/3.0/persistence/scalatra-squeryl/build.sbt b/3.0/persistence/scalatra-squeryl/build.sbt index 25d12c7..1684226 100644 --- a/3.0/persistence/scalatra-squeryl/build.sbt +++ b/3.0/persistence/scalatra-squeryl/build.sbt @@ -6,11 +6,11 @@ scalaVersion := "3.3.1" val ScalatraVersion = "3.0.0" libraryDependencies ++= Seq( - "org.scalatra" %% "scalatra-jakarta" % ScalatraVersion, - "org.scalatra" %% "scalatra-scalatest-jakarta" % ScalatraVersion % Test, "org.squeryl" %% "squeryl" % "0.10.0", "com.h2database" % "h2" % "1.4.200", "com.mchange" % "c3p0" % "0.9.5.5", + "org.scalatra" %% "scalatra-jakarta" % ScalatraVersion, + "org.scalatra" %% "scalatra-scalatest-jakarta" % ScalatraVersion % Test, "ch.qos.logback" % "logback-classic" % "1.4.11" % Provided, "org.eclipse.jetty" % "jetty-webapp" % "11.0.15" % Provided, "jakarta.servlet" % "jakarta.servlet-api" % "5.0.0" % Provided diff --git a/3.0/persistence/scalatra-squeryl/src/main/scala/ScalatraBootstrap.scala b/3.0/persistence/scalatra-squeryl/src/main/scala/ScalatraBootstrap.scala index c75c453..8f8b8c5 100644 --- a/3.0/persistence/scalatra-squeryl/src/main/scala/ScalatraBootstrap.scala +++ b/3.0/persistence/scalatra-squeryl/src/main/scala/ScalatraBootstrap.scala @@ -7,7 +7,7 @@ class ScalatraBootstrap extends LifeCycle with DatabaseInit { override def init(context: ServletContext) = { configureDb - context mount (new ArticlesController, "/*") + context.mount(new ArticlesController, "/*") } override def destroy(context:ServletContext) = { diff --git a/3.0/swagger-example/src/main/scala/ScalatraBootstrap.scala b/3.0/swagger-example/src/main/scala/ScalatraBootstrap.scala index 3572c6c..3db6724 100644 --- a/3.0/swagger-example/src/main/scala/ScalatraBootstrap.scala +++ b/3.0/swagger-example/src/main/scala/ScalatraBootstrap.scala @@ -11,6 +11,6 @@ class ScalatraBootstrap extends LifeCycle { // This is tentative. We will rewrite it once the official version of Scalatra 2.7 is released. context.setInitParameter("org.scalatra.cors.allowedOrigins", "http://petstore.swagger.io") context.mount(new FlowersController, "/flowers", "flowers") - context.mount (new ResourcesApp, "/api-docs") + context.mount(new ResourcesApp, "/api-docs") } }