com.google.auth.http.HttpCredentialsAdapter Java Examples

The following examples show how to use com.google.auth.http.HttpCredentialsAdapter. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DicomStoreExport.java    From java-docs-samples with Apache License 2.0 6 votes vote down vote up
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();
}
 
Example #2
Source File: CloudIotManager.java    From daq with Apache License 2.0 6 votes vote down vote up
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);
  }
}
 
Example #3
Source File: FirebaseRequestInitializerTest.java    From firebase-admin-java with Apache License 2.0 6 votes vote down vote up
@Test
public void testExplicitTimeouts() throws Exception {
  FirebaseApp app = FirebaseApp.initializeApp(new FirebaseOptions.Builder()
      .setCredentials(new MockGoogleCredentials("token"))
      .setConnectTimeout(CONNECT_TIMEOUT_MILLIS)
      .setReadTimeout(READ_TIMEOUT_MILLIS)
      .build());
  HttpRequest request = TestUtils.createRequest();

  FirebaseRequestInitializer initializer = new FirebaseRequestInitializer(app);
  initializer.initialize(request);

  assertEquals(CONNECT_TIMEOUT_MILLIS, request.getConnectTimeout());
  assertEquals(READ_TIMEOUT_MILLIS, request.getReadTimeout());
  assertEquals("Bearer token", request.getHeaders().getAuthorization());
  assertEquals(HttpRequest.DEFAULT_NUMBER_OF_RETRIES, request.getNumberOfRetries());
  assertNull(request.getIOExceptionHandler());
  assertTrue(request.getUnsuccessfulResponseHandler() instanceof HttpCredentialsAdapter);
}
 
Example #4
Source File: DeviceRegistryExample.java    From java-docs-samples with Apache License 2.0 6 votes vote down vote up
/** Delete the given device from the registry. */
protected 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();
}
 
Example #5
Source File: DatasetGetIamPolicy.java    From java-docs-samples with Apache License 2.0 6 votes vote down vote up
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();
}
 
Example #6
Source File: DicomWebRetrieveInstance.java    From java-docs-samples with Apache License 2.0 6 votes vote down vote up
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));

  HttpHeaders headers = new HttpHeaders();
  headers.set("X-GFE-SSL", "yes");
  // Avoid parsing multipart boundaries by setting 'application/dicom' HTTP header.
  // Add 'transfer-syntax=*' to avoid transcoding by returning the file in the format it
  // was originally stored in.
  headers.setAccept("application/dicom; transfer-syntax=*");
  // 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();
}
 
Example #7
Source File: ManagedServiceAccountKeyCredentialTest.java    From styx with Apache License 2.0 6 votes vote down vote up
@Before
public void setUp() throws Exception {
  var defaultCredentials = GoogleCredentials.getApplicationDefault();

  var serviceCredentials = ImpersonatedCredentials.create(
      defaultCredentials, SERVICE_ACCOUNT,
      List.of(), List.of("https://www.googleapis.com/auth/cloud-platform"), 300);

  try {
    serviceCredentials.refreshAccessToken();
  } catch (IOException e) {
    // Do not run this test if we do not have permission to impersonate the test user.
    Assume.assumeNoException(e);
  }

  iam = new Iam.Builder(
      Utils.getDefaultTransport(), Utils.getDefaultJsonFactory(),
      new HttpCredentialsAdapter(serviceCredentials.createScoped(IamScopes.all())))
      .setApplicationName("styx-test")
      .build();
}
 
Example #8
Source File: Hl7v2StoreDelete.java    From java-docs-samples with Apache License 2.0 6 votes vote down vote up
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();
}
 
Example #9
Source File: CloudiotPubsubExampleServer.java    From java-docs-samples with Apache License 2.0 6 votes vote down vote up
/** 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();
}
 
Example #10
Source File: FhirResourceDeletePurge.java    From java-docs-samples with Apache License 2.0 6 votes vote down vote up
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();
}
 
Example #11
Source File: DisableServiceAccount.java    From java-docs-samples with Apache License 2.0 6 votes vote down vote up
private static Iam initService() throws GeneralSecurityException, IOException {
  // Use the Application Default Credentials strategy for authentication. For more info, see:
  // https://cloud.google.com/docs/authentication/production#finding_credentials_automatically
  GoogleCredentials credential =
      GoogleCredentials.getApplicationDefault()
          .createScoped(Collections.singleton(IamScopes.CLOUD_PLATFORM));
  // Initialize the IAM service, which can be used to send requests to the IAM API.
  Iam service =
      new Iam.Builder(
              GoogleNetHttpTransport.newTrustedTransport(),
              JacksonFactory.getDefaultInstance(),
              new HttpCredentialsAdapter(credential))
          .setApplicationName("service-accounts")
          .build();
  return service;
}
 
Example #12
Source File: CreateServiceAccount.java    From java-docs-samples with Apache License 2.0 6 votes vote down vote up
private static Iam initService() throws GeneralSecurityException, IOException {
  // Use the Application Default Credentials strategy for authentication. For more info, see:
  // https://cloud.google.com/docs/authentication/production#finding_credentials_automatically
  GoogleCredentials credential =
      GoogleCredentials.getApplicationDefault()
          .createScoped(Collections.singleton(IamScopes.CLOUD_PLATFORM));
  // Initialize the IAM service, which can be used to send requests to the IAM API.
  Iam service =
      new Iam.Builder(
              GoogleNetHttpTransport.newTrustedTransport(),
              JacksonFactory.getDefaultInstance(),
              new HttpCredentialsAdapter(credential))
          .setApplicationName("service-accounts")
          .build();
  return service;
}
 
Example #13
Source File: TestPermissions.java    From java-docs-samples with Apache License 2.0 6 votes vote down vote up
public static CloudResourceManager createCloudResourceManagerService()
    throws IOException, GeneralSecurityException {
  // Use the Application Default Credentials strategy for authentication. For more info, see:
  // https://cloud.google.com/docs/authentication/production#finding_credentials_automatically
  GoogleCredentials credential =
      GoogleCredentials.getApplicationDefault()
          .createScoped(Collections.singleton(IamScopes.CLOUD_PLATFORM));

  CloudResourceManager service =
      new CloudResourceManager.Builder(
              GoogleNetHttpTransport.newTrustedTransport(),
              JacksonFactory.getDefaultInstance(),
              new HttpCredentialsAdapter(credential))
          .setApplicationName("service-accounts")
          .build();
  return service;
}
 
Example #14
Source File: HL7v2MessageGet.java    From java-docs-samples with Apache License 2.0 6 votes vote down vote up
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();
}
 
Example #15
Source File: Hl7v2StoreCreate.java    From java-docs-samples with Apache License 2.0 6 votes vote down vote up
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();
}
 
Example #16
Source File: Hl7v2StorePatch.java    From java-docs-samples with Apache License 2.0 6 votes vote down vote up
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();
}
 
Example #17
Source File: DicomWebStoreInstance.java    From java-docs-samples with Apache License 2.0 6 votes vote down vote up
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();
}
 
Example #18
Source File: FhirResourceGetPatientEverything.java    From java-docs-samples with Apache License 2.0 6 votes vote down vote up
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();
}
 
Example #19
Source File: FhirResourceListHistory.java    From java-docs-samples with Apache License 2.0 6 votes vote down vote up
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();
}
 
Example #20
Source File: DeviceRegistryExample.java    From java-docs-samples with Apache License 2.0 6 votes vote down vote up
/** Retrieves registry metadata from a project. * */
protected static DeviceRegistry getRegistry(
    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 registryPath =
      String.format(
          "projects/%s/locations/%s/registries/%s", projectId, cloudRegion, registryName);

  return service.projects().locations().registries().get(registryPath).execute();
}
 
Example #21
Source File: TransferClientCreator.java    From java-docs-samples with Apache License 2.0 6 votes vote down vote up
/**
 * Create a Storage Transfer client using user-supplied credentials and other settings.
 *
 * @param httpTransport a user-supplied HttpTransport
 * @param jsonFactory a user-supplied JsonFactory
 * @param credential a user-supplied Google credential
 * @return a Storage Transfer client
 */
public static Storagetransfer createStorageTransferClient(
    HttpTransport httpTransport, JsonFactory jsonFactory, GoogleCredentials credential) {
  Preconditions.checkNotNull(httpTransport);
  Preconditions.checkNotNull(jsonFactory);
  Preconditions.checkNotNull(credential);

  // In some cases, you need to add the scope explicitly.
  if (credential.createScopedRequired()) {
    credential = credential.createScoped(StoragetransferScopes.all());
  }
  // Please use custom HttpRequestInitializer for automatic
  // retry upon failures. We provide a simple reference
  // implementation in the "Retry Handling" section.
  HttpRequestInitializer initializer = new HttpCredentialsAdapter(credential);
  return new Storagetransfer.Builder(httpTransport, jsonFactory, initializer)
      .setApplicationName("storagetransfer-sample")
      .build();
}
 
Example #22
Source File: QuickstartV2.java    From java-docs-samples with Apache License 2.0 6 votes vote down vote up
public static CloudResourceManager initializeService()
    throws IOException, GeneralSecurityException {
  // Use the Application Default Credentials strategy for authentication. For more info, see:
  // https://cloud.google.com/docs/authentication/production#finding_credentials_automatically
  GoogleCredentials credential =
      GoogleCredentials.getApplicationDefault()
          .createScoped(Collections.singleton(IamScopes.CLOUD_PLATFORM));

  // Creates the Cloud Resource Manager service object.
  CloudResourceManager service =
      new CloudResourceManager.Builder(
              GoogleNetHttpTransport.newTrustedTransport(),
              JacksonFactory.getDefaultInstance(),
              new HttpCredentialsAdapter(credential))
          .setApplicationName("service-accounts")
          .build();
  return service;
}
 
Example #23
Source File: DatasetList.java    From java-docs-samples with Apache License 2.0 6 votes vote down vote up
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();
}
 
Example #24
Source File: DeleteServiceAccount.java    From java-docs-samples with Apache License 2.0 6 votes vote down vote up
private static Iam initService() throws GeneralSecurityException, IOException {
  // Use the Application Default Credentials strategy for authentication. For more info, see:
  // https://cloud.google.com/docs/authentication/production#finding_credentials_automatically
  GoogleCredentials credential =
      GoogleCredentials.getApplicationDefault()
          .createScoped(Collections.singleton(IamScopes.CLOUD_PLATFORM));
  // Initialize the IAM service, which can be used to send requests to the IAM API.
  Iam service =
      new Iam.Builder(
              GoogleNetHttpTransport.newTrustedTransport(),
              JacksonFactory.getDefaultInstance(),
              new HttpCredentialsAdapter(credential))
          .setApplicationName("service-accounts")
          .build();
  return service;
}
 
Example #25
Source File: FhirResourceSearchPost.java    From java-docs-samples with Apache License 2.0 6 votes vote down vote up
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();
}
 
Example #26
Source File: BuildIapRequest.java    From java-docs-samples with Apache License 2.0 6 votes vote down vote up
/**
 * 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());
}
 
Example #27
Source File: FhirResourceGetHistory.java    From java-docs-samples with Apache License 2.0 6 votes vote down vote up
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();
}
 
Example #28
Source File: HL7v2MessageIngest.java    From java-docs-samples with Apache License 2.0 6 votes vote down vote up
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();
}
 
Example #29
Source File: DatasetGet.java    From java-docs-samples with Apache License 2.0 6 votes vote down vote up
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();
}
 
Example #30
Source File: DeviceRegistryExample.java    From java-docs-samples with Apache License 2.0 6 votes vote down vote up
/** Retrieves device metadata from a registry. * */
protected static Device getDevice(
    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 " + devicePath);
  return service.projects().locations().registries().devices().get(devicePath).execute();
}