Java Code Examples for io.grpc.reflection.v1alpha.ExtensionNumberResponse

The following examples show how to use io.grpc.reflection.v1alpha.ExtensionNumberResponse. These examples are extracted from open source projects. 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 Project: grpc-nebula-java   Source File: ProtoReflectionService.java    License: Apache License 2.0 6 votes vote down vote up
private void getAllExtensions(ServerReflectionRequest request) {
  String type = request.getAllExtensionNumbersOfType();
  Set<Integer> extensions = serverReflectionIndex.getExtensionNumbersOfType(type);
  if (extensions != null) {
    ExtensionNumberResponse.Builder builder =
        ExtensionNumberResponse.newBuilder()
            .setBaseTypeName(type)
            .addAllExtensionNumber(extensions);
    serverCallStreamObserver.onNext(
        ServerReflectionResponse.newBuilder()
            .setValidHost(request.getHost())
            .setOriginalRequest(request)
            .setAllExtensionNumbersResponse(builder)
            .build());
  } else {
    sendErrorResponse(request, Status.Code.NOT_FOUND, "Type not found.");
  }
}
 
Example 2
Source Project: quarkus   Source File: ReflectionService.java    License: Apache License 2.0 6 votes vote down vote up
private ServerReflectionResponse getAllExtensions(ServerReflectionRequest request) {
    String type = request.getAllExtensionNumbersOfType();
    Set<Integer> extensions = index.getExtensionNumbersOfType(type);
    if (extensions != null) {
        ExtensionNumberResponse.Builder builder = ExtensionNumberResponse.newBuilder()
                .setBaseTypeName(type)
                .addAllExtensionNumber(extensions);
        return ServerReflectionResponse.newBuilder()
                .setValidHost(request.getHost())
                .setOriginalRequest(request)
                .setAllExtensionNumbersResponse(builder)
                .build();
    } else {
        return getErrorResponse(request, Status.Code.NOT_FOUND, "Type not found.");
    }
}
 
Example 3
Source Project: grpc-java   Source File: ProtoReflectionService.java    License: Apache License 2.0 6 votes vote down vote up
private void getAllExtensions(ServerReflectionRequest request) {
  String type = request.getAllExtensionNumbersOfType();
  Set<Integer> extensions = serverReflectionIndex.getExtensionNumbersOfType(type);
  if (extensions != null) {
    ExtensionNumberResponse.Builder builder =
        ExtensionNumberResponse.newBuilder()
            .setBaseTypeName(type)
            .addAllExtensionNumber(extensions);
    serverCallStreamObserver.onNext(
        ServerReflectionResponse.newBuilder()
            .setValidHost(request.getHost())
            .setOriginalRequest(request)
            .setAllExtensionNumbersResponse(builder)
            .build());
  } else {
    sendErrorResponse(request, Status.Code.NOT_FOUND, "Type not found.");
  }
}
 
Example 4
@Test
public void allExtensionNumbersOfTypeForMutableServices() throws Exception {
  String type = "grpc.reflection.testing.TypeWithExtensions";
  ServerReflectionRequest request =
      ServerReflectionRequest.newBuilder()
          .setHost(TEST_HOST)
          .setAllExtensionNumbersOfType(type)
          .build();
  ServerReflectionResponse goldenResponse =
      ServerReflectionResponse.newBuilder()
          .setValidHost(TEST_HOST)
          .setOriginalRequest(request)
          .setAllExtensionNumbersResponse(
              ExtensionNumberResponse.newBuilder()
                  .setBaseTypeName(type)
                  .addExtensionNumber(200)
                  .build())
          .build();

  StreamRecorder<ServerReflectionResponse> responseObserver = StreamRecorder.create();
  StreamObserver<ServerReflectionRequest> requestObserver =
      stub.serverReflectionInfo(responseObserver);
  handlerRegistry.addService(dynamicService);
  requestObserver.onNext(request);
  requestObserver.onCompleted();
  StreamRecorder<ServerReflectionResponse> responseObserver2 = StreamRecorder.create();
  StreamObserver<ServerReflectionRequest> requestObserver2 =
      stub.serverReflectionInfo(responseObserver2);
  handlerRegistry.removeService(dynamicService);
  requestObserver2.onNext(request);
  requestObserver2.onCompleted();
  StreamRecorder<ServerReflectionResponse> responseObserver3 = StreamRecorder.create();
  StreamObserver<ServerReflectionRequest> requestObserver3 =
      stub.serverReflectionInfo(responseObserver3);
  requestObserver3.onNext(request);
  requestObserver3.onCompleted();

  assertEquals(
      ServerReflectionResponse.MessageResponseCase.ERROR_RESPONSE,
      responseObserver.firstValue().get().getMessageResponseCase());
  assertEquals(goldenResponse, responseObserver2.firstValue().get());
  assertEquals(
      ServerReflectionResponse.MessageResponseCase.ERROR_RESPONSE,
      responseObserver3.firstValue().get().getMessageResponseCase());
}
 
Example 5
Source Project: grpc-java   Source File: ProtoReflectionServiceTest.java    License: Apache License 2.0 4 votes vote down vote up
@Test
public void allExtensionNumbersOfTypeForMutableServices() throws Exception {
  String type = "grpc.reflection.testing.TypeWithExtensions";
  ServerReflectionRequest request =
      ServerReflectionRequest.newBuilder()
          .setHost(TEST_HOST)
          .setAllExtensionNumbersOfType(type)
          .build();
  ServerReflectionResponse goldenResponse =
      ServerReflectionResponse.newBuilder()
          .setValidHost(TEST_HOST)
          .setOriginalRequest(request)
          .setAllExtensionNumbersResponse(
              ExtensionNumberResponse.newBuilder()
                  .setBaseTypeName(type)
                  .addExtensionNumber(200)
                  .build())
          .build();

  StreamRecorder<ServerReflectionResponse> responseObserver = StreamRecorder.create();
  StreamObserver<ServerReflectionRequest> requestObserver =
      stub.serverReflectionInfo(responseObserver);
  handlerRegistry.addService(dynamicService);
  requestObserver.onNext(request);
  requestObserver.onCompleted();
  StreamRecorder<ServerReflectionResponse> responseObserver2 = StreamRecorder.create();
  StreamObserver<ServerReflectionRequest> requestObserver2 =
      stub.serverReflectionInfo(responseObserver2);
  handlerRegistry.removeService(dynamicService);
  requestObserver2.onNext(request);
  requestObserver2.onCompleted();
  StreamRecorder<ServerReflectionResponse> responseObserver3 = StreamRecorder.create();
  StreamObserver<ServerReflectionRequest> requestObserver3 =
      stub.serverReflectionInfo(responseObserver3);
  requestObserver3.onNext(request);
  requestObserver3.onCompleted();

  assertEquals(
      ServerReflectionResponse.MessageResponseCase.ERROR_RESPONSE,
      responseObserver.firstValue().get().getMessageResponseCase());
  assertEquals(goldenResponse, responseObserver2.firstValue().get());
  assertEquals(
      ServerReflectionResponse.MessageResponseCase.ERROR_RESPONSE,
      responseObserver3.firstValue().get().getMessageResponseCase());
}