From 18aa9afcb054eca3a16d2bfeb1834531d7f2c869 Mon Sep 17 00:00:00 2001 From: Bekir Oguz Date: Tue, 3 Sep 2024 13:52:09 +0200 Subject: [PATCH] Update circe, logback, objenesis, bcpkix, bcprov, http4s, typesafeConfig versions (#1732) * Update bcpkix-jdk15on, bcprov-jdk15on to 1.78.1 * Update objenesis to 3.4 * Update circe-core, circe-generic, ... to 0.14.9 * Update logback-classic to 1.5.7 * chore: add sbt-scalafix plugin * chore: update circe-generic-extras to version 0.14.4 * chore: update http4sVersion to 0.22.15 * chore: applied design changes of http4s 0.22.x * chore: http4s 0.22.x migration complete * chore: update typeSafeConfig to version 1.4.3 * chore: ignore kotlin compiler version updates --------- Co-authored-by: Scala Steward --- .scala-steward.conf | 5 +- .../ing/bakery/smoke/BakeryEnvironment.scala | 2 +- .../smoke/StateNodeManagementClient.scala | 2 +- .../com/ing/bakery/testing/HoldCleanup.scala | 2 +- .../interaction/RemoteInteractionClient.scala | 22 ++++--- .../ing/bakery/metrics/MetricService.scala | 7 +- .../bakery/interaction/HealthService.scala | 4 +- .../RemoteInteractionService.scala | 8 +-- .../interaction/HealthServiceSpec.scala | 2 +- .../interaction/RemoteInteractionSpec.scala | 2 +- .../components/InteractionRegistry.scala | 2 +- .../bakery/components/MetricServiceSpec.scala | 2 +- .../main/scala/webshop/webservice/Main.scala | 2 +- .../main/scala/webshop/webservice/Main.scala | 2 +- .../StateNodeManagementClient.scala | 2 +- .../http/client/javadsl/BakerClient.scala | 7 +- .../http/client/scaladsl/BakerClient.scala | 65 ++++++++++--------- .../baker/http/client/BakerClientSpec.scala | 10 +-- .../client/common/FailoverStateSpec.scala | 12 ++-- .../client/common/FailoverUtilsSpec.scala | 14 ++-- .../server/scaladsl/Http4sBakerServer.scala | 24 +++---- .../scaladsl/Http4sBakerServerSpec.scala | 11 ++-- project/Dependencies.scala | 18 ++--- project/plugins.sbt | 2 + 24 files changed, 122 insertions(+), 107 deletions(-) diff --git a/.scala-steward.conf b/.scala-steward.conf index 8c1d5b4fe..88f61e2a2 100644 --- a/.scala-steward.conf +++ b/.scala-steward.conf @@ -13,8 +13,9 @@ updates.pin = [ { groupId = "com.github.cb372", artifactId = "cats-retry", version = "2."} ] -# ignore updates for cats-effect 3.x compatible versions +# ignore kotlin compiler version updates and http4s updates for cats-effect 3.x compatible versions updates.ignore = [ { groupId = "org.http4s", version = "0.23." }, - { groupId = "org.http4s", version = "1." } + { groupId = "org.http4s", version = "1." }, + { groupId = "org.jetbrains.kotlin" } ] \ No newline at end of file diff --git a/bakery/integration-tests/src/test/scala/com/ing/bakery/smoke/BakeryEnvironment.scala b/bakery/integration-tests/src/test/scala/com/ing/bakery/smoke/BakeryEnvironment.scala index b56e3a0bf..43adca9e5 100644 --- a/bakery/integration-tests/src/test/scala/com/ing/bakery/smoke/BakeryEnvironment.scala +++ b/bakery/integration-tests/src/test/scala/com/ing/bakery/smoke/BakeryEnvironment.scala @@ -3,7 +3,7 @@ package com.ing.bakery.smoke import cats.effect.{ContextShift, IO, Resource, Timer} import com.ing.bakery.smoke.k8s.{DefinitionFile, Namespace, Pod} import org.http4s.Uri -import org.http4s.client.blaze.BlazeClientBuilder +import org.http4s.blaze.client.BlazeClientBuilder import scala.concurrent.ExecutionContext diff --git a/bakery/integration-tests/src/test/scala/com/ing/bakery/smoke/StateNodeManagementClient.scala b/bakery/integration-tests/src/test/scala/com/ing/bakery/smoke/StateNodeManagementClient.scala index f3e85f8ce..70782b631 100644 --- a/bakery/integration-tests/src/test/scala/com/ing/bakery/smoke/StateNodeManagementClient.scala +++ b/bakery/integration-tests/src/test/scala/com/ing/bakery/smoke/StateNodeManagementClient.scala @@ -4,7 +4,7 @@ import cats.effect.{ContextShift, IO, Resource, Timer} import org.http4s.Method._ import org.http4s.Uri import org.http4s.client.Client -import org.http4s.client.blaze.BlazeClientBuilder +import org.http4s.blaze.client.BlazeClientBuilder import org.http4s.client.dsl.io._ import scala.concurrent.ExecutionContext diff --git a/bakery/integration-tests/src/test/scala/com/ing/bakery/testing/HoldCleanup.scala b/bakery/integration-tests/src/test/scala/com/ing/bakery/testing/HoldCleanup.scala index c46d4b129..6486fcf4a 100644 --- a/bakery/integration-tests/src/test/scala/com/ing/bakery/testing/HoldCleanup.scala +++ b/bakery/integration-tests/src/test/scala/com/ing/bakery/testing/HoldCleanup.scala @@ -9,7 +9,7 @@ import org.http4s._ import org.http4s.dsl.io._ import org.http4s.implicits._ import org.http4s.server.Router -import org.http4s.server.blaze.BlazeServerBuilder +import org.http4s.blaze.server.BlazeServerBuilder import scala.concurrent.ExecutionContext import scala.concurrent.duration._ diff --git a/bakery/interaction-protocol/src/main/scala/com/ing/bakery/interaction/RemoteInteractionClient.scala b/bakery/interaction-protocol/src/main/scala/com/ing/bakery/interaction/RemoteInteractionClient.scala index cd4d42c4d..6b9e1fc94 100644 --- a/bakery/interaction-protocol/src/main/scala/com/ing/bakery/interaction/RemoteInteractionClient.scala +++ b/bakery/interaction-protocol/src/main/scala/com/ing/bakery/interaction/RemoteInteractionClient.scala @@ -9,7 +9,7 @@ import com.ing.bakery.metrics.MetricService import io.prometheus.client.Counter import org.http4s.circe._ import org.http4s.client.Client -import org.http4s.client.blaze.BlazeClientBuilder +import org.http4s.blaze.client.BlazeClientBuilder import org.http4s.dsl.io._ import org.http4s._ @@ -23,11 +23,14 @@ object RemoteInteractionClient { def resource(headers: Headers, pool: ExecutionContext, metricService: MetricService, - tlsConfig: Option[BakeryHttp.TLSConfig])(implicit cs: ContextShift[IO], timer: Timer[IO]): Resource[IO, RemoteInteractionClient] = - BlazeClientBuilder[IO](pool, tlsConfig.map(BakeryHttp.loadSSLContext)) - .withCheckEndpointAuthentication(false) - .resource - .map(new BaseRemoteInteractionClient(_, headers, metricService)) + tlsConfig: Option[BakeryHttp.TLSConfig])(implicit cs: ContextShift[IO], timer: Timer[IO]): Resource[IO, RemoteInteractionClient] = { + + tlsConfig.map(BakeryHttp.loadSSLContext) + .fold(BlazeClientBuilder[IO](pool))(BlazeClientBuilder[IO](pool).withSslContext) + .withCheckEndpointAuthentication(false) + .resource + .map(new BaseRemoteInteractionClient(_, headers, metricService)) + } } trait RemoteInteractionClient { @@ -49,12 +52,15 @@ class BaseRemoteInteractionClient( import RemoteInteractionClient._ import com.ing.baker.runtime.serialization.InteractionExecutionJsonCodecs._ import com.ing.baker.runtime.serialization.JsonCodec._ - def entityCodecs: (EntityEncoder[IO, ExecutionRequest], EntityDecoder[IO, ExecutionResult], EntityDecoder[IO, Interactions]) = + override def entityCodecs: (EntityEncoder[IO, ExecutionRequest], EntityDecoder[IO, ExecutionResult], EntityDecoder[IO, Interactions]) = (jsonEncoderOf[IO, ExecutionRequest], jsonOf[IO, ExecutionResult], jsonOf[IO, Interactions]) - private implicit lazy val (interactionEntityDecoder, executeRequestEntityEncoder, executeResponseEntityDecoder) = entityCodecs + private implicit lazy val ( + interactionEntityDecoder: EntityEncoder[IO, ExecutionRequest], + executeRequestEntityEncoder: EntityDecoder[IO, ExecutionResult], + executeResponseEntityDecoder: EntityDecoder[IO, Interactions]) = entityCodecs def interfaces(uri: Uri): IO[Interactions] = client.expect[Interactions]( diff --git a/bakery/interaction-protocol/src/main/scala/com/ing/bakery/metrics/MetricService.scala b/bakery/interaction-protocol/src/main/scala/com/ing/bakery/metrics/MetricService.scala index aceb863cb..2ab3b2a98 100644 --- a/bakery/interaction-protocol/src/main/scala/com/ing/bakery/metrics/MetricService.scala +++ b/bakery/interaction-protocol/src/main/scala/com/ing/bakery/metrics/MetricService.scala @@ -8,9 +8,10 @@ import io.prometheus.client.{Collector, CollectorRegistry, Counter} import io.prometheus.jmx.JmxCollector import org.http4s.dsl.io._ import org.http4s.implicits.http4sKleisliResponseSyntaxOptionT -import org.http4s.server.blaze.BlazeServerBuilder +import org.http4s.blaze.server.BlazeServerBuilder import org.http4s.server.{Router, Server} import org.http4s._ +import org.typelevel.ci._ import java.io.CharArrayWriter import java.net.InetSocketAddress @@ -46,7 +47,7 @@ object MetricService extends LazyLogging { def defaultInstance = new MetricService(new CollectorRegistry(true)) def resourceServer(socketAddress: InetSocketAddress, registry: CollectorRegistry, ec: ExecutionContext) - (implicit cs: ContextShift[IO], timer: Timer[IO]): Resource[IO, Server[IO]] = { + (implicit cs: ContextShift[IO], timer: Timer[IO]): Resource[IO, Server] = { val encoder = EntityEncoder.stringEncoder def fromPrometheus: String = { @@ -68,7 +69,7 @@ object MetricService extends LazyLogging { Response( status = Ok, body = encoder.toEntity(exportMetrics).body, - headers = Headers.of(Header("Content-Type", TextFormat.CONTENT_TYPE_004)) + headers = Headers(Header.Raw(ci"Content-Type", TextFormat.CONTENT_TYPE_004)) ) } } diff --git a/bakery/interaction/src/main/scala/com/ing/bakery/interaction/HealthService.scala b/bakery/interaction/src/main/scala/com/ing/bakery/interaction/HealthService.scala index 412204049..1419abd2b 100644 --- a/bakery/interaction/src/main/scala/com/ing/bakery/interaction/HealthService.scala +++ b/bakery/interaction/src/main/scala/com/ing/bakery/interaction/HealthService.scala @@ -5,7 +5,7 @@ import java.net.InetSocketAddress import cats.effect.{ContextShift, IO, Resource, Timer} import org.http4s.dsl.io.{->, /, GET, Ok, Root, _} import org.http4s.implicits._ -import org.http4s.server.blaze._ +import org.http4s.blaze.server._ import org.http4s.server.{Router, Server} import org.http4s.{HttpApp, HttpRoutes} @@ -13,7 +13,7 @@ import scala.concurrent.ExecutionContext object HealthService { - def resource(address: InetSocketAddress)(implicit cs: ContextShift[IO], clock: Timer[IO]): Resource[IO, Server[IO]] = + def resource(address: InetSocketAddress)(implicit cs: ContextShift[IO], clock: Timer[IO]): Resource[IO, Server] = BlazeServerBuilder[IO](ExecutionContext.global) .bindSocketAddress(address) .withHttpApp(new HealthService().build) diff --git a/bakery/interaction/src/main/scala/com/ing/bakery/interaction/RemoteInteractionService.scala b/bakery/interaction/src/main/scala/com/ing/bakery/interaction/RemoteInteractionService.scala index 126ba6419..f0280abfc 100644 --- a/bakery/interaction/src/main/scala/com/ing/bakery/interaction/RemoteInteractionService.scala +++ b/bakery/interaction/src/main/scala/com/ing/bakery/interaction/RemoteInteractionService.scala @@ -14,7 +14,7 @@ import org.http4s.circe._ import org.http4s.dsl.io._ import org.http4s.implicits._ import org.http4s.metrics.prometheus.Prometheus -import org.http4s.server.blaze._ +import org.http4s.blaze.server._ import org.http4s.server.middleware.{Logger, Metrics} import org.http4s.server.{Router, Server} @@ -36,7 +36,7 @@ object RemoteInteractionService { metricsPort: Int = 9096, metricsEnabled: Boolean = false, apiUrlPrefix: String = "/api/bakery/interactions", - registry: Option[CollectorRegistry] = None)(implicit timer: Timer[IO], cs: ContextShift[IO], executionContext: ExecutionContext): Resource[IO, Server[IO]] = { + registry: Option[CollectorRegistry] = None)(implicit timer: Timer[IO], cs: ContextShift[IO], executionContext: ExecutionContext): Resource[IO, Server] = { val idToNameMap = interactions.map(i => URLEncoder.encode(i.shaBase64, "UTF-8").take(8) -> i.name).toMap @@ -49,8 +49,8 @@ object RemoteInteractionService { val service = new RemoteInteractionService(interactions) def interactionRequestClassifier(request: Request[IO]): Option[String] = if (interactionPerTypeMetricsEnabled) { - val p = request.pathInfo.split('/') // ... /interactions//execute - we take ID part we care most about - (if (p.length == 4) Some(p(2)) else None).map(v => idToNameMap.getOrElse(v.take(8), "unknown")) + val segments = request.pathInfo.segments // ... /interactions//execute - we take ID part we care most about + (if (segments.length == 4) Some(segments(2)) else None).map(v => idToNameMap.getOrElse(v.toString.take(8), "unknown")) } else None val collectorRegistry = registry.getOrElse(CollectorRegistry.defaultRegistry) diff --git a/bakery/interaction/src/test/scala/com/ing/bakery/interaction/HealthServiceSpec.scala b/bakery/interaction/src/test/scala/com/ing/bakery/interaction/HealthServiceSpec.scala index f3f802471..5d5204f3b 100644 --- a/bakery/interaction/src/test/scala/com/ing/bakery/interaction/HealthServiceSpec.scala +++ b/bakery/interaction/src/test/scala/com/ing/bakery/interaction/HealthServiceSpec.scala @@ -7,7 +7,7 @@ import com.ing.bakery.testing.BakeryFunSpec import org.http4s.Method._ import org.http4s.Uri import org.http4s.client.Client -import org.http4s.client.blaze.BlazeClientBuilder +import org.http4s.blaze.client.BlazeClientBuilder import org.http4s.client.dsl.io._ import org.scalatest.ConfigMap import org.scalatest.matchers.should.Matchers diff --git a/bakery/interaction/src/test/scala/com/ing/bakery/interaction/RemoteInteractionSpec.scala b/bakery/interaction/src/test/scala/com/ing/bakery/interaction/RemoteInteractionSpec.scala index 4d27da565..9a5849864 100644 --- a/bakery/interaction/src/test/scala/com/ing/bakery/interaction/RemoteInteractionSpec.scala +++ b/bakery/interaction/src/test/scala/com/ing/bakery/interaction/RemoteInteractionSpec.scala @@ -141,7 +141,7 @@ class RemoteInteractionSpec extends BakeryFunSpec { val result: IO[Option[String]] = client.execute(uri, implementation0.shaBase64, Seq(ingredient0, ingredient1), Map.empty) .map(_ => None) .handleErrorWith { - case _: java.net.ConnectException | Command.EOF => IO.pure(Some("connection error")) + case _: java.net.SocketException | Command.EOF => IO.pure(Some("connection error")) case e => IO.raiseError(e) } result.map(result => assert(result === Some("connection error"))) diff --git a/bakery/state/src/main/scala/com/ing/bakery/components/InteractionRegistry.scala b/bakery/state/src/main/scala/com/ing/bakery/components/InteractionRegistry.scala index e8faa98a4..46d2549bd 100644 --- a/bakery/state/src/main/scala/com/ing/bakery/components/InteractionRegistry.scala +++ b/bakery/state/src/main/scala/com/ing/bakery/components/InteractionRegistry.scala @@ -14,7 +14,7 @@ import com.ing.bakery.metrics.MetricService import com.typesafe.config.Config import com.typesafe.scalalogging.LazyLogging import org.http4s.client.Client -import org.http4s.client.blaze.BlazeClientBuilder +import org.http4s.blaze.client.BlazeClientBuilder import org.http4s.{Headers, Uri} import scalax.collection.ChainingOps diff --git a/bakery/state/src/test/scala/com/ing/bakery/components/MetricServiceSpec.scala b/bakery/state/src/test/scala/com/ing/bakery/components/MetricServiceSpec.scala index 4debe160d..010899463 100644 --- a/bakery/state/src/test/scala/com/ing/bakery/components/MetricServiceSpec.scala +++ b/bakery/state/src/test/scala/com/ing/bakery/components/MetricServiceSpec.scala @@ -5,7 +5,7 @@ import com.ing.bakery.metrics.MetricService import com.typesafe.config.ConfigFactory import io.prometheus.client.CollectorRegistry import org.http4s.Status.Ok -import org.http4s.client.blaze.BlazeClientBuilder +import org.http4s.blaze.client.BlazeClientBuilder import org.scalatest.funsuite.AnyFunSuite import org.scalatest.matchers.should.Matchers diff --git a/examples/baker-example/src/main/scala/webshop/webservice/Main.scala b/examples/baker-example/src/main/scala/webshop/webservice/Main.scala index d1d0bb0a7..fb1e7b6cf 100644 --- a/examples/baker-example/src/main/scala/webshop/webservice/Main.scala +++ b/examples/baker-example/src/main/scala/webshop/webservice/Main.scala @@ -8,7 +8,7 @@ import com.ing.baker.runtime.akka.AkkaBaker import com.ing.baker.runtime.akka.internal.CachingInteractionManager import com.ing.baker.runtime.scaladsl._ import com.typesafe.config.ConfigFactory -import org.http4s.server.blaze.BlazeServerBuilder +import org.http4s.blaze.server.BlazeServerBuilder import org.log4s.Logger import webshop.webservice.recipe.{MakePaymentInstance, ReserveItemsInstance, ShipItemsInstance} diff --git a/examples/bakery-client-example/src/main/scala/webshop/webservice/Main.scala b/examples/bakery-client-example/src/main/scala/webshop/webservice/Main.scala index 4e3829b4f..97b644dd8 100644 --- a/examples/bakery-client-example/src/main/scala/webshop/webservice/Main.scala +++ b/examples/bakery-client-example/src/main/scala/webshop/webservice/Main.scala @@ -8,7 +8,7 @@ import com.ing.baker.compiler.RecipeCompiler import com.ing.baker.http.client.scaladsl.BakerClient import com.typesafe.config.ConfigFactory import org.http4s.Uri -import org.http4s.server.blaze.BlazeServerBuilder +import org.http4s.blaze.server.BlazeServerBuilder import scala.concurrent.{ExecutionContext, ExecutionContextExecutor} diff --git a/examples/bakery-client-example/src/main/scala/webshop/webservice/StateNodeManagementClient.scala b/examples/bakery-client-example/src/main/scala/webshop/webservice/StateNodeManagementClient.scala index 2af06d7d9..29704e606 100644 --- a/examples/bakery-client-example/src/main/scala/webshop/webservice/StateNodeManagementClient.scala +++ b/examples/bakery-client-example/src/main/scala/webshop/webservice/StateNodeManagementClient.scala @@ -4,7 +4,7 @@ import cats.effect.{ContextShift, IO, Resource, Timer} import org.http4s.Method._ import org.http4s.Uri import org.http4s.client.Client -import org.http4s.client.blaze.BlazeClientBuilder +import org.http4s.blaze.client.BlazeClientBuilder import org.http4s.client.dsl.io._ import scala.concurrent.ExecutionContext diff --git a/http/baker-http-client/src/main/scala/com/ing/baker/http/client/javadsl/BakerClient.scala b/http/baker-http-client/src/main/scala/com/ing/baker/http/client/javadsl/BakerClient.scala index 319ba7dd9..a948c32ca 100644 --- a/http/baker-http-client/src/main/scala/com/ing/baker/http/client/javadsl/BakerClient.scala +++ b/http/baker-http-client/src/main/scala/com/ing/baker/http/client/javadsl/BakerClient.scala @@ -4,7 +4,7 @@ import cats.effect.{ContextShift, IO, Timer} import com.ing.baker.http.client.common.TLSConfig import com.ing.baker.http.client.scaladsl.{BakerClient => ScalaClient, EndpointConfig} import com.ing.baker.runtime.javadsl.{Baker => JavaBaker} -import org.http4s.client.blaze.BlazeClientBuilder +import org.http4s.blaze.client.BlazeClientBuilder import org.http4s.{Request, Uri} import java.util.concurrent.CompletableFuture @@ -45,9 +45,8 @@ object BakerClient { implicit val contextShift: ContextShift[IO] = IO.contextShift(ec) implicit val timer: Timer[IO] = IO.timer(ec) - val future = BlazeClientBuilder[IO]( - executionContext = connectionPool, - sslContext = sslContext) + val future = sslContext + .fold(BlazeClientBuilder[IO](connectionPool))(BlazeClientBuilder[IO](connectionPool).withSslContext) .resource .map { client => new ScalaClient( diff --git a/http/baker-http-client/src/main/scala/com/ing/baker/http/client/scaladsl/BakerClient.scala b/http/baker-http-client/src/main/scala/com/ing/baker/http/client/scaladsl/BakerClient.scala index 7ec74fa06..ccf0cf37b 100644 --- a/http/baker-http-client/src/main/scala/com/ing/baker/http/client/scaladsl/BakerClient.scala +++ b/http/baker-http-client/src/main/scala/com/ing/baker/http/client/scaladsl/BakerClient.scala @@ -17,7 +17,7 @@ import org.http4s.Method._ import org.http4s._ import org.http4s.circe._ import org.http4s.client.Client -import org.http4s.client.blaze._ +import org.http4s.blaze.client._ import org.http4s.client.dsl.io._ import scala.collection.immutable.Seq @@ -33,11 +33,12 @@ object BakerClient { (implicit cs: ContextShift[IO], timer: Timer[IO]): Resource[IO, BakerClient] = { implicit val ex: ExecutionContext = executionContext - BlazeClientBuilder[IO](executionContext, tlsConfig.map(_.loadSSLContext)) - .resource - .map(client => { - new BakerClient(client, endpointConfig, fallbackEndpointConfig, filters) - }) + tlsConfig.map(_.loadSSLContext) + .fold(BlazeClientBuilder[IO](ex))(BlazeClientBuilder[IO](ex).withSslContext) + .resource + .map(client => { + new BakerClient(client, endpointConfig, fallbackEndpointConfig, filters) + }) } def resourceBalanced(endpointConfig: EndpointConfig, @@ -101,11 +102,11 @@ final class BakerClient( client: Client[IO], implicit val interactionRequestEncoder: EntityEncoder[IO, InteractionExecution.ExecutionRequest] = jsonEncoderOf[IO, InteractionExecution.ExecutionRequest] override def addRecipe(recipe: RecipeRecord): Future[String] = - callRemoteBakerService[String]((host, prefix) => POST( + callRemoteBakerService[String]((host, prefix) => IO(POST( EncodedRecipe( base64 = new String(java.util.Base64.getEncoder.encode(Utils.recipeToByteArray(recipe.recipe)), "UTF-8"), createdAt = recipe.updated), - root(host, prefix) / "app" / "recipes")).map { r => + root(host, prefix) / "app" / "recipes"))).map { r => logger.info(s"Result of adding a recipe: $r") r } @@ -163,10 +164,10 @@ final class BakerClient( client: Client[IO], * @return */ override def getRecipe(recipeId: String): Future[RecipeInformation] = - callRemoteBakerService[RecipeInformation]((host, prefix) => GET(root(host, prefix) / "app" / "recipes" / recipeId)) + callRemoteBakerService[RecipeInformation]((host, prefix) => IO(GET(root(host, prefix) / "app" / "recipes" / recipeId))) override def getRecipeVisual(recipeId: String, style: RecipeVisualStyle): Future[String] = - callRemoteBakerService[String]((host, prefix) => GET(root(host, prefix) / "app" / "recipes" / recipeId / "visual")) + callRemoteBakerService[String]((host, prefix) => IO(GET(root(host, prefix) / "app" / "recipes" / recipeId / "visual"))) /** * Returns all recipes added to this baker instance. @@ -174,7 +175,7 @@ final class BakerClient( client: Client[IO], * @return All recipes in the form of map of recipeId -> CompiledRecipe */ override def getAllRecipes: Future[Map[String, RecipeInformation]] = - callRemoteBakerService[Map[String, RecipeInformation]]( (host, prefix) => GET(root(host, prefix) / "app" / "recipes")) + callRemoteBakerService[Map[String, RecipeInformation]]( (host, prefix) => IO(GET(root(host, prefix) / "app" / "recipes"))) /** * Creates a process instance for the given recipeId with the given RecipeInstanceId as identifier @@ -184,26 +185,26 @@ final class BakerClient( client: Client[IO], * @return */ override def bake(recipeId: String, recipeInstanceId: String): Future[Unit] = - callRemoteBakerService[Unit]((host, prefix) => POST(root(host, prefix) / "instances" / recipeInstanceId / "bake" / recipeId)).map { _ => + callRemoteBakerService[Unit]((host, prefix) => IO(POST(root(host, prefix) / "instances" / recipeInstanceId / "bake" / recipeId))).map { _ => logger.info(s"Baked recipe instance '$recipeInstanceId' from recipe '$recipeId'") } override def bake(recipeId: String, recipeInstanceId: String, metadata: Map[String, String]): Future[Unit] = callRemoteBakerService[Unit]((host, prefix) => - POST(BakeRequest(Some(metadata)), root(host, prefix) / "instances" / recipeInstanceId / "bake" / recipeId)).map { _ => + IO(POST(BakeRequest(Some(metadata)), root(host, prefix) / "instances" / recipeInstanceId / "bake" / recipeId))).map { _ => logger.info(s"Baked recipe instance '$recipeInstanceId' from recipe '$recipeId'") } override def getInteraction(interactionName: String): Future[Option[InteractionInstanceDescriptor]] = - callRemoteBakerService[Option[InteractionInstanceDescriptor]]((host, prefix) => GET(root(host, prefix) / "app" / "interactions" / interactionName)) + callRemoteBakerService[Option[InteractionInstanceDescriptor]]((host, prefix) => IO(GET(root(host, prefix) / "app" / "interactions" / interactionName))) override def getAllInteractions: Future[List[InteractionInstanceDescriptor]] = - callRemoteBakerService[List[InteractionInstanceDescriptor]]((host, prefix) => GET(root(host, prefix) / "app" / "interactions")) + callRemoteBakerService[List[InteractionInstanceDescriptor]]((host, prefix) => IO(GET(root(host, prefix) / "app" / "interactions"))) override def executeSingleInteraction(interactionId: String, ingredients: Seq[IngredientInstance]): Future[InteractionExecutionResult] = callRemoteBakerService[InteractionExecution.ExecutionResult]((host, prefix) => - POST(InteractionExecution.ExecutionRequest(interactionId, ingredients.toList, Option.empty), root(host, prefix) / "app" / "interactions" / "execute")).map{ result => + IO(POST(InteractionExecution.ExecutionRequest(interactionId, ingredients.toList, Option.empty), root(host, prefix) / "app" / "interactions" / "execute"))).map{ result => result.outcome match { case Left(failure) => InteractionExecutionResult(Left(failure.toBakerInteractionExecutionFailure)) case Right(success) => InteractionExecutionResult(Right(success.toBakerInteractionExecutionSuccess)) @@ -225,8 +226,8 @@ final class BakerClient( client: Client[IO], event: EventInstance, correlationId: Option[String]): Future[SensoryEventResult] = callRemoteBakerServiceFallbackAware[SensoryEventResult]( - (host, prefix) => POST(event, (root(host, prefix) / "instances" / recipeInstanceId / "fire-and-resolve-when-completed") - .withOptionQueryParam("correlationId", correlationId)), fallbackEndpoint).map { result => + (host, prefix) => IO(POST(event, (root(host, prefix) / "instances" / recipeInstanceId / "fire-and-resolve-when-completed") + .withOptionQueryParam("correlationId", correlationId))), fallbackEndpoint).map { result => logger.info(s"For recipe instance '$recipeInstanceId', fired and completed event '${event.name}', resulting status ${result.sensoryEventStatus}") result } @@ -246,8 +247,8 @@ final class BakerClient( client: Client[IO], event: EventInstance, correlationId: Option[String]): Future[SensoryEventStatus] = callRemoteBakerServiceFallbackAware[SensoryEventStatus]( - (host, prefix) => POST(event, (root(host, prefix) / "instances" / recipeInstanceId / "fire-and-resolve-when-received") - .withOptionQueryParam("correlationId", correlationId)), fallbackEndpoint).map { result => + (host, prefix) => IO(POST(event, (root(host, prefix) / "instances" / recipeInstanceId / "fire-and-resolve-when-received") + .withOptionQueryParam("correlationId", correlationId))), fallbackEndpoint).map { result => logger.info(s"For recipe instance '$recipeInstanceId', fired and received event '${event.name}', resulting status $result") result } @@ -269,8 +270,8 @@ final class BakerClient( client: Client[IO], onEvent: String, correlationId: Option[String]): Future[SensoryEventResult] = callRemoteBakerServiceFallbackAware[SensoryEventResult]( - (host, prefix) => POST(event, (root(host, prefix) / "instances" / recipeInstanceId / "fire-and-resolve-on-event" / onEvent) - .withOptionQueryParam("correlationId", correlationId)), fallbackEndpoint).map { result => + (host, prefix) => IO(POST(event, (root(host, prefix) / "instances" / recipeInstanceId / "fire-and-resolve-on-event" / onEvent) + .withOptionQueryParam("correlationId", correlationId))), fallbackEndpoint).map { result => logger.info(s"For recipe instance '$recipeInstanceId', fired event '${event.name}', and resolved on event '$onEvent', resulting status ${result.sensoryEventStatus}") result } @@ -296,7 +297,7 @@ final class BakerClient( client: Client[IO], */ override def addMetaData(recipeInstanceId: String, metadata: Map[String,String]): Future[Unit] = callRemoteBakerService[Unit]( - (host, prefix) => POST(AddMetaDataRequest(metadata), root(host, prefix) / "instances" / recipeInstanceId / "add-metadata")) + (host, prefix) => IO(POST(AddMetaDataRequest(metadata), root(host, prefix) / "instances" / recipeInstanceId / "add-metadata"))) /** * Returns an index of all running processes. @@ -309,7 +310,7 @@ final class BakerClient( client: Client[IO], * @return An index of all processes */ override def getAllRecipeInstancesMetadata: Future[Set[RecipeInstanceMetadata]] = - callRemoteBakerServiceFallbackAware[Set[RecipeInstanceMetadata]]((host, prefix) => GET(root(host, prefix) / "instances"), fallbackEndpoint) + callRemoteBakerServiceFallbackAware[Set[RecipeInstanceMetadata]]((host, prefix) => IO(GET(root(host, prefix) / "instances")), fallbackEndpoint) /** * Returns the process state. @@ -318,7 +319,7 @@ final class BakerClient( client: Client[IO], * @return The process state. */ override def getRecipeInstanceState(recipeInstanceId: String): Future[RecipeInstanceState] = - callRemoteBakerServiceFallbackAware[RecipeInstanceState]((host, prefix) => GET(root(host, prefix) / "instances" / recipeInstanceId), fallbackEndpoint) + callRemoteBakerServiceFallbackAware[RecipeInstanceState]((host, prefix) => IO(GET(root(host, prefix) / "instances" / recipeInstanceId)), fallbackEndpoint) /** * @param recipeInstanceId @@ -326,7 +327,7 @@ final class BakerClient( client: Client[IO], * @return */ override def getIngredient(recipeInstanceId: String, name: String): Future[Value] = - callRemoteBakerServiceFallbackAware[Value]((host, prefix) => GET(root(host, prefix) / "instances" / recipeInstanceId / "ingredient" / name), fallbackEndpoint) + callRemoteBakerServiceFallbackAware[Value]((host, prefix) => IO(GET(root(host, prefix) / "instances" / recipeInstanceId / "ingredient" / name)), fallbackEndpoint) /** * Returns all provided ingredients for a given RecipeInstance id. @@ -335,7 +336,7 @@ final class BakerClient( client: Client[IO], * @return The provided ingredients. */ override def getIngredients(recipeInstanceId: String): Future[Map[String, Value]] = - callRemoteBakerServiceFallbackAware[Map[String, Value]]((host, prefix) => GET(root(host, prefix) / "instances" / recipeInstanceId / "ingredients"), fallbackEndpoint) + callRemoteBakerServiceFallbackAware[Map[String, Value]]((host, prefix) => IO(GET(root(host, prefix) / "instances" / recipeInstanceId / "ingredients")), fallbackEndpoint) /** * Returns all fired events for a given RecipeInstance id. @@ -344,7 +345,7 @@ final class BakerClient( client: Client[IO], * @return The events */ override def getEvents(recipeInstanceId: String): Future[Seq[EventMoment]] = - callRemoteBakerServiceFallbackAware[List[EventMoment]]((host, prefix) => GET(root(host, prefix) / "instances" / recipeInstanceId / "events"), fallbackEndpoint) + callRemoteBakerServiceFallbackAware[List[EventMoment]]((host, prefix) => IO(GET(root(host, prefix) / "instances" / recipeInstanceId / "events")), fallbackEndpoint) /** * Returns all names of fired events for a given RecipeInstance id. @@ -362,7 +363,7 @@ final class BakerClient( client: Client[IO], * @return A visual (.dot) representation of the process state. */ override def getVisualState(recipeInstanceId: String, style: RecipeVisualStyle): Future[String] = - callRemoteBakerServiceFallbackAware[String]((host, prefix) => GET(root(host, prefix) / "instances" / recipeInstanceId / "visual"), fallbackEndpoint) + callRemoteBakerServiceFallbackAware[String]((host, prefix) => IO(GET(root(host, prefix) / "instances" / recipeInstanceId / "visual")), fallbackEndpoint) /** * Registers a listener to all runtime events for recipes with the given name run in this baker instance. @@ -403,7 +404,7 @@ final class BakerClient( client: Client[IO], * @return */ override def retryInteraction(recipeInstanceId: String, interactionName: String): Future[Unit] = - callRemoteBakerServiceFallbackAware[Unit]((host, apiUrlPrefix) => POST(root(host, apiUrlPrefix) / "instances" / recipeInstanceId / "interaction" / interactionName / "retry"), fallbackEndpoint) + callRemoteBakerServiceFallbackAware[Unit]((host, apiUrlPrefix) => IO(POST(root(host, apiUrlPrefix) / "instances" / recipeInstanceId / "interaction" / interactionName / "retry")), fallbackEndpoint) /** * Resolves a blocked interaction by specifying it's output. @@ -413,7 +414,7 @@ final class BakerClient( client: Client[IO], * @return */ override def resolveInteraction(recipeInstanceId: String, interactionName: String, event: EventInstance): Future[Unit] = - callRemoteBakerServiceFallbackAware[Unit]((host, prefix) => POST(event, root(host, prefix) / "instances" / recipeInstanceId / "interaction" / interactionName / "resolve"), fallbackEndpoint) + callRemoteBakerServiceFallbackAware[Unit]((host, prefix) => IO(POST(event, root(host, prefix) / "instances" / recipeInstanceId / "interaction" / interactionName / "resolve")), fallbackEndpoint) /** * Stops the retrying of an interaction. @@ -421,5 +422,5 @@ final class BakerClient( client: Client[IO], * @return */ override def stopRetryingInteraction(recipeInstanceId: String, interactionName: String): Future[Unit] = - callRemoteBakerServiceFallbackAware[Unit]((host, prefix) => POST(root(host, prefix) / "instances" / recipeInstanceId / "interaction" / interactionName / "stop-retrying"), fallbackEndpoint) + callRemoteBakerServiceFallbackAware[Unit]((host, prefix) => IO(POST(root(host, prefix) / "instances" / recipeInstanceId / "interaction" / interactionName / "stop-retrying")), fallbackEndpoint) } diff --git a/http/baker-http-client/src/test/scala/com/ing/baker/http/client/BakerClientSpec.scala b/http/baker-http-client/src/test/scala/com/ing/baker/http/client/BakerClientSpec.scala index 16253f733..2be1c4421 100644 --- a/http/baker-http-client/src/test/scala/com/ing/baker/http/client/BakerClientSpec.scala +++ b/http/baker-http-client/src/test/scala/com/ing/baker/http/client/BakerClientSpec.scala @@ -12,7 +12,7 @@ import org.http4s.circe._ import org.http4s.dsl.io._ import org.http4s.implicits._ import org.http4s.server.Router -import org.http4s.server.blaze._ +import org.http4s.blaze.server._ import org.scalatest.ConfigMap import java.net.InetSocketAddress @@ -24,7 +24,7 @@ import scala.concurrent.ExecutionContext @nowarn class BakerClientSpec extends BakeryFunSpec { - case class Context(serverAddress: InetSocketAddress, receivedHeaders: IO[List[Header]]) + case class Context(serverAddress: InetSocketAddress, receivedHeaders: IO[List[Header.Raw]]) val serviceTLSConfig: TLSConfig = TLSConfig( @@ -52,12 +52,12 @@ class BakerClientSpec extends BakeryFunSpec { */ def contextBuilder(testArguments: TestArguments): Resource[IO, TestContext] = { - def testServer(receivedHeaders: MVar2[IO, List[Header]]): HttpApp[IO] = { + def testServer(receivedHeaders: MVar2[IO, List[Header.Raw]]): HttpApp[IO] = { implicit val bakerResultEntityEncoder: EntityEncoder[IO, BakerResult] = jsonEncoderOf[IO, BakerResult] Router("/api/bakery/instances" -> HttpRoutes.of[IO] { case request@GET -> Root => for { - _ <- receivedHeaders.put(request.headers.toList) + _ <- receivedHeaders.put(request.headers.headers) response <- Ok(BakerResult(List.empty[Int])) } yield response }).orNotFound @@ -67,7 +67,7 @@ class BakerClientSpec extends BakeryFunSpec { val sslParams = sslConfig.getDefaultSSLParameters sslParams.setNeedClientAuth(true) for { - receivedHeaders <- Resource.eval(MVar.empty[IO, List[Header]]) + receivedHeaders <- Resource.eval(MVar.empty[IO, List[Header.Raw]]) service <- BlazeServerBuilder[IO](ExecutionContext.global) .withSslContextAndParameters(sslConfig, sslParams) .bindSocketAddress(InetSocketAddress.createUnresolved("localhost", 0)) diff --git a/http/baker-http-client/src/test/scala/com/ing/baker/http/client/common/FailoverStateSpec.scala b/http/baker-http-client/src/test/scala/com/ing/baker/http/client/common/FailoverStateSpec.scala index 619fbbd4a..07d2dfe11 100644 --- a/http/baker-http-client/src/test/scala/com/ing/baker/http/client/common/FailoverStateSpec.scala +++ b/http/baker-http-client/src/test/scala/com/ing/baker/http/client/common/FailoverStateSpec.scala @@ -1,7 +1,9 @@ package com.ing.baker.http.client.common +import org.http4s._ +import org.http4s.implicits._ + import com.ing.baker.http.client.scaladsl.EndpointConfig -import org.http4s.Uri import org.scalatest.funspec.AnyFunSpec import scala.concurrent.duration._ @@ -10,10 +12,10 @@ import scala.concurrent.{Await, Future} class FailoverStateSpec extends AnyFunSpec { - private val uriA = Uri(path = "baker-a-host") - private val uriB = Uri(path = "baker-b-host") - private val uriC = Uri(path = "baker-c-host") - private val uriD = Uri(path = "baker-d-host") + private val uriA = uri"baker-a-host" + private val uriB = uri"baker-b-host" + private val uriC = uri"baker-c-host" + private val uriD = uri"baker-d-host" describe("Balancer") { diff --git a/http/baker-http-client/src/test/scala/com/ing/baker/http/client/common/FailoverUtilsSpec.scala b/http/baker-http-client/src/test/scala/com/ing/baker/http/client/common/FailoverUtilsSpec.scala index e68e87014..a1da98f68 100644 --- a/http/baker-http-client/src/test/scala/com/ing/baker/http/client/common/FailoverUtilsSpec.scala +++ b/http/baker-http-client/src/test/scala/com/ing/baker/http/client/common/FailoverUtilsSpec.scala @@ -9,12 +9,12 @@ import org.http4s.Method.GET import org.http4s._ import org.http4s.circe.jsonEncoderOf import org.http4s.client.Client -import org.http4s.client.blaze.BlazeClientBuilder +import org.http4s.blaze.client.BlazeClientBuilder import org.http4s.client.dsl.io._ import org.http4s.dsl.io._ import org.http4s.implicits._ import org.http4s.server.Router -import org.http4s.server.blaze.BlazeServerBuilder +import org.http4s.blaze.server.BlazeServerBuilder import org.scalatest.funspec.FixtureAsyncFunSpec import org.scalatest.{Assertion, FutureOutcome} @@ -117,7 +117,7 @@ class FailoverUtilsSpec extends FixtureAsyncFunSpec { val fos = new FailoverState(EndpointConfig(IndexedSeq(context.server500, context.server200))) for { result <- callWithFailOver(fos, context.client, - (uri, _) => GET(uri / "app" / "recipes"), Seq.empty, + (uri, _) => IO(GET(uri / "app" / "recipes")), Seq.empty, FailoverUtils.handleHttpErrors, None)(executionContext, bakerResultDecoder) } yield { assert(result == BakerResult(List.empty[Int])) @@ -130,7 +130,7 @@ class FailoverUtilsSpec extends FixtureAsyncFunSpec { val fos = new FailoverState(EndpointConfig(IndexedSeq(context.server400, context.server500))) for { _ <- callWithFailOver(fos, context.client, - (uri, _) => GET(uri / "app" / "recipes"), Seq.empty, + (uri, _) => IO(GET(uri / "app" / "recipes")), Seq.empty, FailoverUtils.handleFallbackAwareErrors, Some(EndpointConfig(IndexedSeq(context.server200))))(executionContext, bakerResultDecoder) } yield { assert(callbackCollector.toList == List("400", "200")) @@ -142,7 +142,7 @@ class FailoverUtilsSpec extends FixtureAsyncFunSpec { val fos = new FailoverState(EndpointConfig(IndexedSeq(context.server500, context.server400))) for { result <- callWithFailOver(fos, context.client, - (uri, _) => GET(uri / "app" / "recipes"), Seq.empty, + (uri, _) => IO(GET(uri / "app" / "recipes")), Seq.empty, FailoverUtils.handleFallbackAwareErrors, Some(EndpointConfig(IndexedSeq(context.server200))))(executionContext, bakerResultDecoder) } yield { assert(result == BakerResult(List.empty[Int])) @@ -156,7 +156,7 @@ class FailoverUtilsSpec extends FixtureAsyncFunSpec { for { either <- callWithFailOver(fos, context.client, - (uri, _) => GET(uri / "app" / "recipes"), Seq.empty, + (uri, _) => IO(GET(uri / "app" / "recipes")), Seq.empty, FailoverUtils.handleFallbackAwareErrors, None)(executionContext, bakerResultDecoder).attempt } yield { assert(either.left.get.isInstanceOf[NoSuchProcessException]) @@ -169,7 +169,7 @@ class FailoverUtilsSpec extends FixtureAsyncFunSpec { for { either <- callWithFailOver(fos, context.client, - (uri, _) => GET(uri / "app" / "recipes"), Seq.empty, + (uri, _) => IO(GET(uri / "app" / "recipes")), Seq.empty, FailoverUtils.handleFallbackAwareErrors, Some(EndpointConfig(IndexedSeq(context.server404, context.server404))))(executionContext, bakerResultDecoder).attempt } yield { diff --git a/http/baker-http-server/src/main/scala/com/ing/baker/http/server/scaladsl/Http4sBakerServer.scala b/http/baker-http-server/src/main/scala/com/ing/baker/http/server/scaladsl/Http4sBakerServer.scala index 7f9e3a18d..59df149a5 100644 --- a/http/baker-http-server/src/main/scala/com/ing/baker/http/server/scaladsl/Http4sBakerServer.scala +++ b/http/baker-http-server/src/main/scala/com/ing/baker/http/server/scaladsl/Http4sBakerServer.scala @@ -24,7 +24,7 @@ import org.http4s.headers.{`Content-Length`, `Content-Type`} import org.http4s.implicits._ import org.http4s.metrics.MetricsOps import org.http4s.metrics.prometheus.Prometheus -import org.http4s.server.blaze.BlazeServerBuilder +import org.http4s.blaze.server.BlazeServerBuilder import org.http4s.server.middleware.{CORS, Logger, Metrics} import org.http4s.server.{Router, Server} import org.slf4j.LoggerFactory @@ -36,18 +36,20 @@ import java.util.concurrent.CompletableFuture import scala.compat.java8.FutureConverters import scala.concurrent.duration.DurationInt import scala.concurrent.{ExecutionContext, Future} +import com.ing.baker.il.RecipeVisualizer.logger -object Http4sBakerServer { +object Http4sBakerServer extends LazyLogging { def resource(baker: Baker, ec: ExecutionContext, hostname: InetSocketAddress, apiUrlPrefix: String, dashboardConfiguration: DashboardConfiguration, loggingEnabled: Boolean) - (implicit sync: Sync[IO], cs: ContextShift[IO], timer: Timer[IO]): Resource[IO, Server[IO]] = { + (implicit sync: Sync[IO], cs: ContextShift[IO], timer: Timer[IO]): Resource[IO, Server] = { val apiLoggingAction: Option[String => IO[Unit]] = if (loggingEnabled) { val apiLogger = LoggerFactory.getLogger("API") Some(s => IO(apiLogger.info(s))) } else None + for { metrics <- Prometheus.metricsOps[IO](CollectorRegistry.defaultRegistry, "http_api") blocker <- Blocker[IO] @@ -71,7 +73,7 @@ object Http4sBakerServer { http4sBakerServerConfiguration: Http4sBakerServerConfiguration, dashboardConfiguration: DashboardConfiguration, ec: ExecutionContext = ExecutionContext.global) - (implicit sync: Sync[IO], cs: ContextShift[IO], timer: Timer[IO]): Resource[IO, Server[IO]] = + (implicit sync: Sync[IO], cs: ContextShift[IO], timer: Timer[IO]): Resource[IO, Server] = resource(baker, ec, hostname = InetSocketAddress.createUnresolved(http4sBakerServerConfiguration.apiHost, http4sBakerServerConfiguration.apiPort), apiUrlPrefix = http4sBakerServerConfiguration.apiUrlPrefix, @@ -89,7 +91,7 @@ object Http4sBakerServer { .allocated .unsafeToFuture() .map { - case (server: Server[IO], closeEffect: IO[Unit]) => new ClosableBakerServer(server, closeEffect) + case (server: Server, closeEffect: IO[Unit]) => new ClosableBakerServer(server, closeEffect) }(ExecutionContext.global) FutureConverters.toJava(serverStarted).toCompletableFuture } @@ -99,7 +101,7 @@ object Http4sBakerServer { java(baker, Http4sBakerServerConfiguration.fromConfig(config), DashboardConfiguration.fromConfig(config)) } - class ClosableBakerServer(val server : Server[IO], closeEffect : IO[Unit]) extends Closeable { + class ClosableBakerServer(val server : Server, closeEffect : IO[Unit]) extends Closeable { override def close(): Unit = closeEffect.unsafeRunSync() } def routes(baker: Baker, apiUrlPrefix: String, metrics: MetricsOps[IO], @@ -126,10 +128,8 @@ object Http4sBakerServer { `Content-Length`.unsafeFromLong(bodyText.length) ) )) - //TODO: Change to Dashboard.indexPattern.matches(req.pathInfo) once support for scala_2.12 is removed. - case req if req.method == GET && req.pathInfo.matches(Dashboard.indexPattern.regex) => dashboardFile(req, blocker, "index.html").getOrElseF(NotFound()) - case req if req.method == GET && Dashboard.files.contains(req.pathInfo.substring(1)) => - dashboardFile(req, blocker, req.pathInfo.substring(1)).getOrElseF(NotFound()) + case req if req.method == GET && Dashboard.indexPattern.matches(req.pathInfo.toRelative.renderString) => dashboardFile(req, blocker, "index.html").getOrElseF(NotFound()) + case req if req.method == GET && Dashboard.files.contains(req.pathInfo.toRelative.renderString) => dashboardFile(req, blocker, req.pathInfo.toRelative.renderString).getOrElseF(NotFound()) } private def dashboardFile(request: Request[IO], blocker: Blocker, filename: String) @@ -252,8 +252,8 @@ final class Http4sBakerServer private(baker: Baker)(implicit cs: ContextShift[IO }) def metricsClassifier(apiUrlPrefix: String): Request[IO] => Option[String] = { request => - val uriPath = request.uri.path - val p = uriPath.takeRight(uriPath.length - apiUrlPrefix.length) + val uriPathRendered = request.uri.path.renderString + val p = uriPathRendered.takeRight(uriPathRendered.length - apiUrlPrefix.length) if (p.startsWith("/app")) Some(p) // cardinality is low, we don't care else if (p.startsWith("/instances")) { diff --git a/http/baker-http-server/src/test/scala/com/ing/baker/http/server/scaladsl/Http4sBakerServerSpec.scala b/http/baker-http-server/src/test/scala/com/ing/baker/http/server/scaladsl/Http4sBakerServerSpec.scala index 8a9420ba4..9a57b2821 100644 --- a/http/baker-http-server/src/test/scala/com/ing/baker/http/server/scaladsl/Http4sBakerServerSpec.scala +++ b/http/baker-http-server/src/test/scala/com/ing/baker/http/server/scaladsl/Http4sBakerServerSpec.scala @@ -5,11 +5,14 @@ import cats.effect.{Blocker, IO, Resource} import com.ing.baker.http.DashboardConfiguration import com.ing.baker.runtime.scaladsl.Baker import io.prometheus.client.CollectorRegistry -import org.http4s.headers.{`Content-Length`, `Content-Type`} + +import org.http4s.headers._ import org.http4s.implicits._ import org.http4s.metrics.MetricsOps import org.http4s.metrics.prometheus.Prometheus import org.http4s._ +import org.typelevel.ci._ + import org.mockito.Mockito.{times, verify, when} import org.mockito.MockitoSugar.mock import org.scalatest.flatspec.AsyncFlatSpec @@ -69,13 +72,13 @@ class Http4sBakerServerSpec extends AsyncFlatSpec with AsyncIOSpec with Matcher "the routes" should "serve the dashboard index file if dashboard is enabled" in { val response = doRequest(Request(method = Method.GET, uri = uri"/")) response.status shouldEqual Status.Ok - response.headers.get(`Content-Type`).toString shouldEqual "Some(Content-Type: text/html)" + response.headers.headers contains Header.Raw(ci"Content-Type", "text/html") shouldEqual true } "the routes" should "serve the other static files if dashboard is enabled" in { val response = doRequest(Request(method = Method.GET, uri = uri"/main.js")) response.status shouldEqual Status.Ok - response.headers.get(`Content-Type`).toString shouldEqual "Some(Content-Type: application/javascript)" + response.headers.headers contains Header.Raw(ci"Content-Type", "application/javascript") shouldEqual true } "the routes" should "give 404 if dashboard is disabled" in { @@ -86,7 +89,7 @@ class Http4sBakerServerSpec extends AsyncFlatSpec with AsyncIOSpec with Matcher "the routes" should "give dashboard_config" in { val response = doRequest(Request(method = Method.GET, uri = uri"/dashboard_config")) response.status shouldEqual Status.Ok - response.headers.get(`Content-Length`).toString shouldEqual "Some(Content-Length: 104)" + response.headers.headers contains Header.Raw(ci"Content-Length", "104") shouldEqual true } "the routes" should "call the underlying baker implementation" in { diff --git a/project/Dependencies.scala b/project/Dependencies.scala index a6afc2f8f..598566c99 100644 --- a/project/Dependencies.scala +++ b/project/Dependencies.scala @@ -7,9 +7,9 @@ object Dependencies { val akkaManagementVersion = "1.1.4" val akkaPersistenceCassandraVersion = "1.0.6" val akkaHttpVersion = "10.2.9" - val http4sVersion = "0.21.34" + val http4sVersion = "0.22.15" + val circeVersion = "0.14.9" val fs2Version = "2.5.12" - val circeVersion = "0.14.2" val mockitoScalaVersion = "1.17.37" val catsEffectVersion = "2.5.5" val catsCoreVersion = "2.12.0" @@ -94,7 +94,7 @@ object Dependencies { val circe = "io.circe" %% "circe-core" % circeVersion val circeParser = "io.circe" %% "circe-parser" % circeVersion val circeGeneric = "io.circe" %% "circe-generic" % circeVersion - val circeGenericExtras = "io.circe" %% "circe-generic-extras" % circeVersion + val circeGenericExtras = "io.circe" %% "circe-generic-extras" % "0.14.4" val catsEffect = "org.typelevel" %% "cats-effect" % catsEffectVersion val catsEffectTesting = "com.codecommit" %% "cats-effect-testing-scalatest" % "0.5.4" @@ -119,12 +119,12 @@ object Dependencies { val betterFiles = "com.github.pathikrit" %% "better-files" % "3.9.2" - val typeSafeConfig = "com.typesafe" % "config" % "1.4.2" + val typeSafeConfig = "com.typesafe" % "config" % "1.4.3" - val objenisis = "org.objenesis" % "objenesis" % "3.2" + val objenisis = "org.objenesis" % "objenesis" % "3.4" val jodaTime = "joda-time" % "joda-time" % "2.12.7" val slf4jApi = "org.slf4j" % "slf4j-api" % "2.0.16" - val logback = "ch.qos.logback" % "logback-classic" % "1.4.14" + val logback = "ch.qos.logback" % "logback-classic" % "1.5.7" val logstash = "net.logstash.logback" % "logstash-logback-encoder" % "7.3" val scalaCheck = "org.scalacheck" %% "scalacheck" % "1.18.0" val scalaCheckPlus = "org.scalatestplus" %% "scalacheck-1-17" % "3.2.18.0" @@ -143,10 +143,10 @@ object Dependencies { val jawnParser = "org.typelevel" %% "jawn-parser" % "1.6.0" val nettyHandler = "io.netty" % "netty-handler" % "4.1.112.Final" - private val bouncycastleVersion = "1.70" + private val bouncycastleVersion = "1.78.1" - val bouncyCastleBcprov = "org.bouncycastle" % "bcprov-jdk15on" % bouncycastleVersion - val bouncyCastleBcpkix = "org.bouncycastle" % "bcpkix-jdk15on" % bouncycastleVersion + val bouncyCastleBcprov = "org.bouncycastle" % "bcprov-jdk18on" % bouncycastleVersion + val bouncyCastleBcpkix = "org.bouncycastle" % "bcpkix-jdk18on" % bouncycastleVersion val guava = "com.google.guava" % "guava" % "33.3.0-jre" diff --git a/project/plugins.sbt b/project/plugins.sbt index 06589e8a2..5bfda6fde 100644 --- a/project/plugins.sbt +++ b/project/plugins.sbt @@ -24,4 +24,6 @@ addSbtPlugin("no.arktekk.sbt" % "aether-deploy" % "0.29.1") addSbtPlugin("community.flock.sbt" % "sbt-kotlin-plugin" % "3.0.1") +addSbtPlugin("ch.epfl.scala" % "sbt-scalafix" % "0.11.1") + libraryDependencies += "org.slf4j" % "slf4j-nop" % "2.0.16"