diff --git a/.gitignore b/.gitignore index 517e166..a455a6d 100644 --- a/.gitignore +++ b/.gitignore @@ -32,9 +32,6 @@ native/ # Log files *.log -# Akka Persistence -snapshots - # jenv .java-version .bloop diff --git a/README.md b/README.md index 1e53b78..6926321 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ -# Scala-HTTP-Client +# Scala-Pekko-HTTP-Client -This is a wrapper around the akka-http-client that adds +This is a wrapper around the pekko-http-client that adds * handling for domain errors as HTTP 400 returns * retry logic @@ -9,14 +9,14 @@ This is a wrapper around the akka-http-client that adds * logging * AWS request signing -![Build & Test](https://github.com/moia-oss/scala-http-client/workflows/Build%20&%20Test/badge.svg) -[![Scala 2.13](https://img.shields.io/maven-central/v/io.moia/scala-http-client_2.13.svg)](https://search.maven.org/search?q=scala-http-client_2.13) +![Build & Test](https://github.com/moia-oss/scala-pekko-http-client/workflows/Build%20&%20Test/badge.svg) +[![Scala 2.13](https://img.shields.io/maven-central/v/io.moia/scala-pekko-http-client_2.13.svg)](https://search.maven.org/search?q=scala-pekko-http-client_2.13) [![Scala Steward badge](https://img.shields.io/badge/Scala_Steward-helping-blue.svg?style=flat&logo=data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAA4AAAAQCAMAAAARSr4IAAAAVFBMVEUAAACHjojlOy5NWlrKzcYRKjGFjIbp293YycuLa3pYY2LSqql4f3pCUFTgSjNodYRmcXUsPD/NTTbjRS+2jomhgnzNc223cGvZS0HaSD0XLjbaSjElhIr+AAAAAXRSTlMAQObYZgAAAHlJREFUCNdNyosOwyAIhWHAQS1Vt7a77/3fcxxdmv0xwmckutAR1nkm4ggbyEcg/wWmlGLDAA3oL50xi6fk5ffZ3E2E3QfZDCcCN2YtbEWZt+Drc6u6rlqv7Uk0LdKqqr5rk2UCRXOk0vmQKGfc94nOJyQjouF9H/wCc9gECEYfONoAAAAASUVORK5CYII=)](https://scala-steward.org) ## Usage ```sbt -libraryDependencies += "io.moia" %% "scala-http-client" % "5.0.0" +libraryDependencies += "io.moia" %% "scala-pekko-http-client" % "1.0.0" ``` ```scala @@ -58,7 +58,7 @@ The lib outputs the following response objects (see `io.moia.scalaHttpClient.Htt * HTTP 4xx, 5xx, others => `HttpClientError` * if the deadline expired => `DeadlineExpired` * if an `AwsRequestSigner` is given, but the request already includes an "Authorization" header => `AlreadyAuthorizedException` -* weird akka-errors => `ExceptionOccurred` +* weird pekko-errors => `ExceptionOccurred` ## Custom Logging @@ -110,10 +110,10 @@ See [LoggingExample.scala](/src/it/scala/io/moia/scalaHttpClient/LoggingExample. ## Custom Headers -To use custom-defined headers, you can extend `ModeledCustomHeader` from `akka.http.scaladsl.model.headers`: +To use custom-defined headers, you can extend `ModeledCustomHeader` from `org.apache.pekko.http.scaladsl.model.headers`: ```scala -import akka.http.scaladsl.model.headers.{ModeledCustomHeader, ModeledCustomHeaderCompanion} +import org.apache.pekko.http.scaladsl.model.headers.{ModeledCustomHeader, ModeledCustomHeaderCompanion} import scala.util.Try final class CustomHeader(id: String) extends ModeledCustomHeader[CustomHeader] { @@ -150,18 +150,18 @@ See [HeaderExample.scala](/src/it/scala/io/moia/scalaHttpClient/HeaderExample.sc ## Publishing -[Tag](https://github.com/moia-oss/scala-http-client/tags) the new version (e.g. `v5.0.0`) and push the tags (`git push origin --tags`). +[Tag](https://github.com/moia-oss/scala-pekko-http-client/tags) the new version (e.g. `v1.0.0`) and push the tags (`git push origin --tags`). You need a [public GPG key](https://www.scala-sbt.org/release/docs/Using-Sonatype.html) with your MOIA email and an account on https://oss.sonatype.org that can [access](https://issues.sonatype.org/browse/OSSRH-52948) the `io.moia` group. Add your credentials to `~/.sbt/sonatype_credential` and run ```sbt -sbt:scala-http-client> +publishSigned +sbt:scala-pekko-http-client> +publishSigned ``` Then close and release the [repository](https://oss.sonatype.org/#stagingRepositories). ``` -sbt:scala-http-client> +sonatypeRelease +sbt:scala-pekko-http-client> +sonatypeRelease ``` -Afterwards, add the release to [GitHub](https://github.com/moia-oss/scala-http-client/releases). +Afterwards, add the release to [GitHub](https://github.com/moia-oss/scala-pekko-http-client/releases). diff --git a/build.sbt b/build.sbt index b9a7e51..fe1ad13 100644 --- a/build.sbt +++ b/build.sbt @@ -1,10 +1,10 @@ lazy val root = (project in file(".")) .settings( - name := "scala-http-client", + name := "scala-pekko-http-client", organization := "io.moia", licenses += ("Apache-2.0", url("https://www.apache.org/licenses/LICENSE-2.0")), - scmInfo := Some(ScmInfo(url("https://github.com/moia-oss/scala-http-client"), "scm:git@github.com:moia-oss/scala-http-client.git")), - homepage := Some(url("https://github.com/moia-oss/scala-http-client")), + scmInfo := Some(ScmInfo(url("https://github.com/moia-oss/scala-pekko-http-client"), "scm:git@github.com:moia-oss/scala-pekko-http-client.git")), + homepage := Some(url("https://github.com/moia-oss/scala-pekko-http-client")), scalaVersion := "2.13.11", crossScalaVersions := List("2.12.18", "2.13.11"), versionScheme := Some("early-semver"), @@ -15,7 +15,7 @@ lazy val root = (project in file(".")) case _ => Seq() } }, - libraryDependencies ++= akkaDependencies ++ awsDependencies ++ testDependencies ++ loggingDependencies ++ scalaDependencies + libraryDependencies ++= pekkoDependencies ++ awsDependencies ++ testDependencies ++ loggingDependencies ++ scalaDependencies ) .settings(sonatypeSettings: _*) .configs(IntegrationTest) @@ -31,15 +31,15 @@ lazy val root = (project in file(".")) ) .settings(mimaSettings) -val akkaVersion = "2.6.19" -val akkaHttpVersion = "10.2.10" +val pekkoVersion = "1.0.1" +val pekkoHttpVersion = "1.0.0" -lazy val akkaDependencies = Seq( - "com.typesafe.akka" %% "akka-stream" % akkaVersion, - "com.typesafe.akka" %% "akka-stream-typed" % akkaVersion, - "com.typesafe.akka" %% "akka-http" % akkaHttpVersion, - "com.typesafe.akka" %% "akka-testkit" % akkaVersion % Test, - "com.typesafe.akka" %% "akka-http-testkit" % akkaHttpVersion % Test +lazy val pekkoDependencies = Seq( + "org.apache.pekko" %% "pekko-stream" % pekkoVersion, + "org.apache.pekko" %% "pekko-stream-typed" % pekkoVersion, + "org.apache.pekko" %% "pekko-http" % pekkoHttpVersion, + "org.apache.pekko" %% "pekko-testkit" % pekkoVersion % Test, + "org.apache.pekko" %% "pekko-http-testkit" % pekkoHttpVersion % Test ) lazy val awsJavaSdkVersion = "2.20.153" @@ -104,7 +104,7 @@ lazy val sonatypeSettings = { publishTo := sonatypePublishTo.value, sonatypeProfileName := organization.value, publishMavenStyle := true, - sonatypeProjectHosting := Some(GitHubHosting("moia-oss", "scala-http-client", "oss-support@moia.io")), + sonatypeProjectHosting := Some(GitHubHosting("moia-oss", "scala-pekko-http-client", "oss-support@moia.io")), credentials += Credentials(Path.userHome / ".sbt" / "sonatype_credential") ) } @@ -124,5 +124,5 @@ lazy val sbtGitSettings = Seq( ) lazy val mimaSettings = Seq( - mimaPreviousArtifacts := Set("io.moia" %% "scala-http-client" % "5.0.0") + mimaPreviousArtifacts := Set("io.moia" %% "scala-pekko-http-client" % "1.0.0") ) diff --git a/src/it/scala/io/moia/scalaHttpClient/HeaderExample.scala b/src/it/scala/io/moia/scalaHttpClient/HeaderExample.scala index c910667..32d959a 100644 --- a/src/it/scala/io/moia/scalaHttpClient/HeaderExample.scala +++ b/src/it/scala/io/moia/scalaHttpClient/HeaderExample.scala @@ -1,10 +1,10 @@ package io.moia.scalaHttpClient -import akka.actor.typed.ActorSystem -import akka.actor.typed.scaladsl.Behaviors -import akka.http.scaladsl.model._ -import akka.http.scaladsl.model.headers.{ModeledCustomHeader, ModeledCustomHeaderCompanion} -import akka.http.scaladsl.unmarshalling.{Unmarshal, Unmarshaller} +import org.apache.pekko.actor.typed.ActorSystem +import org.apache.pekko.actor.typed.scaladsl.Behaviors +import org.apache.pekko.http.scaladsl.model._ +import org.apache.pekko.http.scaladsl.model.headers.{ModeledCustomHeader, ModeledCustomHeaderCompanion} +import org.apache.pekko.http.scaladsl.unmarshalling.{Unmarshal, Unmarshaller} import io.moia.scalaHttpClient.ExampleModel.{DomainErrorObject, GatewayException, MySuccessObject} import java.time.Clock diff --git a/src/it/scala/io/moia/scalaHttpClient/LoggingExample.scala b/src/it/scala/io/moia/scalaHttpClient/LoggingExample.scala index 525dd77..a563a9f 100644 --- a/src/it/scala/io/moia/scalaHttpClient/LoggingExample.scala +++ b/src/it/scala/io/moia/scalaHttpClient/LoggingExample.scala @@ -1,8 +1,8 @@ package io.moia.scalaHttpClient -import akka.actor.typed.ActorSystem -import akka.actor.typed.scaladsl.Behaviors -import akka.http.scaladsl.model._ +import org.apache.pekko.actor.typed.ActorSystem +import org.apache.pekko.actor.typed.scaladsl.Behaviors +import org.apache.pekko.http.scaladsl.model._ import com.typesafe.scalalogging._ import io.moia.scalaHttpClient.CustomLogging.LoggingContext import org.slf4j.LoggerFactory diff --git a/src/it/scala/io/moia/scalaHttpClient/SimpleExample.scala b/src/it/scala/io/moia/scalaHttpClient/SimpleExample.scala index bdf47fc..3593fcc 100644 --- a/src/it/scala/io/moia/scalaHttpClient/SimpleExample.scala +++ b/src/it/scala/io/moia/scalaHttpClient/SimpleExample.scala @@ -1,9 +1,9 @@ package io.moia.scalaHttpClient -import akka.actor.typed.ActorSystem -import akka.actor.typed.scaladsl.Behaviors -import akka.http.scaladsl.model._ -import akka.http.scaladsl.unmarshalling.{Unmarshal, Unmarshaller} +import org.apache.pekko.actor.typed.ActorSystem +import org.apache.pekko.actor.typed.scaladsl.Behaviors +import org.apache.pekko.http.scaladsl.model._ +import org.apache.pekko.http.scaladsl.unmarshalling.{Unmarshal, Unmarshaller} import io.moia.scalaHttpClient.ExampleModel.{DomainErrorObject, GatewayException, MySuccessObject} import java.time.Clock diff --git a/src/main/scala/io/moia/scalaHttpClient/AwsRequestSigner.scala b/src/main/scala/io/moia/scalaHttpClient/AwsRequestSigner.scala index d175d18..db27db5 100644 --- a/src/main/scala/io/moia/scalaHttpClient/AwsRequestSigner.scala +++ b/src/main/scala/io/moia/scalaHttpClient/AwsRequestSigner.scala @@ -1,9 +1,9 @@ package io.moia.scalaHttpClient -import akka.http.scaladsl.model.HttpHeader.ParsingResult -import akka.http.scaladsl.model.{HttpHeader, HttpRequest, Uri} -import akka.stream.Materializer -import akka.stream.scaladsl.StreamConverters +import org.apache.pekko.http.scaladsl.model.HttpHeader.ParsingResult +import org.apache.pekko.http.scaladsl.model.{HttpHeader, HttpRequest, Uri} +import org.apache.pekko.stream.Materializer +import org.apache.pekko.stream.scaladsl.StreamConverters import com.typesafe.scalalogging.StrictLogging import software.amazon.awssdk.auth.credentials._ import software.amazon.awssdk.auth.signer.{Aws4Signer, AwsSignerExecutionAttribute} @@ -57,13 +57,13 @@ class AwsRequestSigner private (credentialsProvider: AwsCredentialsProvider, reg /** Checks if the given collection of `HttpHeader`s includes one "Authorization" header * * @param headers - * `Seq[HttpHeader]` headers of an Akka `HttpRequest` + * `Seq[HttpHeader]` headers of a Pekko `HttpRequest` * @return * true if "Authorization" header exists */ private def isAlreadyAuthorized(headers: Seq[HttpHeader]): Boolean = headers.exists(_.is("authorization")) - /** Constructs an `SdkHttpFullRequest` from Akka's `HttpRequest` for signing. + /** Constructs an `SdkHttpFullRequest` from Pekko's `HttpRequest` for signing. * * @param request * HttpRequest to convert @@ -94,7 +94,7 @@ class AwsRequestSigner private (credentialsProvider: AwsCredentialsProvider, reg .build() } - /** Extracts the headers from the `SdkHttpFullRequest` as collection of Akka's `HttpHeader`s + /** Extracts the headers from the `SdkHttpFullRequest` as collection of Pekko's `HttpHeader`s * * @param signedSdkRequest * `SdkHttpFullRequest` after signing diff --git a/src/main/scala/io/moia/scalaHttpClient/HttpClient.scala b/src/main/scala/io/moia/scalaHttpClient/HttpClient.scala index 5af43a7..bb8f68d 100644 --- a/src/main/scala/io/moia/scalaHttpClient/HttpClient.scala +++ b/src/main/scala/io/moia/scalaHttpClient/HttpClient.scala @@ -1,10 +1,11 @@ package io.moia.scalaHttpClient -import akka.actor.typed.ActorSystem -import akka.http.scaladsl.Http -import akka.http.scaladsl.model._ -import akka.http.scaladsl.model.headers.{`Retry-After`, RetryAfterDateTime, RetryAfterDuration} import com.typesafe.scalalogging.{Logger, LoggerTakingImplicit} +import org.apache.pekko.actor.typed.ActorSystem +import org.apache.pekko.http.scaladsl.Http +import org.apache.pekko.http.scaladsl.model._ +import org.apache.pekko.http.scaladsl.model.headers.{`Retry-After`, RetryAfterDateTime, RetryAfterDuration} +import org.apache.pekko.pattern.after import org.slf4j.LoggerFactory import java.time.Clock @@ -148,7 +149,7 @@ abstract class HttpLayer[LoggingContext]( Future.successful(DeadlineExpired(Some(response))) } else { logger.info(s"[$name] Try #$tryNum: Retrying in ${delay.toMillis}ms.") - akka.pattern.after(delay)(executeRequest(request, tryNum + 1, deadline)) + after(delay)(executeRequest(request, tryNum + 1, deadline)) } } else { logger.info(s"[$name] Try #$tryNum: No retries left. Giving up.") @@ -173,7 +174,7 @@ abstract class HttpLayer[LoggingContext]( case NonFatal(e) if tryNum <= retryConfig.retriesException => val delay: FiniteDuration = calculateDelay(None, tryNum) logger.info(s"[$name] Exception in request: ${e.getMessage}, retrying in ${delay.toMillis}ms.", e) - akka.pattern.after(delay)(executeRequest(request, tryNum + 1, deadline)) + after(delay)(executeRequest(request, tryNum + 1, deadline)) case NonFatal(e) => logger.warn(s"[$name] Exception in request: ${e.getMessage}, retries exhausted, giving up.", e) Future.successful(ExceptionOccurred(e)) diff --git a/src/main/scala/io/moia/scalaHttpClient/HttpClientConfig.scala b/src/main/scala/io/moia/scalaHttpClient/HttpClientConfig.scala index d927a5d..b3154ca 100644 --- a/src/main/scala/io/moia/scalaHttpClient/HttpClientConfig.scala +++ b/src/main/scala/io/moia/scalaHttpClient/HttpClientConfig.scala @@ -39,7 +39,7 @@ final case class HttpClientConfig( * @param retriesServerError * Number of retries for all other 5xx codes * @param retriesException - * Number of retries for exceptions in the underlying akka-http client + * Number of retries for exceptions in the underlying pekko-http client * @param initialBackoff * Time to wait until the first retry. Is multiplied with 2^(# of retry). Example: 10ms * 2^0 => 10ms 10ms * 2^1 => 20ms 10ms * 2^2 => 40ms 10ms * 2^3 => * 80ms 10ms * 2^4 => 160ms diff --git a/src/main/scala/io/moia/scalaHttpClient/HttpMetrics.scala b/src/main/scala/io/moia/scalaHttpClient/HttpMetrics.scala index 89feb03..2e2460a 100644 --- a/src/main/scala/io/moia/scalaHttpClient/HttpMetrics.scala +++ b/src/main/scala/io/moia/scalaHttpClient/HttpMetrics.scala @@ -1,6 +1,6 @@ package io.moia.scalaHttpClient -import akka.http.scaladsl.model.{HttpMethod, HttpResponse, Uri} +import org.apache.pekko.http.scaladsl.model.{HttpMethod, HttpResponse, Uri} trait HttpMetrics[LoggingContext] { def meterResponse(method: HttpMethod, path: Uri.Path, response: HttpResponse)(implicit ctx: LoggingContext): Unit diff --git a/src/test/scala/io/moia/scalaHttpClient/AwsRequestSignerTest.scala b/src/test/scala/io/moia/scalaHttpClient/AwsRequestSignerTest.scala index db701a6..0a12215 100644 --- a/src/test/scala/io/moia/scalaHttpClient/AwsRequestSignerTest.scala +++ b/src/test/scala/io/moia/scalaHttpClient/AwsRequestSignerTest.scala @@ -1,8 +1,8 @@ package io.moia.scalaHttpClient -import akka.actor.ActorSystem -import akka.http.scaladsl.model.headers.RawHeader -import akka.http.scaladsl.model.{HttpRequest, Uri} +import org.apache.pekko.actor.ActorSystem +import org.apache.pekko.http.scaladsl.model.headers.RawHeader +import org.apache.pekko.http.scaladsl.model.{HttpRequest, Uri} import io.moia.scalaHttpClient.AwsRequestSigner.AwsRequestSignerConfig import org.scalatest.matchers.should.Matchers import org.scalatest.wordspec.AnyWordSpecLike diff --git a/src/test/scala/io/moia/scalaHttpClient/HttpClientTest.scala b/src/test/scala/io/moia/scalaHttpClient/HttpClientTest.scala index 83105cf..0687f01 100644 --- a/src/test/scala/io/moia/scalaHttpClient/HttpClientTest.scala +++ b/src/test/scala/io/moia/scalaHttpClient/HttpClientTest.scala @@ -1,8 +1,8 @@ package io.moia.scalaHttpClient -import akka.http.scaladsl.model._ -import akka.http.scaladsl.model.headers.{ModeledCustomHeader, ModeledCustomHeaderCompanion} -import akka.http.scaladsl.unmarshalling.Unmarshal +import org.apache.pekko.http.scaladsl.model._ +import org.apache.pekko.http.scaladsl.model.headers.{ModeledCustomHeader, ModeledCustomHeaderCompanion} +import org.apache.pekko.http.scaladsl.unmarshalling.Unmarshal import com.typesafe.scalalogging.StrictLogging import io.moia.scalaHttpClient.AwsRequestSigner.AwsRequestSignerConfig import org.scalatest.{Inside, Inspectors} diff --git a/src/test/scala/io/moia/scalaHttpClient/LoggingHttpClientTest.scala b/src/test/scala/io/moia/scalaHttpClient/LoggingHttpClientTest.scala index 859360d..d39910a 100644 --- a/src/test/scala/io/moia/scalaHttpClient/LoggingHttpClientTest.scala +++ b/src/test/scala/io/moia/scalaHttpClient/LoggingHttpClientTest.scala @@ -1,6 +1,6 @@ package io.moia.scalaHttpClient -import akka.http.scaladsl.model._ +import org.apache.pekko.http.scaladsl.model._ import com.typesafe.scalalogging.{CanLog, Logger, LoggerTakingImplicit} import org.slf4j.{LoggerFactory, MDC} diff --git a/src/test/scala/io/moia/scalaHttpClient/StatusCodesTest.scala b/src/test/scala/io/moia/scalaHttpClient/StatusCodesTest.scala index 0ea57f3..2966e36 100644 --- a/src/test/scala/io/moia/scalaHttpClient/StatusCodesTest.scala +++ b/src/test/scala/io/moia/scalaHttpClient/StatusCodesTest.scala @@ -1,6 +1,6 @@ package io.moia.scalaHttpClient -import akka.http.scaladsl.model._ +import org.apache.pekko.http.scaladsl.model._ import org.mockserver.matchers.Times import org.mockserver.model.HttpRequest.request import org.mockserver.model.HttpResponse.response diff --git a/src/test/scala/io/moia/scalaHttpClient/TestSetup.scala b/src/test/scala/io/moia/scalaHttpClient/TestSetup.scala index d9766a9..a1b7ccb 100644 --- a/src/test/scala/io/moia/scalaHttpClient/TestSetup.scala +++ b/src/test/scala/io/moia/scalaHttpClient/TestSetup.scala @@ -1,9 +1,9 @@ package io.moia.scalaHttpClient import java.time.Clock -import akka.actor.typed.ActorSystem -import akka.actor.typed.scaladsl.Behaviors -import akka.http.scaladsl.model.{HttpMethod, HttpResponse, Uri} +import org.apache.pekko.actor.typed.ActorSystem +import org.apache.pekko.actor.typed.scaladsl.Behaviors +import org.apache.pekko.http.scaladsl.model.{HttpMethod, HttpResponse, Uri} import org.scalatest.matchers.should.Matchers import org.scalatest.wordspec.AnyWordSpecLike