private static List<MethodDescriptor<?, ?>> stubMethods(Class<?> stubClass) { final Method getServiceDescriptorMethod; try { getServiceDescriptorMethod = stubClass.getDeclaredMethod("getServiceDescriptor"); } catch (NoSuchMethodException e) { throw new IllegalStateException("Could not find getServiceDescriptor on gRPC client stub."); } final ServiceDescriptor descriptor; try { descriptor = (ServiceDescriptor) getServiceDescriptorMethod.invoke(stubClass); } catch (IllegalAccessException | InvocationTargetException e) { throw new IllegalStateException("Could not invoke getServiceDescriptor on a gRPC client stub."); } return ImmutableList.copyOf(descriptor.getMethods()); }
@SuppressWarnings({"unchecked", "rawtypes"}) public static ServerServiceDefinition getServiceDefByAnnotation(Class<?> clazz) throws Exception { ServiceDescriptor serviceDesc = getServiceDesc(getGrpcClassName(clazz)); io.grpc.ServerServiceDefinition.Builder builder = io.grpc.ServerServiceDefinition.builder(serviceDesc); for (MethodDescriptor<?, ?> methodDesc : serviceDesc.getMethods()) { builder.addMethod(methodDesc, new MotanServerCallHandler()); } return builder.build(); }
@SuppressWarnings("rawtypes") public static HashMap<String, MethodDescriptor> getMethodDescriptorByAnnotation(Class<?> clazz, String serialization) throws Exception { String clazzName = getGrpcClassName(clazz); HashMap<String, MethodDescriptor> result = serviceMap.get(clazzName); if (result == null) { synchronized (serviceMap) { if (!serviceMap.containsKey(clazzName)) { ServiceDescriptor serviceDesc = getServiceDesc(getGrpcClassName(clazz)); HashMap<String, MethodDescriptor> methodMap = new HashMap<String, MethodDescriptor>(); for (MethodDescriptor<?, ?> methodDesc : serviceDesc.getMethods()) { Method interfaceMethod = getMethod(methodDesc.getFullMethodName(), clazz); if(JSON_CODEC.equals(serialization)){ methodDesc = convertJsonDescriptor(methodDesc, interfaceMethod.getParameterTypes()[0], interfaceMethod.getReturnType()); } methodMap.put(interfaceMethod.getName(), methodDesc); } serviceMap.put(clazzName, methodMap); } result = serviceMap.get(clazzName); } } return result; }
/** * Removes all access predicates for the all methods of the given service. After that, the default will be used for * those methods. * * @param service The service to protect with only the default. * @return This instance for chaining. * @see #setDefault(AccessPredicate) */ public ManualGrpcSecurityMetadataSource remove(final ServiceDescriptor service) { requireNonNull(service, "service"); for (final MethodDescriptor<?, ?> method : service.getMethods()) { this.accessMap.remove(method); } return this; }
/** * Pre-registers the all methods provided by the given service. This will initialize all default counters and timers * for those methods. * * @param service The service to initialize the meters for. * @see #preregisterMethod(MethodDescriptor) */ public void preregisterService(final ServiceDescriptor service) { for (final MethodDescriptor<?, ?> method : service.getMethods()) { preregisterMethod(method); } }
/** * Gets all method names from the given service descriptor. * * @param serviceDescriptor The service descriptor to get the names from. * @return The newly created and sorted list of the method names. */ protected List<String> collectMethodNamesForService(final ServiceDescriptor serviceDescriptor) { final List<String> methods = new ArrayList<>(); for (final MethodDescriptor<?, ?> grpcMethod : serviceDescriptor.getMethods()) { methods.add(extractMethodName(grpcMethod)); } methods.sort(String.CASE_INSENSITIVE_ORDER); return methods; }
/** * Set the given access predicate for the all methods of the given service. This will replace previously set * predicates. * * @param service The service to protect with a custom check. * @param predicate The predicate used to check the {@link Authentication}. * @return This instance for chaining. * @see #setDefault(AccessPredicate) */ public ManualGrpcSecurityMetadataSource set(final ServiceDescriptor service, final AccessPredicate predicate) { requireNonNull(service, "service"); final Collection<ConfigAttribute> wrappedPredicate = wrap(predicate); for (final MethodDescriptor<?, ?> method : service.getMethods()) { this.accessMap.put(method, wrappedPredicate); } return this; }
/** * Removes all access predicates for the all methods of the given service. After that, the default will be used for * those methods. * * @param service The service to protect with only the default. * @return This instance for chaining. * @see #setDefault(AccessPredicate) */ public ManualGrpcSecurityMetadataSource remove(final ServiceDescriptor service) { requireNonNull(service, "service"); for (final MethodDescriptor<?, ?> method : service.getMethods()) { this.accessMap.remove(method); } return this; }
/** * Pre-registers the all methods provided by the given service. This will initialize all default counters and timers * for those methods. * * @param service The service to initialize the meters for. * @see #preregisterMethod(MethodDescriptor) */ public void preregisterService(final ServiceDescriptor service) { for (final MethodDescriptor<?, ?> method : service.getMethods()) { preregisterMethod(method); } }
/** * Reads a list of {@link MethodDescriptor}s from a {@link ServiceDescriptor} and creates a list * of Open Census tags. * * @param descriptors a {@link} of Strings to add Open Census tags to * @param serviceDescriptor A {@link ServiceDescriptor} that contains a list of RPCs that are * provided by that service */ private static void addDescriptor(List<String> descriptors, ServiceDescriptor serviceDescriptor) { for (MethodDescriptor<?, ?> method : serviceDescriptor.getMethods()) { // This is added by Cloud Bigtable's AbstractRetryingOperation descriptors.add("Operation." + method.getFullMethodName().replace('/', '.')); } }
/** * Gets all method names from the given service descriptor. * * @param serviceDescriptor The service descriptor to get the names from. * @return The newly created and sorted list of the method names. */ protected List<String> collectMethodNamesForService(final ServiceDescriptor serviceDescriptor) { final List<String> methods = new ArrayList<>(); for (final MethodDescriptor<?, ?> grpcMethod : serviceDescriptor.getMethods()) { methods.add(extractMethodName(grpcMethod)); } methods.sort(String.CASE_INSENSITIVE_ORDER); return methods; }
private static List<MethodDescriptor<?, ?>> stubMethods(Class<?> stubClass) { final Method getServiceDescriptorMethod; try { getServiceDescriptorMethod = stubClass.getDeclaredMethod("getServiceDescriptor"); } catch (NoSuchMethodException e) { throw new IllegalStateException("Could not find getServiceDescriptor on gRPC client stub."); } final ServiceDescriptor descriptor; try { descriptor = (ServiceDescriptor) getServiceDescriptorMethod.invoke(stubClass); } catch (IllegalAccessException | InvocationTargetException e) { throw new IllegalStateException("Could not invoke getServiceDescriptor on a gRPC client stub."); } return ImmutableList.copyOf(descriptor.getMethods()); }
/** * Set the given access predicate for the all methods of the given service. This will replace previously set * predicates. * * @param service The service to protect with a custom check. * @param predicate The predicate used to check the {@link Authentication}. * @return This instance for chaining. * @see #setDefault(AccessPredicate) */ public ManualGrpcSecurityMetadataSource set(final ServiceDescriptor service, final AccessPredicate predicate) { requireNonNull(service, "service"); final Collection<ConfigAttribute> wrappedPredicate = wrap(predicate); for (final MethodDescriptor<?, ?> method : service.getMethods()) { this.accessMap.put(method, wrappedPredicate); } return this; }
for (MethodDescriptor<?, ?> descriptorMethod : serviceDescriptor.getMethods()) { ServerMethodDefinition<?, ?> removed = tmpMethods.remove( descriptorMethod.getFullMethodName());
for (MethodDescriptor<?, ?> descriptorMethod : serviceDescriptor.getMethods()) { ServerMethodDefinition<?, ?> removed = tmpMethods.remove( descriptorMethod.getFullMethodName());