當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。