Java Code Examples for com.google.protobuf.Descriptors.ServiceDescriptor#findMethodByName()

The following examples show how to use com.google.protobuf.Descriptors.ServiceDescriptor#findMethodByName() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ServiceResolver.java    From grpc-swagger with MIT License 5 votes vote down vote up
/**
 * Returns the descriptor of a protobuf method with the supplied grpc method name. If the method
 * cannot be found, this throws {@link IllegalArgumentException}.
 */
public MethodDescriptor resolveServiceMethod(GrpcMethodDefinition definition) {

    ServiceDescriptor service = findService(definition.getPackageName(), definition.getServiceName());
    MethodDescriptor method = service.findMethodByName(definition.getMethodName());
    if (method == null) {
        throw new IllegalArgumentException(
                "Unable to find method " + definition.getMethodName()
                        + " in service " + definition.getServiceName());
    }
    return method;
}
 
Example 2
Source File: ServiceResolver.java    From milkman with MIT License 5 votes vote down vote up
private MethodDescriptor resolveServiceMethod(
    String serviceName, String methodName, String packageName) {
  ServiceDescriptor service = findService(serviceName, packageName);
  MethodDescriptor method = service.findMethodByName(methodName);
  if (method == null) {
    throw new IllegalArgumentException(
        "Unable to find method " + methodName + " in service " + serviceName);
  }
  return method;
}
 
Example 3
Source File: ServiceResolver.java    From grpc-swagger with MIT License 5 votes vote down vote up
/**
 * Returns the descriptor of a protobuf method with the supplied grpc method name. If the method
 * cannot be found, this throws {@link IllegalArgumentException}.
 */
public MethodDescriptor resolveServiceMethod(GrpcMethodDefinition definition) {

    ServiceDescriptor service = findService(definition.getPackageName(), definition.getServiceName());
    MethodDescriptor method = service.findMethodByName(definition.getMethodName());
    if (method == null) {
        throw new IllegalArgumentException(
                "Unable to find method " + definition.getMethodName()
                        + " in service " + definition.getServiceName());
    }
    return method;
}
 
Example 4
Source File: RpcForwarder.java    From protobuf-socket-rpc with MIT License 5 votes vote down vote up
/**
 * Get matching method.
 */
private MethodDescriptor getMethod(SocketRpcProtos.Request rpcRequest,
    ServiceDescriptor descriptor) throws RpcException {
  MethodDescriptor method = descriptor.findMethodByName(
      rpcRequest.getMethodName());
  if (method == null) {
    throw new RpcException(
        ErrorReason.METHOD_NOT_FOUND,
        String.format("Could not find method %s in service %s",
            rpcRequest.getMethodName(), descriptor.getFullName()),
        null);
  }
  return method;
}
 
Example 5
Source File: DescriptorsTest.java    From travelguide with Apache License 2.0 4 votes vote down vote up
public void testCustomOptions() throws Exception {
  Descriptor descriptor =
    UnittestCustomOptions.TestMessageWithCustomOptions.getDescriptor();

  assertTrue(
    descriptor.getOptions().hasExtension(UnittestCustomOptions.messageOpt1));
  assertEquals(Integer.valueOf(-56),
    descriptor.getOptions().getExtension(UnittestCustomOptions.messageOpt1));

  FieldDescriptor field = descriptor.findFieldByName("field1");
  assertNotNull(field);

  assertTrue(
    field.getOptions().hasExtension(UnittestCustomOptions.fieldOpt1));
  assertEquals(Long.valueOf(8765432109L),
    field.getOptions().getExtension(UnittestCustomOptions.fieldOpt1));

  EnumDescriptor enumType =
    UnittestCustomOptions.TestMessageWithCustomOptions.AnEnum.getDescriptor();

  assertTrue(
    enumType.getOptions().hasExtension(UnittestCustomOptions.enumOpt1));
  assertEquals(Integer.valueOf(-789),
    enumType.getOptions().getExtension(UnittestCustomOptions.enumOpt1));

  ServiceDescriptor service =
    UnittestCustomOptions.TestServiceWithCustomOptions.getDescriptor();

  assertTrue(
    service.getOptions().hasExtension(UnittestCustomOptions.serviceOpt1));
  assertEquals(Long.valueOf(-9876543210L),
    service.getOptions().getExtension(UnittestCustomOptions.serviceOpt1));

  MethodDescriptor method = service.findMethodByName("Foo");
  assertNotNull(method);

  assertTrue(
    method.getOptions().hasExtension(UnittestCustomOptions.methodOpt1));
  assertEquals(UnittestCustomOptions.MethodOpt1.METHODOPT1_VAL2,
    method.getOptions().getExtension(UnittestCustomOptions.methodOpt1));
}