Adven27 / grpc-wiremock

gRPC Mock Server
MIT License
93 stars 40 forks source link

Headers propagation causes errors for some clients #22

Closed codami closed 3 years ago

codami commented 3 years ago

For clients like BloomRPC the mock server fails (because of the encoding I would assume) like this:

2021-10-07 12:25:21.056  INFO 101 --- [ault-executor-2] io.adven.grpc.wiremock.HttpMock          : Grpc request BalanceService/getUserBalance:
Headers: {grpc-accept-encoding=identity,deflate,gzip, content-type=application/grpc, accept-encoding=identity,gzip, user-agent=grpc-node/1.24.2 grpc-c/8.0.0 (windows; chttp2; ganges)}
Message:
id: 100
currency: "Hello"

2021-10-07 12:25:21.070  INFO 101 --- [ault-executor-2] io.adven.grpc.wiremock.HttpMock          : Converting to class api.wallet.UserBalanceResponse json:
▼��RPPJJ�I�KNU�R�♠r�☻����y%p>P�,1�4§I(�������♥¶T2�3P�J��h�/(J-N♣�URT�ʅ�D)���(5/�↕�=J�~�J8�JK�)���♣µI;(��
2021-10-07 12:25:21.072 ERROR 101 --- [ault-executor-2] io.grpc.internal.SerializingExecutor     : Exception while executing runnable io.grpc.internal.ServerImpl$JumpToApplicationThreadServerStreamListener$1HalfClosed@6d5ba219

java.lang.IllegalArgumentException: Failed to convert ▼��RPPJJ�I�KNU�R�♠r�☻����y%p>P�,1�4§I(�������♥¶T2�3P�J��h�/(J-N♣�URT�ʅ�D)���(5/�↕�=J�~�J8�JK�)���♣µI;(�� to class api.wallet.UserBalanceResponse
        at io.adven.grpc.wiremock.HttpMock$ProtoJsonUtil.fromJson(HttpMock.java:117) ~[main/:na]
        at io.adven.grpc.wiremock.HttpMock.send(HttpMock.java:79) ~[main/:na]
        at io.adven.grpc.wiremock.Translator$WireMockTranslator.redirect(Translator.java:31) ~[main/:na]
        at io.adven.grpc.wiremock.Translator$WireMockTranslator.redirectApiWalletBalanceService(Translator.java:39) ~[main/:na]
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:na]
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:na]
        at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:na]
        at java.base/java.lang.reflect.Method.invoke(Method.java:566) ~[na:na]
        at org.springframework.aop.aspectj.AbstractAspectJAdvice.invokeAdviceMethodWithGivenArgs(AbstractAspectJAdvice.java:634) ~[spring-aop-5.3.10.jar:5.3.10]
        at org.springframework.aop.aspectj.AbstractAspectJAdvice.invokeAdviceMethod(AbstractAspectJAdvice.java:624) ~[spring-aop-5.3.10.jar:5.3.10]
        at org.springframework.aop.aspectj.AspectJAroundAdvice.invoke(AspectJAroundAdvice.java:72) ~[spring-aop-5.3.10.jar:5.3.10]
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186) ~[spring-aop-5.3.10.jar:5.3.10]
        at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:750) ~[spring-aop-5.3.10.jar:5.3.10]
        at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:97) ~[spring-aop-5.3.10.jar:5.3.10]
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186) ~[spring-aop-5.3.10.jar:5.3.10]
        at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:750) ~[spring-aop-5.3.10.jar:5.3.10]
        at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:692) ~[spring-aop-5.3.10.jar:5.3.10]
        at io.adven.grpc.wiremock.Translator$ApiWalletBalanceService$$EnhancerBySpringCGLIB$$11421f8f.getUserBalance(<generated>) ~[main/:na]
        at api.wallet.BalanceServiceGrpc$MethodHandlers.invoke(BalanceServiceGrpc.java:205) ~[main/:na]
        at io.grpc.stub.ServerCalls$UnaryServerCallHandler$UnaryServerCallListener.onHalfClose(ServerCalls.java:182) ~[grpc-stub-1.41.0.jar:1.41.0]
        at io.grpc.PartialForwardingServerCallListener.onHalfClose(PartialForwardingServerCallListener.java:35) ~[grpc-api-1.41.0.jar:1.41.0]
        at io.grpc.ForwardingServerCallListener.onHalfClose(ForwardingServerCallListener.java:23) ~[grpc-api-1.41.0.jar:1.41.0]
        at io.grpc.ForwardingServerCallListener$SimpleForwardingServerCallListener.onHalfClose(ForwardingServerCallListener.java:40) ~[grpc-api-1.41.0.jar:1.41.0]
        at io.grpc.Contexts$ContextualizedServerCallListener.onHalfClose(Contexts.java:86) ~[grpc-api-1.41.0.jar:1.41.0]
        at io.grpc.PartialForwardingServerCallListener.onHalfClose(PartialForwardingServerCallListener.java:35) ~[grpc-api-1.41.0.jar:1.41.0]
        at io.grpc.ForwardingServerCallListener.onHalfClose(ForwardingServerCallListener.java:23) ~[grpc-api-1.41.0.jar:1.41.0]
        at io.grpc.ForwardingServerCallListener$SimpleForwardingServerCallListener.onHalfClose(ForwardingServerCallListener.java:40) ~[grpc-api-1.41.0.jar:1.41.0]
        at io.adven.grpc.wiremock.ExceptionHandler$ExceptionHandlingServerCallListener.onHalfClose(ExceptionHandler.java:42) ~[main/:na]
        at io.grpc.internal.ServerCallImpl$ServerStreamListenerImpl.halfClosed(ServerCallImpl.java:335) ~[grpc-core-1.41.0.jar:1.41.0]
        at io.grpc.internal.ServerImpl$JumpToApplicationThreadServerStreamListener$1HalfClosed.runInContext(ServerImpl.java:866) ~[grpc-core-1.41.0.jar:1.41.0]
        at io.grpc.internal.ContextRunnable.run(ContextRunnable.java:37) ~[grpc-core-1.41.0.jar:1.41.0]
        at io.grpc.internal.SerializingExecutor.run(SerializingExecutor.java:133) ~[grpc-core-1.41.0.jar:1.41.0]
        at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128) ~[na:na]
        at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628) ~[na:na]
        at java.base/java.lang.Thread.run(Thread.java:829) ~[na:na]
Caused by: com.google.protobuf.InvalidProtocolBufferException: Expect message object but got: "\u001f�\b\u0000\u0000\u0000\u0000\u0000\u0000\u0000��RPPJJ�I�KNU�R�\u0006r�\u0002����y%p>P�"
        at com.google.protobuf.util.JsonFormat$ParserImpl.mergeMessage(JsonFormat.java:1481) ~[protobuf-java-util-3.17.2.jar:na]
        at com.google.protobuf.util.JsonFormat$ParserImpl.merge(JsonFormat.java:1458) ~[protobuf-java-util-3.17.2.jar:na]
        at com.google.protobuf.util.JsonFormat$ParserImpl.merge(JsonFormat.java:1340) ~[protobuf-java-util-3.17.2.jar:na]
        at com.google.protobuf.util.JsonFormat$Parser.merge(JsonFormat.java:476) ~[protobuf-java-util-3.17.2.jar:na]
        at io.adven.grpc.wiremock.HttpMock$ProtoJsonUtil.fromJson(HttpMock.java:112) ~[main/:na]
        ... 34 common frames omitted
codami commented 3 years ago

grpcurl works fine:

2021-10-07 12:32:55.146  INFO 101 --- [ault-executor-3] io.adven.grpc.wiremock.HttpMock          : Grpc request BalanceService/getUserBalance:
Headers: {content-type=application/grpc, user-agent=grpcurl/v1.8.0 grpc-go/1.30.0}
Message:

2021-10-07 12:32:55.157  INFO 101 --- [ault-executor-3] io.adven.grpc.wiremock.HttpMock          : Converting to class api.wallet.UserBalanceResponse json:
{
  "balance": {
    "amount": {
      "value": {
        "decimal": "0.0"
      },
      "value_present": true
    },
    "currency": {
      "value": "ANY",
      "value_present": false
    }
  }
}