类com.google.api.client.http.HttpRequestInitializer源码实例Demo

下面列出了怎么用com.google.api.client.http.HttpRequestInitializer的API类实例代码及写法,或者点击链接到github查看源代码。

GoogleCredential getJsonCredential(
    Path keyPath,
    HttpTransport transport,
    JsonFactory jsonFactory,
    HttpRequestInitializer httpRequestInitializer,
    Collection<String> scopes)
    throws IOException {
  try (InputStream is = newInputStream(keyPath)) {
    GoogleCredential credential =
        GoogleCredential.fromStream(is, transport, jsonFactory).createScoped(scopes);
    return new GoogleCredential.Builder()
        .setServiceAccountId(credential.getServiceAccountId())
        .setServiceAccountScopes(scopes)
        .setServiceAccountPrivateKey(credential.getServiceAccountPrivateKey())
        .setTransport(transport)
        .setJsonFactory(jsonFactory)
        .setRequestInitializer(httpRequestInitializer)
        .build();
  }
}
 
@Test
public void testNullServiceAccountIdJson() throws Exception {
  File tmpfile =
      temporaryFolder.newFile("testNullServiceAccountIdJson" + SERVICE_ACCOUNT_FILE_JSON);
  GoogleCredential mockCredential = new MockGoogleCredential.Builder().build();
  List<String> scopes = Arrays.asList("profile");
  when(mockCredentialHelper.getJsonCredential(
      eq(tmpfile.toPath()),
      any(HttpTransport.class),
      any(JsonFactory.class),
      any(HttpRequestInitializer.class),
      eq(scopes)))
      .thenReturn(mockCredential);
  LocalFileCredentialFactory subject =
      new LocalFileCredentialFactory.Builder()
          .setServiceAccountKeyFilePath(tmpfile.getAbsolutePath())
          .build();
  subject.getCredential(Arrays.asList("email"));
  assertEquals(mockCredential, subject.getCredential(scopes));
}
 
@Test
public void testGetCredentialP12() throws Exception {
  File tmpfile = temporaryFolder.newFile(SERVICE_ACCOUNT_FILE_P12);
  GoogleCredential mockCredential = new MockGoogleCredential.Builder().build();
  List<String> scopes = Arrays.asList("profile, calendar");
  when(mockCredentialHelper.getP12Credential(
      eq("ServiceAccount"),
      eq(tmpfile.toPath()),
      any(HttpTransport.class),
      any(JsonFactory.class),
      any(HttpRequestInitializer.class),
      eq(scopes)))
      .thenReturn(mockCredential);
  LocalFileCredentialFactory credentialFactory =
      new LocalFileCredentialFactory.Builder()
          .setServiceAccountKeyFilePath(tmpfile.getAbsolutePath())
          .setServiceAccountId("ServiceAccount")
          .build();
  assertEquals(mockCredential, credentialFactory.getCredential(scopes));
}
 
@Test
public void testfromConfigurationJsonKey() throws Exception {
  File tmpfile = temporaryFolder.newFile("testfromConfiguration" + SERVICE_ACCOUNT_FILE_JSON);
  createConfig(tmpfile.getAbsolutePath(), "");
  GoogleCredential mockCredential = new MockGoogleCredential.Builder().build();
  List<String> scopes = Arrays.asList("profile");
  when(mockCredentialHelper.getJsonCredential(
      eq(tmpfile.toPath()),
      any(HttpTransport.class),
      any(JsonFactory.class),
      any(HttpRequestInitializer.class),
      eq(scopes)))
      .thenReturn(mockCredential);
  LocalFileCredentialFactory credentialFactory = LocalFileCredentialFactory.fromConfiguration();
  assertEquals(mockCredential, credentialFactory.getCredential(scopes));
}
 
源代码5 项目: java-docs-samples   文件: FhirStorePatch.java
private static CloudHealthcare createClient() throws IOException {
  // Use Application Default Credentials (ADC) to authenticate the requests
  // For more information see https://cloud.google.com/docs/authentication/production
  GoogleCredentials credential =
      GoogleCredentials.getApplicationDefault()
          .createScoped(Collections.singleton(CloudHealthcareScopes.CLOUD_PLATFORM));

  // Create a HttpRequestInitializer, which will provide a baseline configuration to all requests.
  HttpRequestInitializer requestInitializer =
      request -> {
        new HttpCredentialsAdapter(credential).initialize(request);
        request.setConnectTimeout(60000); // 1 minute connect timeout
        request.setReadTimeout(60000); // 1 minute read timeout
      };

  // Build the client for interacting with the service.
  return new CloudHealthcare.Builder(HTTP_TRANSPORT, JSON_FACTORY, requestInitializer)
      .setApplicationName("your-application-name")
      .build();
}
 
源代码6 项目: daq   文件: CloudIotManager.java
private void initializeCloudIoT() {
  projectPath = "projects/" + projectId + "/locations/" + cloudRegion;
  try {
    System.err.println("Initializing with default credentials...");
    GoogleCredentials credential =
        GoogleCredentials.getApplicationDefault().createScoped(CloudIotScopes.all());
    JsonFactory jsonFactory = JacksonFactory.getDefaultInstance();
    HttpRequestInitializer init = new HttpCredentialsAdapter(credential);
    cloudIotService =
        new CloudIot.Builder(GoogleNetHttpTransport.newTrustedTransport(), jsonFactory, init)
            .setApplicationName("com.google.iot.bos")
            .build();
    cloudIotRegistries = cloudIotService.projects().locations().registries();
    System.err.println("Created service for project " + projectPath);
  } catch (Exception e) {
    throw new RuntimeException("While initializing Cloud IoT project " + projectPath, e);
  }
}
 
源代码7 项目: java-docs-samples   文件: HL7v2MessageGet.java
private static CloudHealthcare createClient() throws IOException {
  // Use Application Default Credentials (ADC) to authenticate the requests
  // For more information see https://cloud.google.com/docs/authentication/production
  GoogleCredentials credential =
      GoogleCredentials.getApplicationDefault()
          .createScoped(Collections.singleton(CloudHealthcareScopes.CLOUD_PLATFORM));

  // Create a HttpRequestInitializer, which will provide a baseline configuration to all requests.
  HttpRequestInitializer requestInitializer =
      request -> {
        new HttpCredentialsAdapter(credential).initialize(request);
        request.setConnectTimeout(60000); // 1 minute connect timeout
        request.setReadTimeout(60000); // 1 minute read timeout
      };

  // Build the client for interacting with the service.
  return new CloudHealthcare.Builder(HTTP_TRANSPORT, JSON_FACTORY, requestInitializer)
      .setApplicationName("your-application-name")
      .build();
}
 
源代码8 项目: java-docs-samples   文件: FhirStoreExport.java
private static CloudHealthcare createClient() throws IOException {
  // Use Application Default Credentials (ADC) to authenticate the requests
  // For more information see https://cloud.google.com/docs/authentication/production
  GoogleCredentials credential =
      GoogleCredentials.getApplicationDefault()
          .createScoped(Collections.singleton(CloudHealthcareScopes.CLOUD_PLATFORM));

  // Create a HttpRequestInitializer, which will provide a baseline configuration to all requests.
  HttpRequestInitializer requestInitializer =
      request -> {
        new HttpCredentialsAdapter(credential).initialize(request);
        request.setConnectTimeout(60000); // 1 minute connect timeout
        request.setReadTimeout(60000); // 1 minute read timeout
      };

  // Build the client for interacting with the service.
  return new CloudHealthcare.Builder(HTTP_TRANSPORT, JSON_FACTORY, requestInitializer)
      .setApplicationName("your-application-name")
      .build();
}
 
源代码9 项目: java-docs-samples   文件: HL7v2MessageList.java
private static CloudHealthcare createClient() throws IOException {
  // Use Application Default Credentials (ADC) to authenticate the requests
  // For more information see https://cloud.google.com/docs/authentication/production
  GoogleCredentials credential =
      GoogleCredentials.getApplicationDefault()
          .createScoped(Collections.singleton(CloudHealthcareScopes.CLOUD_PLATFORM));

  // Create a HttpRequestInitializer, which will provide a baseline configuration to all requests.
  HttpRequestInitializer requestInitializer =
      request -> {
        new HttpCredentialsAdapter(credential).initialize(request);
        request.setConnectTimeout(60000); // 1 minute connect timeout
        request.setReadTimeout(60000); // 1 minute read timeout
      };

  // Build the client for interacting with the service.
  return new CloudHealthcare.Builder(HTTP_TRANSPORT, JSON_FACTORY, requestInitializer)
      .setApplicationName("your-application-name")
      .build();
}
 
源代码10 项目: java-docs-samples   文件: DicomStorePatch.java
private static CloudHealthcare createClient() throws IOException {
  // Use Application Default Credentials (ADC) to authenticate the requests
  // For more information see https://cloud.google.com/docs/authentication/production
  GoogleCredentials credential =
      GoogleCredentials.getApplicationDefault()
          .createScoped(Collections.singleton(CloudHealthcareScopes.CLOUD_PLATFORM));

  // Create a HttpRequestInitializer, which will provide a baseline configuration to all requests.
  HttpRequestInitializer requestInitializer =
      request -> {
        new HttpCredentialsAdapter(credential).initialize(request);
        request.setConnectTimeout(60000); // 1 minute connect timeout
        request.setReadTimeout(60000); // 1 minute read timeout
      };

  // Build the client for interacting with the service.
  return new CloudHealthcare.Builder(HTTP_TRANSPORT, JSON_FACTORY, requestInitializer)
      .setApplicationName("your-application-name")
      .build();
}
 
源代码11 项目: Xero-Java   文件: ApiClient.java
public ApiClient(
    String basePath,
    HttpTransport transport,
    HttpRequestInitializer initializer,
    ObjectMapper objectMapper,
    HttpRequestFactory reqFactory
) {
    this.basePath = basePath == null ? defaultBasePath : (
        basePath.endsWith("/") ? basePath.substring(0, basePath.length() - 1) : basePath
    );
    if (transport != null) {
        this.httpTransport = transport;
    }
    this.httpRequestFactory = (reqFactory != null ? reqFactory : (transport == null ? Utils.getDefaultTransport() : transport).createRequestFactory(initializer) );
    this.objectMapper = (objectMapper == null ? createDefaultObjectMapper() : objectMapper);
}
 
源代码12 项目: UTubeTV   文件: YouTubeAPI.java
public YouTube youTube() {
  if (youTube == null) {
    try {
      HttpRequestInitializer credentials;

      if (mUseAuthCredentials)
        credentials = Auth.getCredentials(mContext, mUseDefaultAccount);
      else
        credentials = Auth.nullCredentials(mContext);

      youTube = new YouTube.Builder(new NetHttpTransport(), new AndroidJsonFactory(), credentials).setApplicationName("YouTubeAPI")
          .build();
    } catch (Exception e) {
      e.printStackTrace();
    } catch (Throwable t) {
      t.printStackTrace();
    }
  }

  return youTube;
}
 
源代码13 项目: java-docs-samples   文件: FhirStoreCreate.java
private static CloudHealthcare createClient() throws IOException {
  // Use Application Default Credentials (ADC) to authenticate the requests
  // For more information see https://cloud.google.com/docs/authentication/production
  GoogleCredentials credential =
      GoogleCredentials.getApplicationDefault()
          .createScoped(Collections.singleton(CloudHealthcareScopes.CLOUD_PLATFORM));

  // Create a HttpRequestInitializer, which will provide a baseline configuration to all requests.
  HttpRequestInitializer requestInitializer =
      request -> {
        new HttpCredentialsAdapter(credential).initialize(request);
        request.setConnectTimeout(60000); // 1 minute connect timeout
        request.setReadTimeout(60000); // 1 minute read timeout
      };

  // Build the client for interacting with the service.
  return new CloudHealthcare.Builder(HTTP_TRANSPORT, JSON_FACTORY, requestInitializer)
      .setApplicationName("your-application-name")
      .build();
}
 
源代码14 项目: java-docs-samples   文件: DatasetSetIamPolicy.java
private static CloudHealthcare createClient() throws IOException {
  // Use Application Default Credentials (ADC) to authenticate the requests
  // For more information see https://cloud.google.com/docs/authentication/production
  GoogleCredentials credential =
      GoogleCredentials.getApplicationDefault()
          .createScoped(Collections.singleton(CloudHealthcareScopes.CLOUD_PLATFORM));

  // Create a HttpRequestInitializer, which will provide a baseline configuration to all requests.
  HttpRequestInitializer requestInitializer =
      request -> {
        new HttpCredentialsAdapter(credential).initialize(request);
        request.setConnectTimeout(60000); // 1 minute connect timeout
        request.setReadTimeout(60000); // 1 minute read timeout
      };

  // Build the client for interacting with the service.
  return new CloudHealthcare.Builder(HTTP_TRANSPORT, JSON_FACTORY, requestInitializer)
      .setApplicationName("your-application-name")
      .build();
}
 
源代码15 项目: appengine-gcs-client   文件: URLFetchUtilsTest.java
@Test
public void testDescribeRequestAndResponseForApiClient() throws Exception {
  HttpRequestInitializer initializer = mock(HttpRequestInitializer.class);
  NetHttpTransport transport = new NetHttpTransport();
  Storage storage = new Storage.Builder(transport, new JacksonFactory(), initializer)
      .setApplicationName("bla").build();
  HttpRequest request = storage.objects().delete("bucket", "object").buildHttpRequest();
  request.getHeaders().clear();
  request.getHeaders().put("k1", "v1");
  request.getHeaders().put("k2", "v2");
  HttpResponseException exception = null;
  try {
    request.execute();
  } catch (HttpResponseException ex) {
    exception = ex;
  }
  String expected = "Request: DELETE " + Storage.DEFAULT_BASE_URL + "b/bucket/o/object\n"
      + "k1: v1\nk2: v2\n\nno content\n\nResponse: 40";
  String result =
      URLFetchUtils.describeRequestAndResponse(new HTTPRequestInfo(request), exception);
  assertTrue(expected + "\nis not a prefix of:\n" + result, result.startsWith(expected));
}
 
源代码16 项目: cloud-pubsub-samples-java   文件: PubsubUtils.java
/**
 * Builds a new Pubsub client and returns it.
 *
 * @param httpTransport HttpTransport for Pubsub client.
 * @param jsonFactory JsonFactory for Pubsub client.
 * @return Pubsub client.
 * @throws IOException when we can not get the default credentials.
 */
public static Pubsub getClient(final HttpTransport httpTransport,
                               final JsonFactory jsonFactory)
        throws IOException {
    Preconditions.checkNotNull(httpTransport);
    Preconditions.checkNotNull(jsonFactory);
    GoogleCredential credential = GoogleCredential.getApplicationDefault();
    if (credential.createScopedRequired()) {
        credential = credential.createScoped(PubsubScopes.all());
    }
    // Please use custom HttpRequestInitializer for automatic
    // retry upon failures.
    HttpRequestInitializer initializer =
            new RetryHttpInitializerWrapper(credential);
    return new Pubsub.Builder(httpTransport, jsonFactory, initializer)
            .setApplicationName(APPLICATION_NAME)
            .build();
}
 
源代码17 项目: java-docs-samples   文件: DeviceRegistryExample.java
/** Retrieves device metadata from a registry. * */
protected static List<DeviceState> getDeviceStates(
    String deviceId, String projectId, String cloudRegion, String registryName)
    throws GeneralSecurityException, IOException {
  GoogleCredentials credential =
      GoogleCredentials.getApplicationDefault().createScoped(CloudIotScopes.all());
  JsonFactory jsonFactory = JacksonFactory.getDefaultInstance();
  HttpRequestInitializer init = new HttpCredentialsAdapter(credential);
  final CloudIot service =
      new CloudIot.Builder(GoogleNetHttpTransport.newTrustedTransport(), jsonFactory, init)
          .setApplicationName(APP_NAME)
          .build();

  final String devicePath =
      String.format(
          "projects/%s/locations/%s/registries/%s/devices/%s",
          projectId, cloudRegion, registryName, deviceId);

  System.out.println("Retrieving device states " + devicePath);

  ListDeviceStatesResponse resp =
      service.projects().locations().registries().devices().states().list(devicePath).execute();

  return resp.getDeviceStates();
}
 
源代码18 项目: beam   文件: HttpHealthcareApiClient.java
private void initClient() throws IOException {

    credentials = GoogleCredentials.getApplicationDefault();
    // Create a HttpRequestInitializer, which will provide a baseline configuration to all requests.
    HttpRequestInitializer requestInitializer =
        new AuthenticatedRetryInitializer(
            credentials.createScoped(
                CloudHealthcareScopes.CLOUD_PLATFORM, StorageScopes.CLOUD_PLATFORM_READ_ONLY));

    client =
        new CloudHealthcare.Builder(
                new NetHttpTransport(), new JacksonFactory(), requestInitializer)
            .setApplicationName("apache-beam-hl7v2-io")
            .build();
    httpClient =
        HttpClients.custom().setRetryHandler(new DefaultHttpRequestRetryHandler(10, false)).build();
  }
 
源代码19 项目: java-docs-samples   文件: FhirStoreGetIamPolicy.java
private static CloudHealthcare createClient() throws IOException {
  // Use Application Default Credentials (ADC) to authenticate the requests
  // For more information see https://cloud.google.com/docs/authentication/production
  GoogleCredentials credential =
      GoogleCredentials.getApplicationDefault()
          .createScoped(Collections.singleton(CloudHealthcareScopes.CLOUD_PLATFORM));

  // Create a HttpRequestInitializer, which will provide a baseline configuration to all requests.
  HttpRequestInitializer requestInitializer =
      request -> {
        new HttpCredentialsAdapter(credential).initialize(request);
        request.setConnectTimeout(60000); // 1 minute connect timeout
        request.setReadTimeout(60000); // 1 minute read timeout
      };

  // Build the client for interacting with the service.
  return new CloudHealthcare.Builder(HTTP_TRANSPORT, JSON_FACTORY, requestInitializer)
      .setApplicationName("your-application-name")
      .build();
}
 
源代码20 项目: java-docs-samples   文件: FhirStoreGet.java
private static CloudHealthcare createClient() throws IOException {
  // Use Application Default Credentials (ADC) to authenticate the requests
  // For more information see https://cloud.google.com/docs/authentication/production
  GoogleCredentials credential =
      GoogleCredentials.getApplicationDefault()
          .createScoped(Collections.singleton(CloudHealthcareScopes.CLOUD_PLATFORM));

  // Create a HttpRequestInitializer, which will provide a baseline configuration to all requests.
  HttpRequestInitializer requestInitializer =
      request -> {
        new HttpCredentialsAdapter(credential).initialize(request);
        request.setConnectTimeout(60000); // 1 minute connect timeout
        request.setReadTimeout(60000); // 1 minute read timeout
      };

  // Build the client for interacting with the service.
  return new CloudHealthcare.Builder(HTTP_TRANSPORT, JSON_FACTORY, requestInitializer)
      .setApplicationName("your-application-name")
      .build();
}
 
源代码21 项目: nomulus   文件: RequestFactoryModuleTest.java
@Test
public void test_provideHttpRequestFactory_remote() throws Exception {
  // Make sure that example.com creates a request factory with the UNITTEST client id but no
  boolean origIsLocal = RegistryConfig.CONFIG_SETTINGS.get().appEngine.isLocal;
  RegistryConfig.CONFIG_SETTINGS.get().appEngine.isLocal = false;
  try {
    HttpRequestFactory factory =
        RequestFactoryModule.provideHttpRequestFactory(credentialsBundle);
    HttpRequestInitializer initializer = factory.getInitializer();
    assertThat(initializer).isNotNull();
    // HttpRequestFactory#buildGetRequest() calls initialize() once.
    HttpRequest request = factory.buildGetRequest(new GenericUrl("http://localhost"));
    verify(httpRequestInitializer).initialize(request);
    assertThat(request.getConnectTimeout()).isEqualTo(REQUEST_TIMEOUT_MS);
    assertThat(request.getReadTimeout()).isEqualTo(REQUEST_TIMEOUT_MS);
    verifyNoMoreInteractions(httpRequestInitializer);
  } finally {
    RegistryConfig.CONFIG_SETTINGS.get().appEngine.isLocal = origIsLocal;
  }
}
 
源代码22 项目: cloud-pubsub-mqtt-proxy   文件: GcloudPubsub.java
/**
 * Constructor that will automatically instantiate a Google Cloud Pub/Sub instance.
 *
 * @throws IOException when the initialization of the Google Cloud Pub/Sub client fails.
 */
public GcloudPubsub() throws IOException {
  if (CLOUD_PUBSUB_PROJECT_ID == null) {
    throw new IllegalStateException(GCLOUD_PUBSUB_PROJECT_ID_NOT_SET_ERROR);
  }
  try {
    serverName = InetAddress.getLocalHost().getCanonicalHostName();
  } catch (UnknownHostException e) {
    throw new IllegalStateException("Unable to retrieve the hostname of the system");
  }
  HttpTransport httpTransport = checkNotNull(Utils.getDefaultTransport());
  JsonFactory jsonFactory = checkNotNull(Utils.getDefaultJsonFactory());
  GoogleCredential credential = GoogleCredential.getApplicationDefault(
      httpTransport, jsonFactory);
  if (credential.createScopedRequired()) {
    credential = credential.createScoped(PubsubScopes.all());
  }
  HttpRequestInitializer initializer =
      new RetryHttpInitializerWrapper(credential);
  pubsub = new Pubsub.Builder(httpTransport, jsonFactory, initializer).build();
  logger.info("Google Cloud Pub/Sub Initialization SUCCESS");
}
 
源代码23 项目: java-docs-samples   文件: HL7v2MessageIngest.java
private static CloudHealthcare createClient() throws IOException {
  // Use Application Default Credentials (ADC) to authenticate the requests
  // For more information see https://cloud.google.com/docs/authentication/production
  GoogleCredentials credential =
      GoogleCredentials.getApplicationDefault()
          .createScoped(Collections.singleton(CloudHealthcareScopes.CLOUD_PLATFORM));

  // Create a HttpRequestInitializer, which will provide a baseline configuration to all requests.
  HttpRequestInitializer requestInitializer =
      request -> {
        new HttpCredentialsAdapter(credential).initialize(request);
        request.setConnectTimeout(60000); // 1 minute connect timeout
        request.setReadTimeout(60000); // 1 minute read timeout
      };

  // Build the client for interacting with the service.
  return new CloudHealthcare.Builder(HTTP_TRANSPORT, JSON_FACTORY, requestInitializer)
      .setApplicationName("your-application-name")
      .build();
}
 
/** Delete this registry from Cloud IoT. */
public static void deleteRegistry(String cloudRegion, String projectId, String registryName)
    throws GeneralSecurityException, IOException {
  GoogleCredentials credential =
      GoogleCredentials.getApplicationDefault().createScoped(CloudIotScopes.all());
  JsonFactory jsonFactory = JacksonFactory.getDefaultInstance();
  HttpRequestInitializer init = new HttpCredentialsAdapter(credential);
  final CloudIot service =
      new CloudIot.Builder(GoogleNetHttpTransport.newTrustedTransport(), jsonFactory, init)
          .setApplicationName(APP_NAME)
          .build();

  final String registryPath =
      String.format(
          "projects/%s/locations/%s/registries/%s", projectId, cloudRegion, registryName);

  System.out.println("Deleting: " + registryPath);
  service.projects().locations().registries().delete(registryPath).execute();
}
 
源代码25 项目: java-docs-samples   文件: BuildIapRequest.java
/**
 * Clone request and add an IAP Bearer Authorization header with signed JWT token.
 *
 * @param request Request to add authorization header
 * @param iapClientId OAuth 2.0 client ID for IAP protected resource
 * @return Clone of request with Bearer style authorization header with signed jwt token.
 * @throws IOException exception creating signed JWT
 */
public static HttpRequest buildIapRequest(HttpRequest request, String iapClientId)
    throws IOException {

  IdTokenProvider idTokenProvider = getIdTokenProvider();
  IdTokenCredentials credentials =
      IdTokenCredentials.newBuilder()
          .setIdTokenProvider(idTokenProvider)
          .setTargetAudience(iapClientId)
          .build();

  HttpRequestInitializer httpRequestInitializer = new HttpCredentialsAdapter(credentials);

  return httpTransport
      .createRequestFactory(httpRequestInitializer)
      .buildRequest(request.getRequestMethod(), request.getUrl(), request.getContent());
}
 
源代码26 项目: java-docs-samples   文件: DatasetGetIamPolicy.java
private static CloudHealthcare createClient() throws IOException {
  // Use Application Default Credentials (ADC) to authenticate the requests
  // For more information see https://cloud.google.com/docs/authentication/production
  GoogleCredentials credential =
      GoogleCredentials.getApplicationDefault()
          .createScoped(Collections.singleton(CloudHealthcareScopes.CLOUD_PLATFORM));

  // Create a HttpRequestInitializer, which will provide a baseline configuration to all requests.
  HttpRequestInitializer requestInitializer =
      request -> {
        new HttpCredentialsAdapter(credential).initialize(request);
        request.setConnectTimeout(60000); // 1 minute connect timeout
        request.setReadTimeout(60000); // 1 minute read timeout
      };

  // Build the client for interacting with the service.
  return new CloudHealthcare.Builder(HTTP_TRANSPORT, JSON_FACTORY, requestInitializer)
      .setApplicationName("your-application-name")
      .build();
}
 
源代码27 项目: java-docs-samples   文件: FhirResourceGetHistory.java
private static CloudHealthcare createClient() throws IOException {
  // Use Application Default Credentials (ADC) to authenticate the requests
  // For more information see https://cloud.google.com/docs/authentication/production
  GoogleCredentials credential =
      GoogleCredentials.getApplicationDefault()
          .createScoped(Collections.singleton(CloudHealthcareScopes.CLOUD_PLATFORM));

  // Create a HttpRequestInitializer, which will provide a baseline configuration to all requests.
  HttpRequestInitializer requestInitializer =
      request -> {
        new HttpCredentialsAdapter(credential).initialize(request);
        request.setConnectTimeout(60000); // 1 minute connect timeout
        request.setReadTimeout(60000); // 1 minute read timeout
      };

  // Build the client for interacting with the service.
  return new CloudHealthcare.Builder(HTTP_TRANSPORT, JSON_FACTORY, requestInitializer)
      .setApplicationName("your-application-name")
      .build();
}
 
private static CloudHealthcare createClient() throws IOException {
  // Use Application Default Credentials (ADC) to authenticate the requests
  // For more information see https://cloud.google.com/docs/authentication/production
  GoogleCredentials credential =
      GoogleCredentials.getApplicationDefault()
          .createScoped(Collections.singleton(CloudHealthcareScopes.CLOUD_PLATFORM));

  // Create a HttpRequestInitializer, which will provide a baseline configuration to all requests.
  HttpRequestInitializer requestInitializer =
      request -> {
        new HttpCredentialsAdapter(credential).initialize(request);
        request.setConnectTimeout(60000); // 1 minute connect timeout
        request.setReadTimeout(60000); // 1 minute read timeout
      };

  // Build the client for interacting with the service.
  return new CloudHealthcare.Builder(HTTP_TRANSPORT, JSON_FACTORY, requestInitializer)
      .setApplicationName("your-application-name")
      .build();
}
 
private static CloudHealthcare createClient() throws IOException {
  // Use Application Default Credentials (ADC) to authenticate the requests
  // For more information see https://cloud.google.com/docs/authentication/production
  GoogleCredentials credential =
      GoogleCredentials.getApplicationDefault()
          .createScoped(Collections.singleton(CloudHealthcareScopes.CLOUD_PLATFORM));

  // Create a HttpRequestInitializer, which will provide a baseline configuration to all requests.
  HttpRequestInitializer requestInitializer =
      request -> {
        new HttpCredentialsAdapter(credential).initialize(request);
        request.setConnectTimeout(60000); // 1 minute connect timeout
        request.setReadTimeout(60000); // 1 minute read timeout
      };

  // Build the client for interacting with the service.
  return new CloudHealthcare.Builder(HTTP_TRANSPORT, JSON_FACTORY, requestInitializer)
      .setApplicationName("your-application-name")
      .build();
}
 
/** Delete this device from Cloud IoT. */
public static void deleteDevice(
    String deviceId, String projectId, String cloudRegion, String registryName)
    throws GeneralSecurityException, IOException {
  GoogleCredentials credential =
      GoogleCredentials.getApplicationDefault().createScoped(CloudIotScopes.all());
  JsonFactory jsonFactory = JacksonFactory.getDefaultInstance();
  HttpRequestInitializer init = new HttpCredentialsAdapter(credential);
  final CloudIot service =
      new CloudIot.Builder(GoogleNetHttpTransport.newTrustedTransport(), jsonFactory, init)
          .setApplicationName(APP_NAME)
          .build();

  final String devicePath =
      String.format(
          "projects/%s/locations/%s/registries/%s/devices/%s",
          projectId, cloudRegion, registryName, deviceId);

  System.out.println("Deleting device " + devicePath);
  service.projects().locations().registries().devices().delete(devicePath).execute();
}
 
 类方法
 同包方法