Skip to content

Commit

Permalink
remove isGrpcRequest check from the java api to align with scala api (#…
Browse files Browse the repository at this point in the history
…1669)

* remove isGrpcRequest check from the java api to align with scala api

* adopd comment to the new logic
  • Loading branch information
sebastian-alfers authored Aug 26, 2022
1 parent 6e38aed commit d125b95
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 7 deletions.
7 changes: 2 additions & 5 deletions runtime/src/main/scala/akka/grpc/javadsl/ServiceHandler.scala
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import java.util.concurrent.{ CompletableFuture, CompletionStage }

import akka.annotation.ApiMayChange
import akka.annotation.InternalApi
import akka.grpc.scaladsl.{ ServiceHandler => sServiceHandler }
import akka.http.javadsl.model.{ HttpRequest, HttpResponse, StatusCodes }
import akka.japi.function.{ Function => JFunction }

Expand Down Expand Up @@ -42,15 +41,13 @@ object ServiceHandler {
/**
* Creates a `HttpRequest` to `HttpResponse` handler for gRPC services that can be used in
* for example `Http().bindAndHandleAsync` for the generated partial function handlers:
* - The generated handler supports the `application/grpc` media type.
* - If the request is for an invalid media type, then a _415: Unsupported Media Type_ response is produced.
* - Otherwise if the request is not handled by one of the provided handlers, a _404: Not Found_ response is produced.
* - If the request is not handled by one of the provided handlers, a _404: Not Found_ response is produced.
*/
@varargs
def handler(handlers: JFunction[HttpRequest, CompletionStage[HttpResponse]]*)
: JFunction[HttpRequest, CompletionStage[HttpResponse]] = {
val servicesHandler = concat(handlers: _*)
(req: HttpRequest) => if (sServiceHandler.isGrpcRequest(req)) servicesHandler(req) else unsupportedMediaType
(req: HttpRequest) => servicesHandler(req)
}

private[javadsl] def concat(handlers: JFunction[HttpRequest, CompletionStage[HttpResponse]]*)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ package akka.grpc.scaladsl

import akka.annotation.ApiMayChange
import akka.grpc.GrpcProtocol
import akka.grpc.internal.{ GrpcProtocolNative, GrpcProtocolWeb, GrpcProtocolWebText }
import akka.grpc.internal.{ GrpcProtocolWeb, GrpcProtocolWebText }
import akka.http.javadsl.{ model => jmodel }
import akka.http.scaladsl.model.{ HttpRequest, HttpResponse, StatusCodes }

Expand All @@ -23,7 +23,6 @@ object ServiceHandler {
private def matchesVariant(variants: Set[GrpcProtocol])(request: jmodel.HttpRequest) =
variants.exists(_.mediaTypes.contains(request.entity.getContentType.mediaType))

private[grpc] val isGrpcRequest: jmodel.HttpRequest => Boolean = matchesVariant(Set(GrpcProtocolNative))
private[grpc] val isGrpcWebRequest: jmodel.HttpRequest => Boolean = matchesVariant(
Set(GrpcProtocolWeb, GrpcProtocolWebText))

Expand Down

0 comments on commit d125b95

Please sign in to comment.