templates.ScalaServer.txt.Handler.template.scala Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of pekko-grpc-codegen_2.12 Show documentation
Show all versions of pekko-grpc-codegen_2.12 Show documentation
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 _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: 454915652008ff912a7960236aad3597720d824c
MATRIX: 696->364|863->438|891->440|902->443|972->492|1000->493|1036->502|1052->509|1085->521|1114->523|1235->616|1264->617|1293->618|1359->656|1388->657|1416->658|1639->853|1668->854|1728->886|1757->887|1786->889|1898->975|1988->1044|2017->1047|2094->1115|2149->1132|2177->1133|2434->1366|2468->1379|2504->1387|2533->1388|2565->1393|3167->1968|3202->1982|3325->2078|3357->2089|3537->2241|3566->2242|3614->2262|3643->2263|3676->2269|4033->2599|4068->2613|4191->2709|4223->2720|4459->2929|4494->2943|4546->2967|4575->2968|4623->2988|4652->2989|4685->2995|5042->3325|5077->3339|5334->3569|5366->3580|5570->3756|5599->3757|5647->3777|5676->3778|5709->3784|6066->4114|6101->4128|6358->4358|6390->4369|6667->4618|6696->4619|6744->4639|6773->4640|6840->4680|6880->4682|6913->4688|7182->4930|7217->4944|7406->5105|7442->5119|7581->5230|7614->5241|7829->5428|7864->5441|7986->5535|8022->5549|8071->5554|8105->5560|8417->5844|8453->5858|8715->6092|8748->6103|8796->6123|8832->6137|9097->6372|9128->6373|9163->6380|9389->6578|9425->6592|9467->6606|9534->6651|9570->6659|9789->6849|9819->6850|9861->6864|9908->6894|9949->6896|9997->6916|10013->6922|10044->6931|10094->6953|10210->7046|10256->7064|10296->7082|10342->7100|10358->7106|10398->7124|10461->7159|10540->7216|10585->7233|10625->7250|10657->7253|10724->7297|10784->7329|10822->7345|10865->7360|10881->7366|10919->7382|10983->7414|11125->7527|11155->7528|11394->7738|11424->7739|11706->7993|11735->7994|11769->8000|11798->8001|11829->8004|11858->8005|11891->8007
LINES: 16->14|21->15|22->16|22->16|22->16|23->17|23->17|23->17|23->17|25->19|28->22|28->22|28->22|28->22|28->22|29->23|35->29|35->29|35->29|35->29|37->31|41->35|41->35|43->37|43->37|43->37|44->38|52->46|52->46|52->46|52->46|53->47|60->54|60->54|63->57|63->57|64->58|64->58|64->58|64->58|66->60|70->64|70->64|73->67|73->67|74->68|74->68|74->68|74->68|74->68|74->68|76->70|80->74|80->74|85->79|85->79|86->80|86->80|86->80|86->80|88->82|92->86|92->86|97->91|97->91|98->92|98->92|98->92|98->92|100->94|100->94|102->96|105->99|105->99|107->101|107->101|110->104|110->104|112->106|112->106|113->107|113->107|114->108|116->110|121->115|121->115|125->119|125->119|125->119|125->119|125->119|125->119|126->120|130->124|130->124|130->124|130->124|132->126|134->128|134->128|135->129|135->129|135->129|136->130|136->130|136->130|137->131|137->131|138->132|138->132|138->132|138->132|138->132|139->133|139->133|139->133|139->133|139->133|139->133|140->134|140->134|140->134|140->134|140->134|141->135|143->137|143->137|147->141|147->141|152->146|152->146|153->147|153->147|154->148|154->148|155->149
-- GENERATED --
*/
© 2015 - 2025 Weber Informatics LLC | Privacy Policy