diff --git a/README.md b/README.md index 0157467..c593260 100644 --- a/README.md +++ b/README.md @@ -46,7 +46,7 @@ or see https://github.com/Doikor/jsonapi-scala-example There is a very generic JsonApiClient interface for implementing a simple client interface for handling the http query writing side of this -The subproject "akka-client" has an implementation of this using akka-http +The subproject "pekko-client" has an implementation of this using pekko-http The subproject "http4s-client" has an implementation of this using http4s @@ -74,19 +74,19 @@ val filtered = jac.filter[BillingAccount]("some nice filter string here") ### Setup -#### akka-http client +#### pekko-http client ```scala -// needs ActorSystem and Materializer for akka-http +// needs ActorSystem and Materializer for pekko-http // the ApiEndPoint is used to as the "root" where to launch queries import io.lemonlabs.uri.typesafe.dsl._ -import akka.actor.ActorSystem -import akka.stream.ActorMaterializer +import org.apache.pekko.actor.ActorSystem +import org.apache.pekko.stream.Materializer import com.qvantel.jsonapi.ApiEndpoint import com.qvantel.jsonapi.JsonApiClient -import com.qvantel.jsonapi.client.akka.AkkaClient._ +import com.qvantel.jsonapi.client.pekko.PekkoClient._ implicit val system: ActorSystem = ActorSystem() -implicit val materializer: ActorMaterializer = ActorMaterializer() +implicit val materializer: Materializer = Materializer(system) implicit val endpoint: ApiEndpoint = ApiEndpoint.Static("http://localhost:8080/api") val jac = JsonApiClient.instance diff --git a/build.sbt b/build.sbt index 758e4d0..d4da69e 100644 --- a/build.sbt +++ b/build.sbt @@ -25,6 +25,8 @@ ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +import Dependencies.* + val scala213 = Seq( "-deprecation", // Emit warning and location for usages of deprecated APIs. "-encoding", @@ -220,15 +222,12 @@ lazy val model = (project in file("model")) libraryDependencies ++= testDeps ) -val akkaVersion = "2.6.20" -val akkaHttpVersion = "10.2.10" - -lazy val akkaClient = (project in file("akka-client")) +lazy val pekkoClient = (project in file("pekko-client")) .dependsOn(core) .enablePlugins(MacrosCompiler) .settings(scalafixSettings) .settings( - name := "jsonapi-scala-akka-client", + name := "jsonapi-scala-pekko-client", scalaVersion := scalaVersion213, crossScalaVersions := Seq(scalaVersion212, scalaVersion213), scalacOptions ++= { @@ -238,19 +237,21 @@ lazy val akkaClient = (project in file("akka-client")) scala213 }, libraryDependencies ++= Seq( - "com.typesafe.akka" %% "akka-stream" % akkaVersion % Provided, - "com.typesafe.akka" %% "akka-actor" % akkaVersion % Provided, - "com.typesafe.akka" %% "akka-http" % akkaHttpVersion % Provided, - "com.typesafe.akka" %% "akka-http-spray-json" % akkaHttpVersion % Provided + `pekko-stream` % Provided, + `pekko-actor` % Provided, + `pekko-http` % Provided, + `pekko-http-spray-json` % Provided, + "io.lemonlabs" %% "scala-uri" % "4.0.3" % Test, + "org.parboiled" %% "parboiled" % "2.5.1" % Test ) ++ testDeps ) -lazy val akka = (project in file("akka")) +lazy val pekko = (project in file("pekko")) .dependsOn(core, model) .enablePlugins(MacrosCompiler) .settings(scalafixSettings) .settings( - name := "jsonapi-scala-akka", + name := "jsonapi-scala-pekko", scalaVersion := scalaVersion213, crossScalaVersions := Seq(scalaVersion212, scalaVersion213), scalacOptions ++= { @@ -260,16 +261,18 @@ lazy val akka = (project in file("akka")) scala213 }, libraryDependencies ++= Seq( - "com.typesafe.akka" %% "akka-actor" % akkaVersion % Provided excludeAll ( - ExclusionRule(organization = "com.typesafe.akka", name = "akka-cluster"), - ExclusionRule(organization = "com.typesafe.akka", name = "akka-remote") + `pekko-actor` % Provided excludeAll ( + ExclusionRule(organization = "org.apache.pekko", name = "pekko-cluster"), + ExclusionRule(organization = "org.apache.pekko", name = "pekko-remote") ), - "com.typesafe.akka" %% "akka-stream" % akkaVersion % Provided, - "com.typesafe.akka" %% "akka-http" % akkaHttpVersion % Provided, - "com.typesafe.akka" %% "akka-http-core" % akkaHttpVersion % Provided, - "com.typesafe.akka" %% "akka-http-testkit" % akkaHttpVersion % Test, - "com.typesafe.akka" %% "akka-testkit" % akkaVersion % Test, - "org.scalatest" %% "scalatest" % "3.2.14" % Test + `pekko-stream` % Provided, + `pekko-http` % Provided, + `pekko-http-core` % Provided, + `pekko-http-testkit` % Test, + `pekko-testkit` % Test, + "io.lemonlabs" %% "scala-uri" % "4.0.3" % Test, + "org.parboiled" %% "parboiled" % "2.5.1" % Test, + "org.scalatest" %% "scalatest" % "3.2.18" % Test ) ++ testDeps ) @@ -298,7 +301,7 @@ lazy val http4sClient = (project in file("http4s-client")) ) lazy val root = (project in file(".")) - .aggregate(core, model, akkaClient, http4sClient, akka) + .aggregate(core, model, pekkoClient, http4sClient, pekko) .settings( publishArtifact := false, name := "jsonapi-scala", diff --git a/akka-client/src/main/scala/com/qvantel/jsonapi/client/akka/AkkaClient.scala b/pekko-client/src/main/scala/com/qvantel/jsonapi/client/pekko/PekkoClient.scala similarity index 92% rename from akka-client/src/main/scala/com/qvantel/jsonapi/client/akka/AkkaClient.scala rename to pekko-client/src/main/scala/com/qvantel/jsonapi/client/pekko/PekkoClient.scala index fa3eb8f..ed4bad3 100644 --- a/akka-client/src/main/scala/com/qvantel/jsonapi/client/akka/AkkaClient.scala +++ b/pekko-client/src/main/scala/com/qvantel/jsonapi/client/pekko/PekkoClient.scala @@ -1,23 +1,23 @@ -package com.qvantel.jsonapi.client.akka +package com.qvantel.jsonapi.client.pekko import _root_.spray.json._ -import akka.actor.ActorSystem -import akka.http.scaladsl.Http -import akka.http.scaladsl.coding.{Deflate, Gzip, NoCoding} -import akka.http.scaladsl.marshallers.sprayjson.SprayJsonSupport -import akka.http.scaladsl.model._ -import akka.http.scaladsl.model.headers.HttpEncodings -import akka.http.scaladsl.unmarshalling.Unmarshaller._ -import akka.http.scaladsl.unmarshalling._ -import akka.stream.ActorMaterializer +import org.apache.pekko.actor.ActorSystem +import org.apache.pekko.http.scaladsl.Http +import org.apache.pekko.http.scaladsl.coding.{Deflate, Gzip, NoCoding} +import org.apache.pekko.http.scaladsl.marshallers.sprayjson.SprayJsonSupport +import org.apache.pekko.http.scaladsl.model._ +import org.apache.pekko.http.scaladsl.model.headers.HttpEncodings +import org.apache.pekko.http.scaladsl.unmarshalling.Unmarshaller._ +import org.apache.pekko.http.scaladsl.unmarshalling._ +import org.apache.pekko.stream.Materializer import cats.effect.{ContextShift, IO} import io.lemonlabs.uri.Url import io.lemonlabs.uri.typesafe.dsl._ import com.qvantel.jsonapi._ -object AkkaClient { - implicit def instance(implicit m: ActorMaterializer, system: ActorSystem, endpoint: ApiEndpoint): JsonApiClient = { +object PekkoClient { + implicit def instance(implicit m: Materializer, system: ActorSystem, endpoint: ApiEndpoint): JsonApiClient = { import system.dispatcher implicit val cs: ContextShift[IO] = IO.contextShift(system.dispatcher) @@ -186,7 +186,7 @@ object AkkaClient { reqUrl: String, method: HttpMethod = HttpMethods.GET, entity: RequestEntity = HttpEntity.Empty, - headers: List[HttpHeader])(implicit m: ActorMaterializer, system: ActorSystem): IO[HttpResponse] = { + headers: List[HttpHeader])(implicit m: Materializer, system: ActorSystem): IO[HttpResponse] = { import system.dispatcher implicit val cs: ContextShift[IO] = IO.contextShift(system.dispatcher) diff --git a/akka-client/src/test/scala/com/qvantel/jsonapi/client/akka/AkkaClientSpec.scala b/pekko-client/src/test/scala/com/qvantel/jsonapi/client/pekko/PekkoClientSpec.scala similarity index 92% rename from akka-client/src/test/scala/com/qvantel/jsonapi/client/akka/AkkaClientSpec.scala rename to pekko-client/src/test/scala/com/qvantel/jsonapi/client/pekko/PekkoClientSpec.scala index 13cf525..9ca71d5 100644 --- a/akka-client/src/test/scala/com/qvantel/jsonapi/client/akka/AkkaClientSpec.scala +++ b/pekko-client/src/test/scala/com/qvantel/jsonapi/client/pekko/PekkoClientSpec.scala @@ -1,11 +1,10 @@ -package com.qvantel.jsonapi.client.akka +package com.qvantel.jsonapi.client.pekko import scala.language.experimental.macros - import scala.concurrent.Await import scala.concurrent.duration.Duration -import akka.actor.ActorSystem -import akka.stream.ActorMaterializer +import org.apache.pekko.actor.ActorSystem +import org.apache.pekko.stream.Materializer import cats.syntax.traverse._ import cats.data.OptionT import cats.instances.list._ @@ -13,17 +12,16 @@ import io.lemonlabs.uri.typesafe.dsl._ import org.specs2.matcher.MatcherMacros import org.specs2.mutable.Specification import org.specs2.specification.AfterAll - import com.qvantel.jsonapi._ -import com.qvantel.jsonapi.client.akka.AkkaClient._ +import PekkoClient._ -class AkkaClientSpec extends Specification with MatcherMacros with AfterAll { +class PekkoClientSpec extends Specification with MatcherMacros with AfterAll { // this is an integration test. // to run these tests uncomment this and start a jsonapi.org compatible server in the url specified for the endpoint skipAll implicit val system: ActorSystem = ActorSystem() - implicit val m: ActorMaterializer = ActorMaterializer() + implicit val m: Materializer = Materializer(system) implicit val endpoint: ApiEndpoint = ApiEndpoint.Static("http://localhost:8080/api", Map()) val jac = JsonApiClient.instance diff --git a/akka-client/src/test/scala/com/qvantel/jsonapi/client/akka/TestClasses.scala b/pekko-client/src/test/scala/com/qvantel/jsonapi/client/pekko/TestClasses.scala similarity index 93% rename from akka-client/src/test/scala/com/qvantel/jsonapi/client/akka/TestClasses.scala rename to pekko-client/src/test/scala/com/qvantel/jsonapi/client/pekko/TestClasses.scala index 950a120..50d69ed 100644 --- a/akka-client/src/test/scala/com/qvantel/jsonapi/client/akka/TestClasses.scala +++ b/pekko-client/src/test/scala/com/qvantel/jsonapi/client/pekko/TestClasses.scala @@ -1,4 +1,4 @@ -package com.qvantel.jsonapi.client.akka +package com.qvantel.jsonapi.client.pekko import com.qvantel.jsonapi.{ToMany, ToOne, jsonApiResource} import spray.json.DefaultJsonProtocol._ diff --git a/akka-client/src/test/scala/com/qvantel/jsonapi/client/akka/package.scala b/pekko-client/src/test/scala/com/qvantel/jsonapi/client/pekko/package.scala similarity index 88% rename from akka-client/src/test/scala/com/qvantel/jsonapi/client/akka/package.scala rename to pekko-client/src/test/scala/com/qvantel/jsonapi/client/pekko/package.scala index 874c38f..a194b7a 100644 --- a/akka-client/src/test/scala/com/qvantel/jsonapi/client/akka/package.scala +++ b/pekko-client/src/test/scala/com/qvantel/jsonapi/client/pekko/package.scala @@ -5,6 +5,6 @@ import com.qvantel.jsonapi.ApiRoot /** * Created by ahuttunen on 27/04/2017. */ -package object akka { +package object pekko { implicit val apiroot: ApiRoot = ApiRoot.empty } diff --git a/akka/src/main/scala/com/qvantel/jsonapi/akka/JsonApiSupport.scala b/pekko/src/main/scala/com/qvantel/jsonapi/pekko/JsonApiSupport.scala similarity index 92% rename from akka/src/main/scala/com/qvantel/jsonapi/akka/JsonApiSupport.scala rename to pekko/src/main/scala/com/qvantel/jsonapi/pekko/JsonApiSupport.scala index 9a89a68..4d2ced6 100644 --- a/akka/src/main/scala/com/qvantel/jsonapi/akka/JsonApiSupport.scala +++ b/pekko/src/main/scala/com/qvantel/jsonapi/pekko/JsonApiSupport.scala @@ -24,17 +24,17 @@ ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -package com.qvantel.jsonapi.akka - -import _root_.akka.http.scaladsl.Http -import _root_.akka.http.scaladsl.client.RequestBuilding -import _root_.akka.http.scaladsl.marshalling._ -import _root_.akka.http.scaladsl.model._ -import _root_.akka.http.scaladsl.model.headers._ -import _root_.akka.http.scaladsl.unmarshalling._ -import _root_.akka.stream.Materializer -import _root_.akka.stream.scaladsl._ -import _root_.akka.util.{ByteString, Timeout} +package com.qvantel.jsonapi.pekko + +import _root_.org.apache.pekko.http.scaladsl.Http +import _root_.org.apache.pekko.http.scaladsl.client.RequestBuilding +import _root_.org.apache.pekko.http.scaladsl.marshalling._ +import _root_.org.apache.pekko.http.scaladsl.model._ +import _root_.org.apache.pekko.http.scaladsl.model.headers._ +import _root_.org.apache.pekko.http.scaladsl.unmarshalling._ +import _root_.org.apache.pekko.stream.Materializer +import _root_.org.apache.pekko.stream.scaladsl._ +import _root_.org.apache.pekko.util.{ByteString, Timeout} import _root_.spray.json._ import scala.concurrent.{ExecutionContext, Future} @@ -168,9 +168,9 @@ trait JsonApiSupport0 { /** Custom SendReceive that adds the include params into X-Internal-Include * header that can be read by FromResponseUnmarshaller */ -object JsonApiClientAkka extends RequestBuilding { - import _root_.akka.actor._ - import _root_.akka.http.scaladsl.settings.{ClientConnectionSettings, ConnectionPoolSettings} +object JsonApiClientPekko extends RequestBuilding { + import _root_.org.apache.pekko.actor._ + import _root_.org.apache.pekko.http.scaladsl.settings.{ClientConnectionSettings, ConnectionPoolSettings} import scala.concurrent.duration._ diff --git a/akka/src/main/scala/com/qvantel/jsonapi/akka/AkkaExceptionHandler.scala b/pekko/src/main/scala/com/qvantel/jsonapi/pekko/PekkoExceptionHandler.scala similarity index 89% rename from akka/src/main/scala/com/qvantel/jsonapi/akka/AkkaExceptionHandler.scala rename to pekko/src/main/scala/com/qvantel/jsonapi/pekko/PekkoExceptionHandler.scala index 117f503..a151474 100644 --- a/akka/src/main/scala/com/qvantel/jsonapi/akka/AkkaExceptionHandler.scala +++ b/pekko/src/main/scala/com/qvantel/jsonapi/pekko/PekkoExceptionHandler.scala @@ -24,29 +24,26 @@ ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -package com.qvantel.jsonapi.akka - -import com.qvantel.jsonapi.model.ErrorObject +package com.qvantel.jsonapi.pekko import _root_.spray.json.DefaultJsonProtocol._ import _root_.spray.json._ - -import akka.event.LoggingAdapter -import akka.http.scaladsl.model.StatusCodes._ -import akka.http.scaladsl.model.{StatusCode, IllegalRequestException, ContentType} -import akka.http.scaladsl.settings.RoutingSettings -import akka.http.scaladsl.model.{HttpEntity, HttpResponse, MediaTypes} -import akka.http.scaladsl.server.Directives._ -import akka.http.scaladsl.server._ -import akka.http.scaladsl.server.AuthenticationFailedRejection._ +import com.qvantel.jsonapi.model.ErrorObject +import org.apache.pekko.event.LoggingAdapter +import org.apache.pekko.http.scaladsl.model.StatusCodes._ +import org.apache.pekko.http.scaladsl.model._ +import org.apache.pekko.http.scaladsl.server.AuthenticationFailedRejection._ +import org.apache.pekko.http.scaladsl.server.Directives._ +import org.apache.pekko.http.scaladsl.server._ +import org.apache.pekko.http.scaladsl.settings.RoutingSettings import scala.util.control.NonFatal -trait AkkaExceptionHandlerTrait { +trait PekkoExceptionHandlerTrait { - import AkkaExceptionHandlerObject._ + import PekkoExceptionHandlerObject._ - val defaultAkkaRejectionHandler: RejectionHandler = RejectionHandler + val defaultPekkoRejectionHandler: RejectionHandler = RejectionHandler .newBuilder() .handle { case AuthenticationFailedRejection(cause, _) => @@ -146,15 +143,14 @@ trait AkkaExceptionHandlerTrait { } .result() - def defaultAkkaExceptionHandler(implicit settings: RoutingSettings, log: LoggingAdapter): ExceptionHandler = + def defaultPekkoExceptionHandler(implicit settings: RoutingSettings, log: LoggingAdapter): ExceptionHandler = ExceptionHandler { - case e: IllegalRequestException => { + case e: IllegalRequestException => extractRequestContext { ctx => log.warning("Illegal request {}\n\t{}\n\tCompleting with '{}' response", ctx.request, e.getMessage, e.status) complete(jsonApiErrorResponse(e.status, "Illegal Request", e.info.format(settings.verboseErrorMessages))) } - } - case NonFatal(e) => { + case NonFatal(e) => extractRequestContext { ctx => log.error(e, "Error during processing of request {}", ctx.request) complete( @@ -162,11 +158,10 @@ trait AkkaExceptionHandlerTrait { InternalServerError.reason, if (e.getMessage != null) e.getMessage else InternalServerError.defaultMessage)) } - } } } -object AkkaExceptionHandlerObject extends Rejection { +object PekkoExceptionHandlerObject extends Rejection { def jsonApiError(code: StatusCode, title: String, detail: String): JsValue = JsObject("errors" -> List( diff --git a/akka/src/test/scala/com/qvantel/jsonapi/JsonApiSortingAkkaSpec.scala b/pekko/src/test/scala/com/qvantel/jsonapi/JsonApiSortingPekkoSpec.scala similarity index 98% rename from akka/src/test/scala/com/qvantel/jsonapi/JsonApiSortingAkkaSpec.scala rename to pekko/src/test/scala/com/qvantel/jsonapi/JsonApiSortingPekkoSpec.scala index 3625ff8..95a14fc 100644 --- a/akka/src/test/scala/com/qvantel/jsonapi/JsonApiSortingAkkaSpec.scala +++ b/pekko/src/test/scala/com/qvantel/jsonapi/JsonApiSortingPekkoSpec.scala @@ -26,16 +26,16 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ package com.qvantel.jsonapi -import akka.JsonApiSupport._ - -import org.specs2.mutable._ +import pekko.JsonApiSupport._ +import _root_.org.apache.pekko.http.scaladsl.testkit.Specs2RouteTest import _root_.spray.json.DefaultJsonProtocol._ import _root_.spray.json._ -import _root_.akka.http.scaladsl.testkit.Specs2RouteTest import io.lemonlabs.uri.typesafe.dsl._ +import org.apache.pekko.actor.ActorSystem +import org.specs2.mutable._ -final class JsonApiSortingAkkaSpec extends Specification with Specs2RouteTest { - def actorRefFactory = system +final class JsonApiSortingPekkoSpec extends Specification with Specs2RouteTest { + def actorRefFactory: ActorSystem = system implicit val apiRoot: com.qvantel.jsonapi.ApiRoot = ApiRoot(Some("/api")) diff --git a/akka/src/test/scala/com/qvantel/jsonapi/RelatedResponseAkkaSpec.scala b/pekko/src/test/scala/com/qvantel/jsonapi/RelatedResponsePekkoSpec.scala similarity index 89% rename from akka/src/test/scala/com/qvantel/jsonapi/RelatedResponseAkkaSpec.scala rename to pekko/src/test/scala/com/qvantel/jsonapi/RelatedResponsePekkoSpec.scala index ea8af3b..6a738c8 100644 --- a/akka/src/test/scala/com/qvantel/jsonapi/RelatedResponseAkkaSpec.scala +++ b/pekko/src/test/scala/com/qvantel/jsonapi/RelatedResponsePekkoSpec.scala @@ -26,17 +26,19 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ package com.qvantel.jsonapi -import com.qvantel.jsonapi.akka.JsonApiSupport._ - +import pekko.JsonApiSupport._ import org.specs2.mutable._ +import _root_.org.apache.pekko.http.scaladsl.model._ +import _root_.org.apache.pekko.http.scaladsl.server.Directives._ +import _root_.org.apache.pekko.http.scaladsl.testkit.Specs2RouteTest import _root_.spray.json._ -import _root_.spray.json.DefaultJsonProtocol._ -import _root_.akka.http.scaladsl.testkit.Specs2RouteTest -import _root_.akka.http.scaladsl.model._ -import _root_.akka.http.scaladsl.server.Directives._ +import org.apache.pekko.actor.ActorSystem +import org.specs2.mutable._ +import spray.json._ +import DefaultJsonProtocol._ -class RelatedResponseAkkaSpec extends Specification with Specs2RouteTest { - def actorRefFactory = system +class RelatedResponsePekkoSpec extends Specification with Specs2RouteTest { + def actorRefFactory: ActorSystem = system implicit val apiRoot: com.qvantel.jsonapi.ApiRoot = ApiRoot(None) @jsonApiResource final case class Test(id: String, name: String) diff --git a/akka/src/test/scala/com/qvantel/jsonapi/akka/JsonApiSupportSpec.scala b/pekko/src/test/scala/com/qvantel/jsonapi/pekko/JsonApiSupportSpec.scala similarity index 98% rename from akka/src/test/scala/com/qvantel/jsonapi/akka/JsonApiSupportSpec.scala rename to pekko/src/test/scala/com/qvantel/jsonapi/pekko/JsonApiSupportSpec.scala index 0f2169d..9d0a09d 100644 --- a/akka/src/test/scala/com/qvantel/jsonapi/akka/JsonApiSupportSpec.scala +++ b/pekko/src/test/scala/com/qvantel/jsonapi/pekko/JsonApiSupportSpec.scala @@ -24,26 +24,25 @@ ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -package com.qvantel.jsonapi.akka - -import scala.concurrent.Future - -import _root_.akka.http.scaladsl.marshalling.ToEntityMarshaller -import _root_.akka.http.scaladsl.model._ -import _root_.akka.http.scaladsl.server.Directive._ -import _root_.akka.http.scaladsl.server.Directives._ -import _root_.akka.http.scaladsl.server._ -import _root_.akka.http.scaladsl.testkit.Specs2RouteTest +package com.qvantel.jsonapi.pekko + +import _root_.org.apache.pekko.http.scaladsl.marshalling.ToEntityMarshaller +import _root_.org.apache.pekko.http.scaladsl.model._ +import _root_.org.apache.pekko.http.scaladsl.server.Directive._ +import _root_.org.apache.pekko.http.scaladsl.server.Directives._ +import _root_.org.apache.pekko.http.scaladsl.server._ +import _root_.org.apache.pekko.http.scaladsl.testkit.Specs2RouteTest import _root_.spray.json.DefaultJsonProtocol._ import _root_.spray.json._ +import com.qvantel.jsonapi._ +import com.qvantel.jsonapi.model.{ErrorObject, TopLevel} +import com.qvantel.jsonapi.pekko.JsonApiSupport._ import io.lemonlabs.uri.Url import io.lemonlabs.uri.typesafe.dsl._ import org.specs2.mutable.Specification import shapeless._ -import com.qvantel.jsonapi._ -import com.qvantel.jsonapi.akka.JsonApiSupport._ -import com.qvantel.jsonapi.model.{ErrorObject, TopLevel} +import scala.concurrent.Future final class JsonApiSupportSpec extends Specification with Specs2RouteTest { val ct = ContentType(MediaTypes.`application/vnd.api+json`) diff --git a/akka/src/test/scala/com/qvantel/jsonapi/akka/AkkaExceptionHandlerSpec.scala b/pekko/src/test/scala/com/qvantel/jsonapi/pekko/PekkoExceptionHandlerSpec.scala similarity index 94% rename from akka/src/test/scala/com/qvantel/jsonapi/akka/AkkaExceptionHandlerSpec.scala rename to pekko/src/test/scala/com/qvantel/jsonapi/pekko/PekkoExceptionHandlerSpec.scala index 4570167..8ae954c 100644 --- a/akka/src/test/scala/com/qvantel/jsonapi/akka/AkkaExceptionHandlerSpec.scala +++ b/pekko/src/test/scala/com/qvantel/jsonapi/pekko/PekkoExceptionHandlerSpec.scala @@ -24,31 +24,31 @@ ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -package com.qvantel.jsonapi.akka +package com.qvantel.jsonapi.pekko import _root_.spray.json.DefaultJsonProtocol._ import _root_.spray.json.lenses.JsonLenses._ import _root_.spray.json.{JsArray, JsonParser} -import akka.event.Logging -import akka.http.scaladsl.model._ -import akka.http.scaladsl.model.StatusCodes._ -import akka.http.scaladsl.model.headers._ -import akka.http.scaladsl.server.AuthenticationFailedRejection.{CredentialsMissing, CredentialsRejected} -import akka.http.scaladsl.server._ -import akka.http.scaladsl.testkit.Specs2RouteTest +import org.apache.pekko.event.Logging +import org.apache.pekko.http.scaladsl.model._ +import org.apache.pekko.http.scaladsl.model.StatusCodes._ +import org.apache.pekko.http.scaladsl.model.headers._ +import org.apache.pekko.http.scaladsl.server.AuthenticationFailedRejection.{CredentialsMissing, CredentialsRejected} +import org.apache.pekko.http.scaladsl.server._ +import org.apache.pekko.http.scaladsl.testkit.Specs2RouteTest import org.specs2.mutable.Specification -class AkkaExceptionHandlerSpec extends Specification with Directives with Specs2RouteTest { - class TestAkkaExceptionHandler extends AkkaExceptionHandlerTrait +class PekkoExceptionHandlerSpec extends Specification with Directives with Specs2RouteTest { + class TestPekkoExceptionHandler extends PekkoExceptionHandlerTrait - val testAkkaExceptionHandler = new TestAkkaExceptionHandler - implicit val log = Logging(system, "Log") - private[this] val wrap = Directives.handleExceptions(testAkkaExceptionHandler.defaultAkkaExceptionHandler) - val JSON = ContentType(MediaTypes.`application/vnd.api+json`) + val testPekkoExceptionHandler = new TestPekkoExceptionHandler + implicit val log = Logging(system, "Log") + private[this] val wrap = Directives.handleExceptions(testPekkoExceptionHandler.defaultPekkoExceptionHandler) + val JSON = ContentType(MediaTypes.`application/vnd.api+json`) val route = - handleRejections(testAkkaExceptionHandler.defaultAkkaRejectionHandler) { + handleRejections(testPekkoExceptionHandler.defaultPekkoRejectionHandler) { path("authenticationMissing") { reject(AuthenticationFailedRejection(CredentialsMissing, HttpChallenge("Auth", Some("")))) } ~ @@ -114,7 +114,7 @@ class AkkaExceptionHandlerSpec extends Specification with Directives with Specs2 } } - "The Akka ExceptionHandler" should { + "The Pekko ExceptionHandler" should { "Respond with InternalServerError and specified error message" in { Get() ~> wrap { @@ -159,7 +159,7 @@ class AkkaExceptionHandlerSpec extends Specification with Directives with Specs2 } } - "The Akka RejectionHandler" should { + "The Pekko RejectionHandler" should { "authentication should return 401 with credentialsmissing and a proper jsonapi.org error object" in { Get("/authenticationMissing") ~> route ~> check { diff --git a/project/Dependencies.scala b/project/Dependencies.scala new file mode 100644 index 0000000..56f274f --- /dev/null +++ b/project/Dependencies.scala @@ -0,0 +1,15 @@ +import sbt._ + +object Dependencies extends AutoPlugin { + + val `pekko-actor` = "org.apache.pekko" %% "pekko-actor" % "1.0.2" + val `pekko-slf4j` = "org.apache.pekko" %% "pekko-slf4j" % `pekko-actor`.revision + val `pekko-stream` = "org.apache.pekko" %% "pekko-stream" % `pekko-actor`.revision + val `pekko-testkit` = "org.apache.pekko" %% "pekko-testkit" % `pekko-actor`.revision + // + val `pekko-http` = "org.apache.pekko" %% "pekko-http" % "1.0.1" + val `pekko-http-spray-json` = "org.apache.pekko" %% "pekko-http-spray-json" % `pekko-http`.revision + val `pekko-http-core` = "org.apache.pekko" %% "pekko-http-core" % `pekko-http`.revision + val `pekko-http-testkit` = "org.apache.pekko" %% "pekko-http-testkit" % `pekko-http`.revision + +}