All Downloads are FREE. Search and download functionalities are using the official Maven repository.

templates.ScalaServer.txt.Handler.template.scala Maven / Gradle / Ivy

Go to download

Apache Pekko gRPC - Support for building streaming gRPC servers and clients on top of Pekko Streams.

The newest version!

package templates.ScalaServer.txt

import _root_.play.twirl.api.TwirlFeatureImports.*
import _root_.play.twirl.api.TwirlHelperImports.*
import scala.language.adhocExtensions
import _root_.play.twirl.api.Html
import _root_.play.twirl.api.JavaScript
import _root_.play.twirl.api.Txt
import _root_.play.twirl.api.Xml

object Handler extends _root_.play.twirl.api.BaseScalaTemplate[play.twirl.api.TxtFormat.Appendable,_root_.play.twirl.api.Format[play.twirl.api.TxtFormat.Appendable]](play.twirl.api.TxtFormat) with _root_.play.twirl.api.Template2[org.apache.pekko.grpc.gen.scaladsl.Service,Boolean,play.twirl.api.TxtFormat.Appendable] {

  /*
 * Copyright (C) 2018-2021 Lightbend Inc. 
 */
  def apply/*14.2*/(service: org.apache.pekko.grpc.gen.scaladsl.Service, powerApis: Boolean):play.twirl.api.TxtFormat.Appendable = {
    _display_ {
      {


Seq[Any](format.raw/*15.1*/("""
"""),_display_(/*16.2*/org/*16.5*/.apache.pekko.grpc.gen.Constants.DoNotEditComment),format.raw/*16.54*/("""
"""),format.raw/*17.1*/("""package """),_display_(/*17.10*/service/*17.17*/.packageName),format.raw/*17.29*/("""

"""),format.raw/*19.1*/("""import scala.concurrent.ExecutionContext

import org.apache.pekko
import pekko.grpc.scaladsl."""),format.raw/*22.28*/("""{"""),format.raw/*22.29*/(""" """),format.raw/*22.30*/("""GrpcExceptionHandler, GrpcMarshalling """),format.raw/*22.68*/("""}"""),format.raw/*22.69*/("""
"""),format.raw/*23.1*/("""import pekko.grpc.Trailers

import pekko.actor.ActorSystem
import pekko.actor.ClassicActorSystemProvider
import pekko.annotation.ApiMayChange
import pekko.http.scaladsl.model
import pekko.stream."""),format.raw/*29.21*/("""{"""),format.raw/*29.22*/("""Materializer, SystemMaterializer"""),format.raw/*29.54*/("""}"""),format.raw/*29.55*/("""

"""),format.raw/*31.1*/("""import pekko.grpc.internal.TelemetryExtension

import pekko.grpc.PekkoGrpcGenerated

"""),_display_(/*35.2*/{if (powerApis) "import pekko.grpc.scaladsl.MetadataBuilder" else ""}),format.raw/*35.71*/("""

"""),_display_(/*37.2*/defining(if (powerApis) service.name + "PowerApi" else service.name)/*37.70*/ { serviceName =>_display_(Seq[Any](format.raw/*37.87*/("""
"""),format.raw/*38.1*/("""/*
 * Generated by Pekko gRPC. DO NOT EDIT.
 *
 * The API of this class may still change in future Pekko gRPC versions, see for instance
 * https://github.com/akka/akka-grpc/issues/994
 */
@ApiMayChange
@PekkoGrpcGenerated
object """),_display_(/*46.9*/{serviceName}),format.raw/*46.22*/("""Handler """),format.raw/*46.30*/("""{"""),format.raw/*46.31*/("""
    """),format.raw/*47.5*/("""private val notFound = scala.concurrent.Future.successful(model.HttpResponse(model.StatusCodes.NotFound))
    private val unsupportedMediaType = scala.concurrent.Future.successful(model.HttpResponse(model.StatusCodes.UnsupportedMediaType))

    /**
     * Creates a `HttpRequest` to `HttpResponse` handler that can be used in for example `Http().bindAndHandleAsync`
     * for the generated partial function handler and ends with `StatusCodes.NotFound` if the request is not matching.
     *
     * Use `org.apache.pekko.grpc.scaladsl.ServiceHandler.concatOrNotFound` with `"""),_display_(/*54.84*/{service.name}),format.raw/*54.98*/("""Handler.partial` when combining
     * several services.
     */
    def apply(implementation: """),_display_(/*57.32*/serviceName),format.raw/*57.43*/(""")(implicit system: ClassicActorSystemProvider): model.HttpRequest => scala.concurrent.Future[model.HttpResponse] =
      partial(implementation).orElse """),format.raw/*58.38*/("""{"""),format.raw/*58.39*/(""" case _ => notFound """),format.raw/*58.59*/("""}"""),format.raw/*58.60*/("""

    """),format.raw/*60.5*/("""/**
     * Creates a `HttpRequest` to `HttpResponse` handler that can be used in for example `Http().bindAndHandleAsync`
     * for the generated partial function handler and ends with `StatusCodes.NotFound` if the request is not matching.
     *
     * Use `org.apache.pekko.grpc.scaladsl.ServiceHandler.concatOrNotFound` with `"""),_display_(/*64.84*/{service.name}),format.raw/*64.98*/("""Handler.partial` when combining
     * several services.
     */
    def apply(implementation: """),_display_(/*67.32*/serviceName),format.raw/*67.43*/(""", eHandler: ActorSystem => PartialFunction[Throwable, Trailers])(implicit system: ClassicActorSystemProvider): model.HttpRequest => scala.concurrent.Future[model.HttpResponse] =
      partial(implementation, """),_display_(/*68.32*/{service.name}),format.raw/*68.46*/(""".name, eHandler).orElse """),format.raw/*68.70*/("""{"""),format.raw/*68.71*/(""" case _ => notFound """),format.raw/*68.91*/("""}"""),format.raw/*68.92*/("""

    """),format.raw/*70.5*/("""/**
     * Creates a `HttpRequest` to `HttpResponse` handler that can be used in for example `Http().bindAndHandleAsync`
     * for the generated partial function handler and ends with `StatusCodes.NotFound` if the request is not matching.
     *
     * Use `org.apache.pekko.grpc.scaladsl.ServiceHandler.concatOrNotFound` with `"""),_display_(/*74.84*/{service.name}),format.raw/*74.98*/("""Handler.partial` when combining
     * several services.
     *
     * Registering a gRPC service under a custom prefix is not widely supported and strongly discouraged by the specification.
     */
    def apply(implementation: """),_display_(/*79.32*/serviceName),format.raw/*79.43*/(""", prefix: String)(implicit system: ClassicActorSystemProvider): model.HttpRequest => scala.concurrent.Future[model.HttpResponse] =
      partial(implementation, prefix).orElse """),format.raw/*80.46*/("""{"""),format.raw/*80.47*/(""" case _ => notFound """),format.raw/*80.67*/("""}"""),format.raw/*80.68*/("""

    """),format.raw/*82.5*/("""/**
     * Creates a `HttpRequest` to `HttpResponse` handler that can be used in for example `Http().bindAndHandleAsync`
     * for the generated partial function handler and ends with `StatusCodes.NotFound` if the request is not matching.
     *
     * Use `org.apache.pekko.grpc.scaladsl.ServiceHandler.concatOrNotFound` with `"""),_display_(/*86.84*/{service.name}),format.raw/*86.98*/("""Handler.partial` when combining
     * several services.
     *
     * Registering a gRPC service under a custom prefix is not widely supported and strongly discouraged by the specification.
     */
    def apply(implementation: """),_display_(/*91.32*/serviceName),format.raw/*91.43*/(""", prefix: String, eHandler: ActorSystem => PartialFunction[Throwable, Trailers])(implicit system: ClassicActorSystemProvider): model.HttpRequest => scala.concurrent.Future[model.HttpResponse] =
      partial(implementation, prefix, eHandler).orElse """),format.raw/*92.56*/("""{"""),format.raw/*92.57*/(""" case _ => notFound """),format.raw/*92.77*/("""}"""),format.raw/*92.78*/("""

"""),_display_(if(serviceName != "ServerReflection")/*94.39*/ {_display_(Seq[Any](format.raw/*94.41*/("""

    """),format.raw/*96.5*/("""/**
     * Creates a `HttpRequest` to `HttpResponse` handler that can be used in for example `Http().bindAndHandleAsync`
     * for the generated partial function handler. The generated handler falls back to a reflection handler for
     * `"""),_display_(/*99.10*/{service.name}),format.raw/*99.24*/("""` and ends with `StatusCodes.NotFound` if the request is not matching.
     *
     * Use `org.apache.pekko.grpc.scaladsl.ServiceHandler.concatOrNotFound` with `"""),_display_(/*101.84*/{service.name}),format.raw/*101.98*/("""Handler.partial` when combining
     * several services.
     */
    def withServerReflection(implementation: """),_display_(/*104.47*/serviceName),format.raw/*104.58*/(""")(implicit system: ClassicActorSystemProvider): model.HttpRequest => scala.concurrent.Future[model.HttpResponse] =
        pekko.grpc.scaladsl.ServiceHandler.concatOrNotFound(
          """),_display_(/*106.12*/{serviceName}),format.raw/*106.25*/("""Handler.partial(implementation),
          pekko.grpc.scaladsl.ServerReflection.partial(List("""),_display_(/*107.62*/{service.name}),format.raw/*107.76*/(""")))
""")))} else {null} ),format.raw/*108.2*/("""

    """),format.raw/*110.5*/("""/**
     * Creates a partial `HttpRequest` to `HttpResponse` handler that can be combined with handlers of other
     * services with `org.apache.pekko.grpc.scaladsl.ServiceHandler.concatOrNotFound` and then used in for example
     * `Http().bindAndHandleAsync`.
     *
     * Use `"""),_display_(/*115.14*/{service.name}),format.raw/*115.28*/("""Handler.apply` if the server is only handling one service.
     *
     * Registering a gRPC service under a custom prefix is not widely supported and strongly discouraged by the specification.
     */
    def partial(implementation: """),_display_(/*119.34*/serviceName),format.raw/*119.45*/(""", prefix: String = """),_display_(/*119.65*/{service.name}),format.raw/*119.79*/(""".name, eHandler: ActorSystem => PartialFunction[Throwable, Trailers] = GrpcExceptionHandler.defaultMapper)(implicit system: ClassicActorSystemProvider): PartialFunction[model.HttpRequest, scala.concurrent.Future[model.HttpResponse]] = """),format.raw/*119.314*/("""{"""),format.raw/*119.315*/("""
      """),format.raw/*120.7*/("""implicit val mat: Materializer = SystemMaterializer(system).materializer
      implicit val ec: ExecutionContext = mat.executionContext
      val spi = TelemetryExtension(system).spi

      import """),_display_(/*124.15*/{service.name}),format.raw/*124.29*/(""".Serializers."""),_display_(/*124.43*/{service.scalaCompatConstants.WildcardImport}),format.raw/*124.88*/("""

      """),format.raw/*126.7*/("""def handle(request: model.HttpRequest, method: String): scala.concurrent.Future[model.HttpResponse] =
        GrpcMarshalling.negotiated(request, (reader, writer) =>
          (method match """),format.raw/*128.25*/("""{"""),format.raw/*128.26*/("""
            """),_display_(/*129.14*/for(method <- service.methods) yield /*129.44*/ {_display_(Seq[Any](format.raw/*129.46*/("""
            case """"),_display_(/*130.20*/method/*130.26*/.grpcName),format.raw/*130.35*/("""" =>
                """),_display_(/*131.18*/{if(powerApis) { "val metadata = MetadataBuilder.fromHeaders(request.headers)" } else { "" }}),format.raw/*131.111*/("""
                """),_display_(/*132.18*/{method.unmarshal}),format.raw/*132.36*/("""(request.entity)("""),_display_(/*132.54*/method/*132.60*/.deserializer.name),format.raw/*132.78*/(""", mat, reader)
                  ."""),_display_(/*133.21*/{if(method.outputStreaming) { "map" } else { "flatMap" }}),format.raw/*133.78*/("""(implementation."""),_display_(/*133.95*/{method.nameSafe}),format.raw/*133.112*/("""(_"""),_display_(/*133.115*/{if(powerApis) { ", metadata" } else { "" }}),format.raw/*133.159*/("""))
                  .map(e => """),_display_(/*134.30*/{method.marshal}),format.raw/*134.46*/("""(e, eHandler)("""),_display_(/*134.61*/method/*134.67*/.serializer.name),format.raw/*134.83*/(""", writer, system))
            """)))}),format.raw/*135.14*/("""
            case m => scala.concurrent.Future.failed(new NotImplementedError(s"Not implemented: $m"))
          """),format.raw/*137.11*/("""}"""),format.raw/*137.12*/(""")
          .recoverWith(GrpcExceptionHandler.from(eHandler(system.classicSystem))(system, writer))
      ).getOrElse(unsupportedMediaType)

      Function.unlift((req: model.HttpRequest) => req.uri.path match """),format.raw/*141.70*/("""{"""),format.raw/*141.71*/("""
        case model.Uri.Path.Slash(model.Uri.Path.Segment(`prefix`, model.Uri.Path.Slash(model.Uri.Path.Segment(method, model.Uri.Path.Empty)))) =>
          Some(handle(spi.onRequest(prefix, method, req), method))
        case _ =>
          None
      """),format.raw/*146.7*/("""}"""),format.raw/*146.8*/(""")
    """),format.raw/*147.5*/("""}"""),format.raw/*147.6*/("""
  """),format.raw/*148.3*/("""}"""),format.raw/*148.4*/("""
""")))}),format.raw/*149.2*/("""
"""))
      }
    }
  }

  def render(service:org.apache.pekko.grpc.gen.scaladsl.Service,powerApis:Boolean): play.twirl.api.TxtFormat.Appendable = apply(service,powerApis)

  def f:((org.apache.pekko.grpc.gen.scaladsl.Service,Boolean) => play.twirl.api.TxtFormat.Appendable) = (service,powerApis) => apply(service,powerApis)

  def ref: this.type = this

}


              /*
                  -- GENERATED --
                  SOURCE: codegen/src/main/twirl/templates/ScalaServer/Handler.scala.txt
                  HASH: 87c276a59c58a5c9d718cadf28b81aa3af406252
                  MATRIX: 734->364|901->438|929->440|940->443|1010->492|1038->493|1074->502|1090->509|1123->521|1152->523|1273->616|1302->617|1331->618|1397->656|1426->657|1454->658|1677->853|1706->854|1766->886|1795->887|1824->889|1936->975|2026->1044|2055->1047|2132->1115|2187->1132|2215->1133|2472->1366|2506->1379|2542->1387|2571->1388|2603->1393|3205->1968|3240->1982|3363->2078|3395->2089|3575->2241|3604->2242|3652->2262|3681->2263|3714->2269|4071->2599|4106->2613|4229->2709|4261->2720|4497->2929|4532->2943|4584->2967|4613->2968|4661->2988|4690->2989|4723->2995|5080->3325|5115->3339|5372->3569|5404->3580|5608->3756|5637->3757|5685->3777|5714->3778|5747->3784|6104->4114|6139->4128|6396->4358|6428->4369|6705->4618|6734->4619|6782->4639|6811->4640|6878->4680|6918->4682|6951->4688|7220->4930|7255->4944|7444->5105|7480->5119|7619->5230|7652->5241|7867->5428|7902->5441|8024->5535|8060->5549|8109->5554|8143->5560|8455->5844|8491->5858|8753->6092|8786->6103|8834->6123|8870->6137|9135->6372|9166->6373|9201->6380|9427->6578|9463->6592|9505->6606|9572->6651|9608->6659|9827->6849|9857->6850|9899->6864|9946->6894|9987->6896|10035->6916|10051->6922|10082->6931|10132->6953|10248->7046|10294->7064|10334->7082|10380->7100|10396->7106|10436->7124|10499->7159|10578->7216|10623->7233|10663->7250|10695->7253|10762->7297|10822->7329|10860->7345|10903->7360|10919->7366|10957->7382|11021->7414|11163->7527|11193->7528|11432->7738|11462->7739|11744->7993|11773->7994|11807->8000|11836->8001|11867->8004|11896->8005|11929->8007
                  LINES: 17->14|22->15|23->16|23->16|23->16|24->17|24->17|24->17|24->17|26->19|29->22|29->22|29->22|29->22|29->22|30->23|36->29|36->29|36->29|36->29|38->31|42->35|42->35|44->37|44->37|44->37|45->38|53->46|53->46|53->46|53->46|54->47|61->54|61->54|64->57|64->57|65->58|65->58|65->58|65->58|67->60|71->64|71->64|74->67|74->67|75->68|75->68|75->68|75->68|75->68|75->68|77->70|81->74|81->74|86->79|86->79|87->80|87->80|87->80|87->80|89->82|93->86|93->86|98->91|98->91|99->92|99->92|99->92|99->92|101->94|101->94|103->96|106->99|106->99|108->101|108->101|111->104|111->104|113->106|113->106|114->107|114->107|115->108|117->110|122->115|122->115|126->119|126->119|126->119|126->119|126->119|126->119|127->120|131->124|131->124|131->124|131->124|133->126|135->128|135->128|136->129|136->129|136->129|137->130|137->130|137->130|138->131|138->131|139->132|139->132|139->132|139->132|139->132|140->133|140->133|140->133|140->133|140->133|140->133|141->134|141->134|141->134|141->134|141->134|142->135|144->137|144->137|148->141|148->141|153->146|153->146|154->147|154->147|155->148|155->148|156->149
                  -- GENERATED --
              */
          




© 2015 - 2025 Weber Informatics LLC | Privacy Policy