playframework/play-samples

Play gRPC: ALPN must be enabled and list HTTP/2 as a supported protocol

Closed this issue · 1 comments

I've tried to replicate the play-scala-grpc-example in my own Play project but it seems I cannot make this scala test pass, no matter what I do:

    "work with a gRPC client" in withGrpcClient[TenancyServiceClient] { client: TenancyServiceClient =>
      val tenantId  = UUID.randomUUID()
      val companyId = UUID.randomUUID()
      val reply =
        client.isCompanyIdOwnedByTenant(CheckCompanyRequest(tenantId.toString, companyId.toString)).futureValue
      reply.isOwnedByTenant mustBe false
    }

I've reported the details also in https://stackoverflow.com/q/77095588/1977778

I'm trying to enable ALPN and HTTP/2 in a Scala Play Framework 2.8.20 app running on JDK 11.0.20 and Scala 2.13.11 (SBT 1.9.3). My objective is to work with play-grpc and specifically to serve grpc calls using Play.

In project/plugins.sbt I added:

// Akka gRPC
addSbtPlugin("com.lightbend.akka.grpc" % "sbt-akka-grpc" % "2.1.6")
addSbtPlugin("com.github.sbt"    % "sbt-javaagent" % "0.1.7") // ALPN agent
// Cannot be moved into build.sbt
libraryDependencies += "com.lightbend.play" %% "play-grpc-generators" % "0.9.1"

In build.sbt:

lazy val `myProject` = (project in file("."))
  .enablePlugins(PlayScala)
  .enablePlugins(JavaAgent)
  .enablePlugins(AkkaGrpcPlugin)       // enables source generation for gRPC
  .enablePlugins(PlayAkkaHttp2Support) // enables serving HTTP/2 and gRPC
  .settings(
    akkaGrpcGeneratedLanguages := Seq(AkkaGrpc.Scala),
    akkaGrpcExtraGenerators += PlayScalaClientCodeGenerator,
    akkaGrpcExtraGenerators += PlayScalaServerCodeGenerator,
    // #grpc_server_generators
    PlayKeys.devSettings ++= Seq(
      "play.server.https.port" -> "9443",
      // Configures the keystore to use in Dev mode. This setting is equivalent to `play.server.https.keyStore.path`
      // in `application.conf`.
      "play.server.https.keyStore.path" -> "conf/selfsigned.keystore"
    )
  )

javaAgents += "org.mortbay.jetty.alpn" % "jetty-alpn-agent" % "2.0.10" % Runtime

When running tests I get:

[info] - must work with a gRPC client *** FAILED ***
[info]   java.lang.IllegalArgumentException: ALPN must be enabled and list HTTP/2 as a supported protocol.
[info]   at com.google.common.base.Preconditions.checkArgument(Preconditions.java:145)
[info]   at io.grpc.netty.shaded.io.grpc.netty.GrpcSslContexts.ensureAlpnAndH2Enabled(GrpcSslContexts.java:278)
[info]   at io.grpc.netty.shaded.io.grpc.netty.NettyChannelBuilder.sslContext(NettyChannelBuilder.java:350)
[info]   at akka.grpc.internal.NettyClientUtils$.createChannel(NettyClientUtils.scala:61)
[info]   at akka.grpc.internal.ChannelUtils$.create(ChannelUtils.scala:41)
[info]   at akka.grpc.GrpcChannel$.apply(GrpcChannel.scala:57)
[info]   at io.kode.protos.tenancy.TenancyServiceClient$.apply(TenancyServiceClient.scala:29)
[info]   at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[info]   at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
[info]   at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)

How should I fix this error??

ALPN must be enabled and list HTTP/2 as a supported protocol