Skip to content
This repository was archived by the owner on Mar 16, 2022. It is now read-only.

Commit d7d5453

Browse files
authored
Use full service name in default mappings for HTTP API (#504)
1 parent 3a25f6e commit d7d5453

File tree

5 files changed

+43
-3
lines changed

5 files changed

+43
-3
lines changed

proxy/core/src/main/scala/io/cloudstate/proxy/HttpApi.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -674,7 +674,7 @@ object HttpApi {
674674
body = "*", // Parse all input
675675
responseBody = "", // Include all output
676676
additionalBindings = Nil, // No need for additional bindings
677-
pattern = HttpRule.Pattern.Post((Path / "v1" / method.getName).toString)
677+
pattern = HttpRule.Pattern.Post((Path / service.getFullName / method.getName).toString)
678678
)
679679
log.info(s"Using generated HTTP API endpoint using [$rule]")
680680
rule

proxy/core/src/main/scala/io/cloudstate/proxy/Serve.scala

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,15 @@ import akka.grpc.internal.{
2828
}
2929
import akka.NotUsed
3030
import akka.grpc.{ProtobufSerializer, Trailers}
31-
import akka.http.scaladsl.model.{HttpEntity, HttpHeader, HttpRequest, HttpResponse, StatusCodes}
31+
import akka.http.scaladsl.model.{
32+
ContentTypes,
33+
HttpEntity,
34+
HttpHeader,
35+
HttpProtocols,
36+
HttpRequest,
37+
HttpResponse,
38+
StatusCodes
39+
}
3240
import akka.http.scaladsl.model.Uri.Path
3341
import akka.actor.{ActorRef, ActorSystem}
3442
import akka.event.{Logging, LoggingAdapter}
@@ -196,6 +204,11 @@ object Serve {
196204
)
197205
}
198206

207+
private def isGrpcRequest(request: HttpRequest): Boolean =
208+
(request.protocol == HttpProtocols.`HTTP/2.0`) &&
209+
((request.entity.contentType == ContentTypes.`application/grpc+proto`) ||
210+
(request.entity.contentType.mediaType.value == "application/grpc"))
211+
199212
private[this] final def createGrpcApi(entities: Seq[ServableEntity],
200213
router: UserFunctionRouter,
201214
entityDiscoveryClient: EntityDiscoveryClient,
@@ -215,7 +228,7 @@ object Serve {
215228
}).toMap
216229

217230
val routes: PartialFunction[HttpRequest, Future[(List[HttpHeader], Source[ProtobufAny, NotUsed])]] = {
218-
case req: HttpRequest if rpcMethodSerializers.contains(req.uri.path) =>
231+
case req: HttpRequest if isGrpcRequest(req) && rpcMethodSerializers.contains(req.uri.path) =>
219232
log.debug("Received gRPC request [{}]", req.uri.path)
220233

221234
val handler = rpcMethodSerializers(req.uri.path)

tck/src/main/scala/io/cloudstate/tck/CrdtEntityTCK.scala

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1952,6 +1952,15 @@ trait CrdtEntityTCK extends TCKSpec {
19521952
.expectIncoming(command(1, id, "Process", Request(id)))
19531953
.expectOutgoing(reply(1, PNCounter.state(0)))
19541954

1955+
client.http
1956+
.request("cloudstate.tck.model.crdt.CrdtTwo/Call", s"""{"id": "$id"}""")
1957+
.futureValue mustBe "{}"
1958+
interceptor
1959+
.expectCrdtEntityConnection()
1960+
.expectIncoming(init(ServiceTwo, id))
1961+
.expectIncoming(command(1, id, "Call", Request(id)))
1962+
.expectOutgoing(reply(1, Response()))
1963+
19551964
client.http
19561965
.request(s"tck/model/crdt/$id", """{"actions": [{"update": {"pncounter": {"change": 42} }}]}""")
19571966
.futureValue mustBe """{"state":{"pncounter":{"value":"42"}}}"""

tck/src/main/scala/io/cloudstate/tck/EntityTCK.scala

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -425,6 +425,15 @@ trait EntityTCK extends TCKSpec {
425425
.expectIncoming(command(1, id, "Process", Request(id)))
426426
.expectOutgoing(reply(1, Response()))
427427

428+
client.http
429+
.request("cloudstate.tck.model.valueentity.ValueEntityTwo/Call", s"""{"id": "$id"}""")
430+
.futureValue mustBe """{"message":""}"""
431+
interceptor
432+
.expectEntityConnection()
433+
.expectIncoming(init(ServiceTwo, id))
434+
.expectIncoming(command(1, id, "Call", Request(id)))
435+
.expectOutgoing(reply(1, Response()))
436+
428437
client.http
429438
.request(s"tck/model/entity/$id", """{"actions": [{"update": {"value": "one"}}]}""")
430439
.futureValue mustBe """{"message":"one"}"""

tck/src/main/scala/io/cloudstate/tck/EventSourcedEntityTCK.scala

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -504,6 +504,15 @@ trait EventSourcedEntityTCK extends TCKSpec {
504504
.expectIncoming(command(1, id, "Process", Request(id)))
505505
.expectOutgoing(reply(1, Response()))
506506

507+
client.http
508+
.request("cloudstate.tck.model.EventSourcedTwo/Call", s"""{"id": "$id"}""")
509+
.futureValue mustBe """{"message":""}"""
510+
interceptor
511+
.expectEventSourcedEntityConnection()
512+
.expectIncoming(init(ServiceTwo, id))
513+
.expectIncoming(command(1, id, "Call", Request(id)))
514+
.expectOutgoing(reply(1, Response()))
515+
507516
client.http
508517
.request(s"tck/model/eventsourced/$id", """{"actions": [{"emit": {"value": "x"}}]}""")
509518
.futureValue mustBe """{"message":"x"}"""

0 commit comments

Comments
 (0)