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


Java ClientInterceptors.intercept方法代码示例

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


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

示例1: SeldonClientExample

import io.grpc.ClientInterceptors; //导入方法依赖的package包/类
/** Construct client for accessing RouteGuide server using the existing channel. */
public SeldonClientExample(ManagedChannelBuilder<?> channelBuilder) {
 ClientInterceptor interceptor = new HeaderClientInterceptor();
  channel = channelBuilder.build();
  Channel interceptChannel = ClientInterceptors.intercept(channel, interceptor);
  blockingStub = SeldonGrpc.newBlockingStub(interceptChannel);
  asyncStub = SeldonGrpc.newStub(interceptChannel);
}
 
开发者ID:SeldonIO,项目名称:seldon-core,代码行数:9,代码来源:SeldonClientExample.java

示例2: initServerConnection

import io.grpc.ClientInterceptors; //导入方法依赖的package包/类
/**
 * Initializes a connection to the gRPC server.
 * @return a boolean indicating the success.
 */
private boolean initServerConnection() {
    if(!mConnected) {
        mInterceptor = new AuthHeaderClientInterceptor(
                getUserIdToken());
        try {
            mChannelImpl = OkHttpChannelBuilder
                    .forAddress(AndroidConstants.HOST,
                            AndroidConstants.PORT)
                    .build();
            Channel mOriginChannel = ClientInterceptors
                    .intercept(mChannelImpl, mInterceptor);
            mBlockingStub = AbelanaGrpc.newBlockingStub(mOriginChannel);
            mConnected = true;
        } catch (RuntimeException e) {
            mConnected = false;
        }
    }
    return mConnected;
}
 
开发者ID:googlearchive,项目名称:abelana,代码行数:24,代码来源:AbelanaClient.java

示例3: setUp

import io.grpc.ClientInterceptors; //导入方法依赖的package包/类
@Before
public void setUp() throws Exception {
  faker = new Faker();
  Injector injector = Guice.createInjector();
  EchoService echoService = injector.getInstance(EchoService.class);
  ServiceInterceptor serviceInterceptor = injector.getInstance(ServiceInterceptor.class);
  CallerInterceptor callerInterceptor = injector.getInstance(CallerInterceptor.class);

  grpcServerRule.getServiceRegistry().addService(ServerInterceptors.intercept(echoService, serviceInterceptor));
  Channel channel = ClientInterceptors.intercept(
      grpcServerRule.getChannel(),
      callerInterceptor);
  stub = EchoServiceGrpc.newBlockingStub(channel);
}
 
开发者ID:email2liyang,项目名称:grpc-mate,代码行数:15,代码来源:EchoServiceTest.java

示例4: CustomHeaderClient

import io.grpc.ClientInterceptors; //导入方法依赖的package包/类
/**
 * A custom client.
 */
private CustomHeaderClient(String host, int port) {
  originChannel = ManagedChannelBuilder.forAddress(host, port)
      .usePlaintext(true)
      .build();
  ClientInterceptor interceptor = new HeaderClientInterceptor();
  Channel channel = ClientInterceptors.intercept(originChannel, interceptor);
  blockingStub = GreeterGrpc.newBlockingStub(channel);
}
 
开发者ID:lrtdc,项目名称:book_ldrtc,代码行数:12,代码来源:CustomHeaderClient.java

示例5: getChannel

import io.grpc.ClientInterceptors; //导入方法依赖的package包/类
/** Return {@link io.grpc.Channel} which is used by Cloud Pub/Sub gRPC API's. */
public static Channel getChannel() throws IOException {
  ManagedChannel channelImpl =
      NettyChannelBuilder.forAddress(ENDPOINT, 443).negotiationType(NegotiationType.TLS).build();
  final ClientAuthInterceptor interceptor =
      new ClientAuthInterceptor(
          GoogleCredentials.getApplicationDefault().createScoped(CPS_SCOPE),
          Executors.newCachedThreadPool());
  return ClientInterceptors.intercept(channelImpl, interceptor);
}
 
开发者ID:GoogleCloudPlatform,项目名称:pubsub,代码行数:11,代码来源:ConnectorUtils.java

示例6: HelloWorldClient

import io.grpc.ClientInterceptors; //导入方法依赖的package包/类
/** Construct client connecting to HelloWorld server at {@code host:port}. */
public HelloWorldClient(String address, String apiKey) {
  channel = ManagedChannelBuilder.forTarget(address)
      // Channels are secure by default (via SSL/TLS). For the example we disable TLS to avoid
      // needing certificates.
      .usePlaintext(true)
      .build();
  Channel ch = ClientInterceptors.intercept(channel,  new Interceptor(apiKey));

  blockingStub = GreeterGrpc.newBlockingStub(ch);
}
 
开发者ID:GoogleCloudPlatform,项目名称:java-docs-samples,代码行数:12,代码来源:HelloWorldClient.java

示例7: createBookstoreStub

import io.grpc.ClientInterceptors; //导入方法依赖的package包/类
static BookstoreGrpc.BookstoreBlockingStub createBookstoreStub(
    String address, String apiKey, String authToken) {
  Channel channel = ManagedChannelBuilder.forTarget(address)
      .usePlaintext(true)
      .build();

  channel = ClientInterceptors.intercept(channel,  new Interceptor(apiKey, authToken));

  return BookstoreGrpc.newBlockingStub(channel);
}
 
开发者ID:GoogleCloudPlatform,项目名称:java-docs-samples,代码行数:11,代码来源:BookstoreClient.java

示例8: main

import io.grpc.ClientInterceptors; //导入方法依赖的package包/类
public static void main(final String[] args) throws Exception {

        if (args.length == 0) {
            System.err.println("Please specify your project name.");
            System.exit(1);
        }
        final String project = args[0];
        ManagedChannelImpl channelImpl = NettyChannelBuilder
            .forAddress("pubsub.googleapis.com", 443)
            .negotiationType(NegotiationType.TLS)
            .build();
        GoogleCredentials creds = GoogleCredentials.getApplicationDefault();
        // Down-scope the credential to just the scopes required by the service
        creds = creds.createScoped(Arrays.asList("https://www.googleapis.com/auth/pubsub"));
        // Intercept the channel to bind the credential
        ExecutorService executor = Executors.newSingleThreadExecutor();
        ClientAuthInterceptor interceptor = new ClientAuthInterceptor(creds, executor);
        Channel channel = ClientInterceptors.intercept(channelImpl, interceptor);
        // Create a stub using the channel that has the bound credential
        PublisherGrpc.PublisherBlockingStub publisherStub = PublisherGrpc.newBlockingStub(channel);
        ListTopicsRequest request = ListTopicsRequest.newBuilder()
                .setPageSize(10)
                .setProject("projects/" + project)
                .build();
        ListTopicsResponse resp = publisherStub.listTopics(request);
        System.out.println("Found " + resp.getTopicsCount() + " topics.");
        for (Topic topic : resp.getTopicsList()) {
            System.out.println(topic.getName());
        }
    }
 
开发者ID:GoogleCloudPlatform,项目名称:cloud-pubsub-samples-java,代码行数:31,代码来源:Main.java

示例9: newClient

import io.grpc.ClientInterceptors; //导入方法依赖的package包/类
private GrpcRemoteCache newClient() throws IOException {
  AuthAndTLSOptions authTlsOptions = Options.getDefaults(AuthAndTLSOptions.class);
  authTlsOptions.useGoogleDefaultCredentials = true;
  authTlsOptions.googleCredentials = "/exec/root/creds.json";
  authTlsOptions.googleAuthScopes = ImmutableList.of("dummy.scope");

  GenericJson json = new GenericJson();
  json.put("type", "authorized_user");
  json.put("client_id", "some_client");
  json.put("client_secret", "foo");
  json.put("refresh_token", "bar");
  Scratch scratch = new Scratch();
  scratch.file(authTlsOptions.googleCredentials, new JacksonFactory().toString(json));

  CallCredentials creds =
      GoogleAuthUtils.newCallCredentials(
          scratch.resolve(authTlsOptions.googleCredentials).getInputStream(),
          authTlsOptions.googleAuthScopes);
  RemoteOptions remoteOptions = Options.getDefaults(RemoteOptions.class);
  RemoteRetrier retrier =
      new RemoteRetrier(
          remoteOptions, RemoteRetrier.RETRIABLE_GRPC_ERRORS, Retrier.ALLOW_ALL_CALLS);
  return new GrpcRemoteCache(
      ClientInterceptors.intercept(
          InProcessChannelBuilder.forName(fakeServerName).directExecutor().build(),
          ImmutableList.of(new CallCredentialsInterceptor(creds))),
      creds,
      remoteOptions,
      retrier,
      DIGEST_UTIL);
}
 
开发者ID:bazelbuild,项目名称:bazel,代码行数:32,代码来源:GrpcRemoteCacheTest.java

示例10: setUp

import io.grpc.ClientInterceptors; //导入方法依赖的package包/类
@Before
public void setUp() throws Exception {
  grpcServerRule
      .getServiceRegistry()
      .addService(
          ServerInterceptors.intercept(greeterServiceImpl, injectCacheControlInterceptor));
  grpcServerRule.getServiceRegistry().addService(anotherGreeterServiceImpl);
  baseChannel = grpcServerRule.getChannel();

  SafeMethodCachingInterceptor interceptor =
      SafeMethodCachingInterceptor.newSafeMethodCachingInterceptor(cache);

  channelToUse = ClientInterceptors.intercept(baseChannel, interceptor);
}
 
开发者ID:grpc,项目名称:grpc-java,代码行数:15,代码来源:SafeMethodCachingInterceptorTest.java

示例11: invalidResponseMaxAge_usesDefault

import io.grpc.ClientInterceptors; //导入方法依赖的package包/类
@Test
public void invalidResponseMaxAge_usesDefault() throws Exception {
  SafeMethodCachingInterceptor interceptorWithCustomMaxAge =
      SafeMethodCachingInterceptor.newSafeMethodCachingInterceptor(cache, 1);
  channelToUse = ClientInterceptors.intercept(baseChannel, interceptorWithCustomMaxAge);
  cacheControlDirectives.add("max-age=-10");

  HelloReply reply1 =
      ClientCalls.blockingUnaryCall(
          channelToUse, safeGreeterSayHelloMethod, CallOptions.DEFAULT, message);
  HelloReply reply2 =
      ClientCalls.blockingUnaryCall(
          channelToUse, safeGreeterSayHelloMethod, CallOptions.DEFAULT, message);
  assertEquals(reply1, reply2);

  // Wait for cache entry to expire
  sleepAtLeast(1001);

  assertNotEquals(
      reply1,
      ClientCalls.blockingUnaryCall(
          channelToUse, safeGreeterSayHelloMethod, CallOptions.DEFAULT, message));
  Truth.assertThat(cache.removedKeys).hasSize(1);
  assertEquals(
      new SafeMethodCachingInterceptor.Key(
          GreeterGrpc.getSayHelloMethod().getFullMethodName(), message),
      cache.removedKeys.get(0));
}
 
开发者ID:grpc,项目名称:grpc-java,代码行数:29,代码来源:SafeMethodCachingInterceptorTest.java

示例12: afterDefaultMaxAge_cacheEntryInvalidated

import io.grpc.ClientInterceptors; //导入方法依赖的package包/类
@Test
public void afterDefaultMaxAge_cacheEntryInvalidated() throws Exception {
  SafeMethodCachingInterceptor interceptorWithCustomMaxAge =
      SafeMethodCachingInterceptor.newSafeMethodCachingInterceptor(cache, 1);
  channelToUse = ClientInterceptors.intercept(baseChannel, interceptorWithCustomMaxAge);

  HelloReply reply1 =
      ClientCalls.blockingUnaryCall(
          channelToUse, safeGreeterSayHelloMethod, CallOptions.DEFAULT, message);
  HelloReply reply2 =
      ClientCalls.blockingUnaryCall(
          channelToUse, safeGreeterSayHelloMethod, CallOptions.DEFAULT, message);
  assertSame(reply1, reply2);

  // Wait for cache entry to expire
  sleepAtLeast(1001);

  assertNotEquals(
      reply1,
      ClientCalls.blockingUnaryCall(
          channelToUse, safeGreeterSayHelloMethod, CallOptions.DEFAULT, message));
  Truth.assertThat(cache.removedKeys).hasSize(1);
  assertEquals(
      new SafeMethodCachingInterceptor.Key(
          GreeterGrpc.getSayHelloMethod().getFullMethodName(), message),
      cache.removedKeys.get(0));
}
 
开发者ID:grpc,项目名称:grpc-java,代码行数:28,代码来源:SafeMethodCachingInterceptorTest.java

示例13: InteropTester

import io.grpc.ClientInterceptors; //导入方法依赖的package包/类
public InteropTester(String testCase,
                     ManagedChannel channel,
                     TestListener listener,
                     boolean useGet) {
  this.testCase = testCase;
  this.listener = listener;
  this.channel = channel;
  Channel channelToUse = channel;
  if (useGet) {
    channelToUse = ClientInterceptors.intercept(channel, new SafeMethodChannelInterceptor());
  }
  blockingStub = TestServiceGrpc.newBlockingStub(channelToUse);
  asyncStub = TestServiceGrpc.newStub(channelToUse);
}
 
开发者ID:grpc,项目名称:grpc-java,代码行数:15,代码来源:InteropTester.java

示例14: cacheableUnary

import io.grpc.ClientInterceptors; //导入方法依赖的package包/类
/** Sends a cacheable unary rpc using GET. Requires that the server is behind a caching proxy. */
public void cacheableUnary() {
  // Set safe to true.
  MethodDescriptor<SimpleRequest, SimpleResponse> safeCacheableUnaryCallMethod =
      TestServiceGrpc.getCacheableUnaryCallMethod().toBuilder().setSafe(true).build();
  // Set fake user IP since some proxies (GFE) won't cache requests from localhost.
  Metadata.Key<String> userIpKey = Metadata.Key.of("x-user-ip", Metadata.ASCII_STRING_MARSHALLER);
  Metadata metadata = new Metadata();
  metadata.put(userIpKey, "1.2.3.4");
  Channel channelWithUserIpKey =
      ClientInterceptors.intercept(channel, MetadataUtils.newAttachHeadersInterceptor(metadata));
  SimpleRequest requests1And2 =
      SimpleRequest.newBuilder()
          .setPayload(
              Payload.newBuilder()
                  .setBody(ByteString.copyFromUtf8(String.valueOf(System.nanoTime()))))
          .build();
  SimpleRequest request3 =
      SimpleRequest.newBuilder()
          .setPayload(
              Payload.newBuilder()
                  .setBody(ByteString.copyFromUtf8(String.valueOf(System.nanoTime()))))
          .build();

  SimpleResponse response1 =
      ClientCalls.blockingUnaryCall(
          channelWithUserIpKey, safeCacheableUnaryCallMethod, CallOptions.DEFAULT, requests1And2);
  SimpleResponse response2 =
      ClientCalls.blockingUnaryCall(
          channelWithUserIpKey, safeCacheableUnaryCallMethod, CallOptions.DEFAULT, requests1And2);
  SimpleResponse response3 =
      ClientCalls.blockingUnaryCall(
          channelWithUserIpKey, safeCacheableUnaryCallMethod, CallOptions.DEFAULT, request3);

  assertEquals(response1, response2);
  assertNotEquals(response1, response3);
}
 
开发者ID:grpc,项目名称:grpc-java,代码行数:38,代码来源:AbstractInteropTest.java

示例15: createChannelWithCredentials

import io.grpc.ClientInterceptors; //导入方法依赖的package包/类
public Channel createChannelWithCredentials(HostAndPort endpoint, Credentials credentials) {
  return ClientInterceptors.intercept(
      createChannel(endpoint), new ClientAuthInterceptor(credentials, authExecutor));
}
 
开发者ID:grpc-ecosystem,项目名称:polyglot,代码行数:5,代码来源:ChannelFactory.java


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