Search in sources :

Example 6 with JacksonFactory

use of com.google.api.client.json.jackson.JacksonFactory in project google-cloud-eclipse by GoogleCloudPlatform.

the class ProjectRepositoryTest method testHasAppengineApplication_GoogleJsonResponseException.

@Test(expected = ProjectRepositoryException.class)
public void testHasAppengineApplication_GoogleJsonResponseException() throws IOException, ProjectRepositoryException {
    Apps.Get get = initializeGetRequest();
    GoogleJsonResponseException exception = GoogleJsonResponseExceptionFactoryTesting.newMock(new JacksonFactory(), 500, "Server Error");
    when(get.execute()).thenThrow(exception);
    repository.getAppEngineApplication(mock(Credential.class), "projectId");
}
Also used : GoogleJsonResponseException(com.google.api.client.googleapis.json.GoogleJsonResponseException) Credential(com.google.api.client.auth.oauth2.Credential) Apps(com.google.api.services.appengine.v1.Appengine.Apps) JacksonFactory(com.google.api.client.json.jackson.JacksonFactory) Test(org.junit.Test)

Example 7 with JacksonFactory

use of com.google.api.client.json.jackson.JacksonFactory in project appengine-java-standard by GoogleCloudPlatform.

the class CloudDatastoreV1ClientImpl method getCredential.

private static Credential getCredential() throws GeneralSecurityException, IOException {
    if (DatastoreServiceGlobalConfig.getConfig().emulatorHost() != null) {
        logger.log(Level.INFO, "Emulator host was provided. Not using credentials.");
        return null;
    }
    String serviceAccount = DatastoreServiceGlobalConfig.getConfig().serviceAccount();
    if (serviceAccount != null) {
        String privateKeyFile = DatastoreServiceGlobalConfig.getConfig().privateKeyFile();
        if (privateKeyFile != null) {
            logger.log(Level.INFO, "Service account and private key file were provided. " + "Using service account credential.");
            return getServiceAccountCredentialBuilder(serviceAccount).setServiceAccountPrivateKeyFromP12File(new File(privateKeyFile)).build();
        }
        PrivateKey privateKey = DatastoreServiceGlobalConfig.getConfig().privateKey();
        if (privateKey != null) {
            logger.log(Level.INFO, "Service account and private key were provided. " + "Using service account credential.");
            return getServiceAccountCredentialBuilder(serviceAccount).setServiceAccountPrivateKey(privateKey).build();
        }
        throw new IllegalStateException("Service account was provided without private key or private key file.");
    }
    if (DatastoreServiceGlobalConfig.getConfig().useComputeEngineCredential()) {
        // See b/35156374.
        return new ComputeCredential(GoogleNetHttpTransport.newTrustedTransport(), new JacksonFactory());
    }
    return GoogleCredential.getApplicationDefault().createScoped(DatastoreOptions.SCOPES);
}
Also used : PrivateKey(java.security.PrivateKey) ComputeCredential(com.google.api.client.googleapis.compute.ComputeCredential) File(java.io.File) JacksonFactory(com.google.api.client.json.jackson.JacksonFactory)

Aggregations

JacksonFactory (com.google.api.client.json.jackson.JacksonFactory)7 GoogleCredential (com.google.api.client.googleapis.auth.oauth2.GoogleCredential)2 ComputeCredential (com.google.api.client.googleapis.compute.ComputeCredential)2 GoogleNetHttpTransport (com.google.api.client.googleapis.javanet.GoogleNetHttpTransport)2 GoogleJsonResponseException (com.google.api.client.googleapis.json.GoogleJsonResponseException)2 HttpTransport (com.google.api.client.http.HttpTransport)2 NetHttpTransport (com.google.api.client.http.javanet.NetHttpTransport)2 Apps (com.google.api.services.appengine.v1.Appengine.Apps)2 GeneralSecurityException (java.security.GeneralSecurityException)2 Test (org.junit.Test)2 Credential (com.google.api.client.auth.oauth2.Credential)1 File (java.io.File)1 IOException (java.io.IOException)1 PrivateKey (java.security.PrivateKey)1