pl.touk.nussknacker.engine.embedded.requestresponse.ScenarioDispatcherRoute.scala Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of nussknacker-lite-embedded-deploymentmanager_2.13 Show documentation
Show all versions of nussknacker-lite-embedded-deploymentmanager_2.13 Show documentation
nussknacker-lite-embedded-deploymentManager
The newest version!
package pl.touk.nussknacker.engine.embedded.requestresponse
import akka.event.Logging
import akka.http.scaladsl.model.{HttpResponse, StatusCodes}
import akka.http.scaladsl.server.directives.DebuggingDirectives
import akka.http.scaladsl.server.{Directive0, Directives, Route}
import akka.stream.Materializer
import com.typesafe.scalalogging.LazyLogging
import scala.concurrent.ExecutionContext
class ScenarioDispatcherRoute(scenarioRoutes: scala.collection.Map[String, Route]) extends Directives with LazyLogging {
protected def logDirective(scenarioName: String): Directive0 =
DebuggingDirectives.logRequestResult((s"request-response-$scenarioName", Logging.DebugLevel))
def route(implicit ec: ExecutionContext, mat: Materializer): Route =
pathPrefix("scenario" / Segment) { scenarioSlug =>
handle(scenarioSlug)
}
private def handle(scenarioSlug: String): Route = scenarioRoutes.get(scenarioSlug) match {
case None =>
complete {
HttpResponse(status = StatusCodes.NotFound)
}
case Some(r) => r
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy