LogNet / grpc-spring-boot-starter

Spring Boot starter module for gRPC framework.
Apache License 2.0
2.23k stars 433 forks source link

GRpcServicesRegistry#descriptorToServiceMethod not mapping method names #267

Open tobq opened 3 years ago

tobq commented 3 years ago

org.lognet.springboot.grpc.GRpcServicesRegistry#descriptorToServiceMethod doesn't map the RPC methods, of the form rpc_method_name (snake-case) to the generated java methods, of the form rpcMethodName (camel-case).

This causes the following error to be thrown at run-time:

org.lognet.springboot.grpc.security.SecurityInterceptor$1: Authentication failure.
    at org.lognet.springboot.grpc.security.SecurityInterceptor.interceptCall(SecurityInterceptor.java:147) ~[grpc-spring-boot-starter-4.5.10.jar:na]
    at io.grpc.ServerInterceptors$InterceptCallHandler.startCall(ServerInterceptors.java:244) ~[grpc-api-1.42.0.jar:1.42.0]
    at org.lognet.springboot.grpc.recovery.GRpcExceptionHandlerInterceptor.interceptCall(GRpcExceptionHandlerInterceptor.java:59) ~[grpc-spring-boot-starter-4.5.10.jar:na]
    at io.grpc.ServerInterceptors$InterceptCallHandler.startCall(ServerInterceptors.java:244) ~[grpc-api-1.42.0.jar:1.42.0]
    at io.grpc.internal.ServerImpl$ServerTransportListenerImpl.startWrappedCall(ServerImpl.java:703) ~[grpc-core-1.42.0.jar:1.42.0]
    at io.grpc.internal.ServerImpl$ServerTransportListenerImpl.access$2200(ServerImpl.java:406) ~[grpc-core-1.42.0.jar:1.42.0]
    at io.grpc.internal.ServerImpl$ServerTransportListenerImpl$1HandleServerCall.runInternal(ServerImpl.java:615) ~[grpc-core-1.42.0.jar:1.42.0]
    at io.grpc.internal.ServerImpl$ServerTransportListenerImpl$1HandleServerCall.runInContext(ServerImpl.java:603) ~[grpc-core-1.42.0.jar:1.42.0]
    at io.grpc.internal.ContextRunnable.run(ContextRunnable.java:37) ~[grpc-core-1.42.0.jar:1.42.0]
    at io.grpc.internal.SerializingExecutor.run(SerializingExecutor.java:133) ~[grpc-core-1.42.0.jar:1.42.0]
    at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1135) ~[na:na]
    at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635) ~[na:na]
    at java.base/java.lang.Thread.run(Thread.java:831) ~[na:na]
Caused by: java.lang.IllegalStateException: Method ***rpc_method_name*** not found in service ***org.me.MyGrpcService***
    at org.lognet.springboot.grpc.GRpcServicesRegistry.descriptorToServiceMethod(GRpcServicesRegistry.java:186) ~[grpc-spring-boot-starter-4.5.10.jar:na]
    at org.springframework.util.function.SingletonSupplier.get(SingletonSupplier.java:97) ~[spring-core-5.3.7.jar:5.3.7]
    at org.lognet.springboot.grpc.GRpcServicesRegistry.getGrpServiceMethod(GRpcServicesRegistry.java:120) ~[grpc-spring-boot-starter-4.5.10.jar:na]
    at org.lognet.springboot.grpc.security.SecurityInterceptor.setupGRpcSecurityContext(SecurityInterceptor.java:261) ~[grpc-spring-boot-starter-4.5.10.jar:na]
    at org.lognet.springboot.grpc.security.SecurityInterceptor.interceptCall(SecurityInterceptor.java:143) ~[grpc-spring-boot-starter-4.5.10.jar:na]
    ... 12 common frames omitted
jvmlet commented 3 years ago

Please post your proto as a sample

tobq commented 3 years ago

@jvmlet Here's an abstracted version

syntax = "proto3";

package org.tobi;
option java_package = "org.tobi.grpc";
option java_multiple_files = true;

import "....proto";
service MyGrpcService {
  rpc rpc_method_name(org.tobi...) returns (RpcResponse) {};
}
tobq commented 3 years ago

@jvmlet seems the problem is the generator, at compile time, compiles to camelCase, however at runtime, the library is not doing this same conversion from snake_case to camelCase

tobq commented 2 years ago

Any updates? @jvmlet

jvmlet commented 2 years ago

https://github.com/grpc/grpc-java/issues/8826

tobq commented 2 years ago

@jvmlet I put this hack in place:

    private static final Pattern SNAKE_CASE_PATTERN = Pattern.compile("_");
// ...
        Function<String, ReflectionUtils.MethodFilter> filterFactory = name -> method -> {
            var processedName = SNAKE_CASE_PATTERN.matcher(name).replaceAll("");
            return method.getName().equalsIgnoreCase(processedName);
        };
jvmlet commented 2 years ago

I'm aware about this ;-) , but what about this :

service MyGrpcService {
  rpc rpc_method_name(org.tobi...) returns (RpcResponse) {};
  rpc rpc_mEthod_nAme(org.tobi...) returns (RpcResponse) {};
}

?

tobq commented 2 years ago

@jvmlet ah, so the whole implementation needs to be reworked, because the original implementation simply does an ignoreCase comparison. Anyway, I don't have any cases like this so I will keep my hack in place until the package is patched, as it was completely blocking me

jvmlet commented 2 years ago

You are right... I'll implement your suggestion meanwhile since the original implementation suffers from this anyway. Let's hope grpc java team will provide solution in the nearest future.

jvmlet commented 2 years ago

@tobq , please try with 4.6.0-SNAPSHOT, I'll keep the issue open meanwhile. may be grpc team will provide the requested API

tobq commented 2 years ago

@jvmlet I get:

- Gradle Core Plugins (plugin is not in 'org.gradle' namespace)
- Plugin Repositories (could not resolve plugin artifact 'io.github.lognet.grpc-spring-boot:io.github.lognet.grpc-spring-boot.gradle.plugin:4.6.0-SNAPSHOT')
  Searched in the following repositories:
    maven(https://repo.spring.io/milestone)
    maven2(https://repo.spring.io/snapshot)
    Gradle Central Plugin Repository
jvmlet commented 2 years ago

Snapshot version of grpc spring boot gradle plugin is published to sonatype only. Gradle plugins repo doesn't support snapshots. Please add sonatype repo as source for gradle plugins.

jvmlet commented 2 years ago

https://oss.sonatype.org/#nexus-search;gav~io.github.lognet.grpc-spring-boot~io.github.lognet.grpc-spring-boot.gradle.plugin~~~~kw,versionexpand

tobq commented 2 years ago

@jvmlet I tried

settings.gradle

pluginManagement {
repositories {
maven {
url 'https://oss.sonatype.org/content/repositories/snapshots'
}
}
}

build.gradle

plugins {
id "io.github.lognet.grpc-spring-boot" version '4.6.0-SNAPSHOT'
}

which doesn't work