当前位置: 首页>>代码示例>>Java>>正文


Java ServerCall.Listener方法代码示例

本文整理汇总了Java中io.grpc.ServerCall.Listener方法的典型用法代码示例。如果您正苦于以下问题:Java ServerCall.Listener方法的具体用法?Java ServerCall.Listener怎么用?Java ServerCall.Listener使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在io.grpc.ServerCall的用法示例。


在下文中一共展示了ServerCall.Listener方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: echoRequestHeadersInterceptor

import io.grpc.ServerCall; //导入方法依赖的package包/类
/**
 * Echo the request headers from a client into response headers and trailers. Useful for
 * testing end-to-end metadata propagation.
 */
private static ServerInterceptor echoRequestHeadersInterceptor(final Metadata.Key<?>... keys) {
  final Set<Metadata.Key<?>> keySet = new HashSet<Metadata.Key<?>>(Arrays.asList(keys));
  return new ServerInterceptor() {
    @Override
    public <ReqT, RespT> ServerCall.Listener<ReqT> interceptCall(
        ServerCall<ReqT, RespT> call,
        final Metadata requestHeaders,
        ServerCallHandler<ReqT, RespT> next) {
      return next.startCall(new SimpleForwardingServerCall<ReqT, RespT>(call) {
            @Override
            public void sendHeaders(Metadata responseHeaders) {
              responseHeaders.merge(requestHeaders, keySet);
              super.sendHeaders(responseHeaders);
            }

            @Override
            public void close(Status status, Metadata trailers) {
              trailers.merge(requestHeaders, keySet);
              super.close(status, trailers);
            }
          }, requestHeaders);
    }
  };
}
 
开发者ID:grpc,项目名称:grpc-java,代码行数:29,代码来源:TestServiceImpl.java

示例2: interceptCall

import io.grpc.ServerCall; //导入方法依赖的package包/类
@Override
public <ReqT, RespT> ServerCall.Listener<ReqT> interceptCall(
        ServerCall<ReqT, RespT> call,
        Metadata headers,
        ServerCallHandler<ReqT, RespT> next) {
    if (Objects.isNull(SecurityContextHolder.getContext().getAuthentication())) {
        SecurityContextHolder.getContext().setAuthentication(new AnonymousAuthenticationToken(key,
                "anonymousUser", Collections.singletonList(new SimpleGrantedAuthority("ROLE_ANONYMOUS"))));

        log.debug("Populated SecurityContextHolder with anonymous token: {}",
                SecurityContextHolder.getContext().getAuthentication());
    } else {
        log.debug("SecurityContextHolder not populated with anonymous token, as it already contained: {}",
                SecurityContextHolder.getContext().getAuthentication());
    }

    return next.startCall(call, headers);
}
 
开发者ID:revinate,项目名称:grpc-spring-security-demo,代码行数:19,代码来源:AnonymousAuthenticationInterceptor.java

示例3: cannotDisableAutoFlowControlAfterServiceInvocation

import io.grpc.ServerCall; //导入方法依赖的package包/类
@Test
public void cannotDisableAutoFlowControlAfterServiceInvocation() throws Exception {
  final AtomicReference<ServerCallStreamObserver<Integer>> callObserver =
      new AtomicReference<ServerCallStreamObserver<Integer>>();
  ServerCallHandler<Integer, Integer> callHandler =
      ServerCalls.asyncBidiStreamingCall(
          new ServerCalls.BidiStreamingMethod<Integer, Integer>() {
            @Override
            public StreamObserver<Integer> invoke(StreamObserver<Integer> responseObserver) {
              callObserver.set((ServerCallStreamObserver<Integer>) responseObserver);
              return new ServerCalls.NoopStreamObserver<Integer>();
            }
          });
  ServerCall.Listener<Integer> callListener =
      callHandler.startCall(serverCall, new Metadata());
  callListener.onMessage(1);
  try {
    callObserver.get().disableAutoInboundFlowControl();
    fail("Cannot set onCancel handler after service invocation");
  } catch (IllegalStateException expected) {
    // Expected
  }
}
 
开发者ID:grpc,项目名称:grpc-java,代码行数:24,代码来源:ServerCallsTest.java

示例4: clientSendsOne_errorMissingRequest_unary

import io.grpc.ServerCall; //导入方法依赖的package包/类
@Test
public void clientSendsOne_errorMissingRequest_unary() {
  ServerCallRecorder serverCall = new ServerCallRecorder(UNARY_METHOD);
  ServerCallHandler<Integer, Integer> callHandler =
      ServerCalls.asyncUnaryCall(
          new ServerCalls.UnaryMethod<Integer, Integer>() {
            @Override
            public void invoke(Integer req, StreamObserver<Integer> responseObserver) {
              fail("should not be reached");
            }
          });
  ServerCall.Listener<Integer> listener = callHandler.startCall(serverCall, new Metadata());
  listener.onHalfClose();
  assertThat(serverCall.responses).isEmpty();
  assertEquals(Status.Code.INTERNAL, serverCall.status.getCode());
  assertEquals(ServerCalls.MISSING_REQUEST, serverCall.status.getDescription());
}
 
开发者ID:grpc,项目名称:grpc-java,代码行数:18,代码来源:ServerCallsTest.java

示例5: clientSendsOne_errorMissingRequest_serverStreaming

import io.grpc.ServerCall; //导入方法依赖的package包/类
@Test
public void clientSendsOne_errorMissingRequest_serverStreaming() {
  ServerCallRecorder serverCall = new ServerCallRecorder(SERVER_STREAMING_METHOD);
  ServerCallHandler<Integer, Integer> callHandler =
      ServerCalls.asyncServerStreamingCall(
          new ServerCalls.ServerStreamingMethod<Integer, Integer>() {
            @Override
            public void invoke(Integer req, StreamObserver<Integer> responseObserver) {
              fail("should not be reached");
            }
          });
  ServerCall.Listener<Integer> listener = callHandler.startCall(serverCall, new Metadata());
  listener.onHalfClose();
  assertThat(serverCall.responses).isEmpty();
  assertEquals(Status.Code.INTERNAL, serverCall.status.getCode());
  assertEquals(ServerCalls.MISSING_REQUEST, serverCall.status.getDescription());

}
 
开发者ID:grpc,项目名称:grpc-java,代码行数:19,代码来源:ServerCallsTest.java

示例6: clientSendsOne_errorTooManyRequests_serverStreaming

import io.grpc.ServerCall; //导入方法依赖的package包/类
@Test
public void clientSendsOne_errorTooManyRequests_serverStreaming() {
  ServerCallRecorder serverCall = new ServerCallRecorder(SERVER_STREAMING_METHOD);
  ServerCallHandler<Integer, Integer> callHandler =
      ServerCalls.asyncServerStreamingCall(
          new ServerCalls.ServerStreamingMethod<Integer, Integer>() {
            @Override
            public void invoke(Integer req, StreamObserver<Integer> responseObserver) {
              fail("should not be reached");
            }
          });
  ServerCall.Listener<Integer> listener = callHandler.startCall(serverCall, new Metadata());
  listener.onMessage(1);
  listener.onMessage(1);
  assertThat(serverCall.responses).isEmpty();
  assertEquals(Status.Code.INTERNAL, serverCall.status.getCode());
  assertEquals(ServerCalls.TOO_MANY_REQUESTS, serverCall.status.getDescription());
  // ensure onHalfClose does not invoke
  listener.onHalfClose();
}
 
开发者ID:grpc,项目名称:grpc-java,代码行数:21,代码来源:ServerCallsTest.java

示例7: startCall

import io.grpc.ServerCall; //导入方法依赖的package包/类
/** Never returns {@code null}. */
private <ReqT, RespT> ServerStreamListener startCall(ServerStream stream, String fullMethodName,
    ServerMethodDefinition<ReqT, RespT> methodDef, Metadata headers,
    Context.CancellableContext context, StatsTraceContext statsTraceCtx) {
  // TODO(ejona86): should we update fullMethodName to have the canonical path of the method?
  ServerCallImpl<ReqT, RespT> call = new ServerCallImpl<ReqT, RespT>(
      stream, methodDef.getMethodDescriptor(), headers, context,
      decompressorRegistry, compressorRegistry);
  ServerCallHandler<ReqT, RespT> callHandler = methodDef.getServerCallHandler();
  statsTraceCtx.serverCallStarted(
      new ServerCallInfoImpl<ReqT, RespT>(
          methodDef.getMethodDescriptor(),
          call.getAttributes(),
          call.getAuthority()));

  for (ServerInterceptor interceptor : interceptors) {
    callHandler = InternalServerInterceptors.interceptCallHandler(interceptor, callHandler);
  }
  ServerCall.Listener<ReqT> listener = callHandler.startCall(call, headers);
  if (listener == null) {
    throw new NullPointerException(
        "startCall() returned a null listener for method " + fullMethodName);
  }
  return call.newServerStreamListener(listener);
}
 
开发者ID:grpc,项目名称:grpc-java,代码行数:26,代码来源:ServerImpl.java

示例8: clientSendsOne_errorTooManyRequests_unary

import io.grpc.ServerCall; //导入方法依赖的package包/类
@Test
public void clientSendsOne_errorTooManyRequests_unary() {
  ServerCallRecorder serverCall = new ServerCallRecorder(UNARY_METHOD);
  ServerCallHandler<Integer, Integer> callHandler =
      ServerCalls.asyncUnaryCall(
          new ServerCalls.UnaryMethod<Integer, Integer>() {
            @Override
            public void invoke(Integer req, StreamObserver<Integer> responseObserver) {
              fail("should not be reached");
            }
          });
  ServerCall.Listener<Integer> listener = callHandler.startCall(serverCall, new Metadata());
  listener.onMessage(1);
  listener.onMessage(1);
  assertThat(serverCall.responses).isEmpty();
  assertEquals(Status.Code.INTERNAL, serverCall.status.getCode());
  assertEquals(ServerCalls.TOO_MANY_REQUESTS, serverCall.status.getDescription());
  // ensure onHalfClose does not invoke
  listener.onHalfClose();
}
 
开发者ID:grpc,项目名称:grpc-java,代码行数:21,代码来源:ServerCallsTest.java

示例9: interceptCall

import io.grpc.ServerCall; //导入方法依赖的package包/类
@Override
public <ReqT, RespT> ServerCall.Listener<ReqT> interceptCall(
      ServerCall<ReqT, RespT> call,
      final Metadata requestHeaders,
      ServerCallHandler<ReqT, RespT> next) {
    String token = requestHeaders.get(authKey);
    String principal = null;
    if (StringUtils.isEmpty(token))
    {
        logger.warn("Failed to find token");
    }
    else
    {
        Map<String,String> tokenParams = new HashMap<>();
        tokenParams.put(OAuth2AccessToken.ACCESS_TOKEN,token);
        OAuth2AccessToken otoken = DefaultOAuth2AccessToken.valueOf(tokenParams);
        OAuth2Authentication auth = server.getTokenStore().readAuthentication(otoken);
        if (auth != null && auth.isAuthenticated())
        {
            logger.debug("Principal:"+auth.getPrincipal());
            principal = auth.getPrincipal().toString();
        }
        else
        {
            logger.warn("Failed to authenticate token "+token);
        }
    }
    return new MessagePrincipalListener<ReqT>(next.startCall(call, requestHeaders),principal,server);
  }
 
开发者ID:SeldonIO,项目名称:seldon-core,代码行数:30,代码来源:HeaderServerInterceptor.java

示例10: interceptCall

import io.grpc.ServerCall; //导入方法依赖的package包/类
@Override
public <ReqT, RespT> ServerCall.Listener<ReqT> interceptCall(
    MethodDescriptor<ReqT, RespT> method,
    ServerCall<RespT> call,
    final Metadata requestHeaders,
    ServerCallHandler<ReqT, RespT> next) {
  logger.info("header received from client:" + requestHeaders);
  return next.startCall(method, new SimpleForwardingServerCall<RespT>(call) {
    @Override
    public void sendHeaders(Metadata responseHeaders) {
      responseHeaders.put(customHeadKey, "customRespondValue");
      super.sendHeaders(responseHeaders);
    }
  }, requestHeaders);
}
 
开发者ID:lrtdc,项目名称:book_ldrtc,代码行数:16,代码来源:HeaderServerInterceptor.java

示例11: interceptCall

import io.grpc.ServerCall; //导入方法依赖的package包/类
@Override
public <ReqT, RespT> ServerCall.Listener<ReqT> interceptCall(ServerCall<ReqT, RespT> call, Metadata headers,
                                                             ServerCallHandler<ReqT, RespT> next) {
    System.out.println(call.getMethodDescriptor().getFullMethodName());
    log.info(call.getMethodDescriptor().getFullMethodName());
    return next.startCall(call, headers);
}
 
开发者ID:LogNet,项目名称:grpc-spring-boot-starter,代码行数:8,代码来源:LogInterceptor.java

示例12: interceptCall

import io.grpc.ServerCall; //导入方法依赖的package包/类
@Override
public <ReqT, RespT> ServerCall.Listener<ReqT> interceptCall(ServerCall<ReqT, RespT> call,
    final Metadata requestHeaders, ServerCallHandler<ReqT, RespT> next) {
  
  Context context = Context.current().withValue(MINI_DEVICE_INFO, requestHeaders.get(miniDeviceInfoKey));

  return Contexts.interceptCall(context, call, requestHeaders, next);
}
 
开发者ID:benson-git,项目名称:ibole-microservice,代码行数:9,代码来源:DeviceInfoGrpcServerInterceptor.java

示例13: interceptCall

import io.grpc.ServerCall; //导入方法依赖的package包/类
@Override
public <R, S> ServerCall.Listener<R> interceptCall(
    ServerCall<R, S> call,
    Metadata requestHeaders,
    ServerCallHandler<R, S> next) {
  MethodDescriptor<R, S> method = call.getMethodDescriptor();
  ServerMetrics metrics = serverMetricsFactory.createMetricsForMethod(method);
  GrpcMethod grpcMethod = GrpcMethod.of(method);
  ServerCall<R,S> monitoringCall = new MonitoringServerCall(call, clock, grpcMethod, metrics, configuration);
  return new MonitoringServerCallListener<>(
      next.startCall(monitoringCall, requestHeaders), metrics, GrpcMethod.of(method));
}
 
开发者ID:grpc-ecosystem,项目名称:java-grpc-prometheus,代码行数:13,代码来源:MonitoringServerInterceptor.java

示例14: startCall

import io.grpc.ServerCall; //导入方法依赖的package包/类
@Nullable
private <I, O> ArmeriaServerCall<I, O> startCall(
        String fullMethodName,
        ServerMethodDefinition<I, O> methodDef,
        ServiceRequestContext ctx,
        HttpHeaders headers,
        HttpResponseWriter res,
        SerializationFormat serializationFormat) {
    ArmeriaServerCall<I, O> call = new ArmeriaServerCall<>(
            headers,
            methodDef.getMethodDescriptor(),
            compressorRegistry,
            decompressorRegistry,
            res,
            maxInboundMessageSizeBytes,
            maxOutboundMessageSizeBytes,
            ctx,
            serializationFormat,
            jsonMarshaller);
    final ServerCall.Listener<I> listener;
    try (SafeCloseable ignored = RequestContext.push(ctx)) {
        listener = methodDef.getServerCallHandler().startCall(call, EMPTY_METADATA);
    } catch (Throwable t) {
        call.setListener(new EmptyListener<>());
        call.close(Status.fromThrowable(t), EMPTY_METADATA);
        logger.warn(
                "Exception thrown from streaming request stub method before processing any request data" +
                " - this is likely a bug in the stub implementation.");
        return null;
    }
    if (listener == null) {
        // This will never happen for normal generated stubs but could conceivably happen for manually
        // constructed ones.
        throw new NullPointerException(
                "startCall() returned a null listener for method " + fullMethodName);
    }
    call.setListener(listener);
    return call;
}
 
开发者ID:line,项目名称:armeria,代码行数:40,代码来源:GrpcService.java

示例15: interceptCall

import io.grpc.ServerCall; //导入方法依赖的package包/类
@Override
public <ReqT, RespT> ServerCall.Listener<ReqT> interceptCall(
    ServerCall<ReqT, RespT> call,
    Metadata headers,
    ServerCallHandler<ReqT, RespT> next) {
  RequestMetadata meta = headers.get(TracingMetadataUtils.METADATA_KEY);
  assertThat(meta.getCorrelatedInvocationsId()).isEqualTo("build-req-id");
  assertThat(meta.getToolInvocationId()).isEqualTo("command-id");
  assertThat(meta.getActionId()).isNotEmpty();
  assertThat(meta.getToolDetails().getToolName()).isEqualTo("bazel");
  assertThat(meta.getToolDetails().getToolVersion())
      .isEqualTo(BlazeVersionInfo.instance().getVersion());
  return next.startCall(call, headers);
}
 
开发者ID:bazelbuild,项目名称:bazel,代码行数:15,代码来源:GrpcRemoteExecutionClientTest.java


注:本文中的io.grpc.ServerCall.Listener方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。