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


Java Metadata.getAll方法代码示例

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


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

示例1: testCopyCredentialToHeaders

import io.grpc.Metadata; //导入方法依赖的package包/类
@Test
public void testCopyCredentialToHeaders() throws IOException {
  ListMultimap<String, String> values = LinkedListMultimap.create();
  values.put("Authorization", "token1");
  values.put("Authorization", "token2");
  values.put("Extra-Authorization", "token3");
  values.put("Extra-Authorization", "token4");
  when(credentials.getRequestMetadata(any(URI.class))).thenReturn(Multimaps.asMap(values));
  ClientCall<String, Integer> interceptedCall =
      interceptor.interceptCall(descriptor, CallOptions.DEFAULT, channel);
  Metadata headers = new Metadata();
  interceptedCall.start(listener, headers);
  assertEquals(listener, call.responseListener);
  assertEquals(headers, call.headers);

  Iterable<String> authorization = headers.getAll(AUTHORIZATION);
  Assert.assertArrayEquals(new String[]{"token1", "token2"},
      Iterables.toArray(authorization, String.class));
  Iterable<String> extraAuthorization = headers.getAll(EXTRA_AUTHORIZATION);
  Assert.assertArrayEquals(new String[]{"token3", "token4"},
      Iterables.toArray(extraAuthorization, String.class));
}
 
开发者ID:grpc,项目名称:grpc-java,代码行数:23,代码来源:ClientAuthInterceptorTest.java

示例2: testWithOAuth2Credential

import io.grpc.Metadata; //导入方法依赖的package包/类
@Test
public void testWithOAuth2Credential() {
  final AccessToken token = new AccessToken("allyourbase", new Date(Long.MAX_VALUE));
  final OAuth2Credentials oAuth2Credentials = new OAuth2Credentials() {
    @Override
    public AccessToken refreshAccessToken() throws IOException {
      return token;
    }
  };
  interceptor = new ClientAuthInterceptor(oAuth2Credentials, executor);
  ClientCall<String, Integer> interceptedCall =
      interceptor.interceptCall(descriptor, CallOptions.DEFAULT, channel);
  Metadata headers = new Metadata();
  interceptedCall.start(listener, headers);
  assertEquals(listener, call.responseListener);
  assertEquals(headers, call.headers);
  Iterable<String> authorization = headers.getAll(AUTHORIZATION);
  Assert.assertArrayEquals(new String[]{"Bearer allyourbase"},
      Iterables.toArray(authorization, String.class));
}
 
开发者ID:grpc,项目名称:grpc-java,代码行数:21,代码来源:ClientAuthInterceptorTest.java

示例3: copyCredentialsToHeaders

import io.grpc.Metadata; //导入方法依赖的package包/类
@Test
public void copyCredentialsToHeaders() throws Exception {
  ListMultimap<String, String> values = LinkedListMultimap.create();
  values.put("Authorization", "token1");
  values.put("Authorization", "token2");
  values.put("Extra-Authorization-bin", "dG9rZW4z");  // bytes "token3" in base64
  values.put("Extra-Authorization-bin", "dG9rZW40");  // bytes "token4" in base64
  when(credentials.getRequestMetadata(eq(expectedUri))).thenReturn(Multimaps.asMap(values));

  GoogleAuthLibraryCallCredentials callCredentials =
      new GoogleAuthLibraryCallCredentials(credentials);
  callCredentials.applyRequestMetadata(method, attrs, executor, applier);

  verify(credentials).getRequestMetadata(eq(expectedUri));
  verify(applier).apply(headersCaptor.capture());
  Metadata headers = headersCaptor.getValue();
  Iterable<String> authorization = headers.getAll(AUTHORIZATION);
  assertArrayEquals(new String[]{"token1", "token2"},
      Iterables.toArray(authorization, String.class));
  Iterable<byte[]> extraAuthorization = headers.getAll(EXTRA_AUTHORIZATION);
  assertEquals(2, Iterables.size(extraAuthorization));
  assertArrayEquals("token3".getBytes(US_ASCII), Iterables.get(extraAuthorization, 0));
  assertArrayEquals("token4".getBytes(US_ASCII), Iterables.get(extraAuthorization, 1));
}
 
开发者ID:grpc,项目名称:grpc-java,代码行数:25,代码来源:GoogleAuthLibraryCallCredentialsTest.java

示例4: oauth2Credential

import io.grpc.Metadata; //导入方法依赖的package包/类
@Test
public void oauth2Credential() {
  final AccessToken token = new AccessToken("allyourbase", new Date(Long.MAX_VALUE));
  final OAuth2Credentials credentials = new OAuth2Credentials() {
    @Override
    public AccessToken refreshAccessToken() throws IOException {
      return token;
    }
  };

  GoogleAuthLibraryCallCredentials callCredentials =
      new GoogleAuthLibraryCallCredentials(credentials);
  callCredentials.applyRequestMetadata(method, attrs, executor, applier);
  assertEquals(1, runPendingRunnables());

  verify(applier).apply(headersCaptor.capture());
  Metadata headers = headersCaptor.getValue();
  Iterable<String> authorization = headers.getAll(AUTHORIZATION);
  assertArrayEquals(new String[]{"Bearer allyourbase"},
      Iterables.toArray(authorization, String.class));
}
 
开发者ID:grpc,项目名称:grpc-java,代码行数:22,代码来源:GoogleAuthLibraryCallCredentialsTest.java

示例5: serviceAccountWithScopeNotToJwt

import io.grpc.Metadata; //导入方法依赖的package包/类
@Test
public void serviceAccountWithScopeNotToJwt() throws Exception {
  final AccessToken token = new AccessToken("allyourbase", new Date(Long.MAX_VALUE));
  KeyPair pair = KeyPairGenerator.getInstance("RSA").generateKeyPair();
  @SuppressWarnings("deprecation")
  ServiceAccountCredentials credentials = new ServiceAccountCredentials(
      null, "[email protected]", pair.getPrivate(), null, Arrays.asList("somescope")) {
    @Override
    public AccessToken refreshAccessToken() {
      return token;
    }
  };

  GoogleAuthLibraryCallCredentials callCredentials =
      new GoogleAuthLibraryCallCredentials(credentials);
  callCredentials.applyRequestMetadata(method, attrs, executor, applier);
  assertEquals(1, runPendingRunnables());

  verify(applier).apply(headersCaptor.capture());
  Metadata headers = headersCaptor.getValue();
  Iterable<String> authorization = headers.getAll(AUTHORIZATION);
  assertArrayEquals(new String[]{"Bearer allyourbase"},
      Iterables.toArray(authorization, String.class));
}
 
开发者ID:grpc,项目名称:grpc-java,代码行数:25,代码来源:GoogleAuthLibraryCallCredentialsTest.java

示例6: oauthClassesNotInClassPath

import io.grpc.Metadata; //导入方法依赖的package包/类
@Test
public void oauthClassesNotInClassPath() throws Exception {
  ListMultimap<String, String> values = LinkedListMultimap.create();
  values.put("Authorization", "token1");
  when(credentials.getRequestMetadata(eq(expectedUri))).thenReturn(Multimaps.asMap(values));

  assertNull(GoogleAuthLibraryCallCredentials.createJwtHelperOrNull(null));
  GoogleAuthLibraryCallCredentials callCredentials =
      new GoogleAuthLibraryCallCredentials(credentials, null);
  callCredentials.applyRequestMetadata(method, attrs, executor, applier);

  verify(credentials).getRequestMetadata(eq(expectedUri));
  verify(applier).apply(headersCaptor.capture());
  Metadata headers = headersCaptor.getValue();
  Iterable<String> authorization = headers.getAll(AUTHORIZATION);
  assertArrayEquals(new String[]{"token1"},
      Iterables.toArray(authorization, String.class));
}
 
开发者ID:grpc,项目名称:grpc-java,代码行数:19,代码来源:GoogleAuthLibraryCallCredentialsTest.java


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