List of usage examples for com.google.api.client.googleapis.javanet GoogleNetHttpTransport newTrustedTransport
public static NetHttpTransport newTrustedTransport() throws GeneralSecurityException, IOException
From source file:hello.storage.DriveService.java
License:Apache License
public static void main(String UPLOAD_FILE_PATH, String ContentType) { try {//from ww w . j a v a 2s. co m java.io.File UPLOAD_FILE = new java.io.File(UPLOAD_FILE_PATH); HTTP_TRANSPORT = GoogleNetHttpTransport.newTrustedTransport(); DATA_STORE_FACTORY = new FileDataStoreFactory(DATA_STORE_DIR); // authorization // set up the global Drive instance drive = getDriveService(); // run commands View.header1("Starting Resumable Media Upload"); View.header1("Starting Simple Media Upload"); File uploadedFile = uploadFile(true, UPLOAD_FILE, ContentType); View.header1("Success!"); return; } catch (IOException e) { System.err.println(e.getMessage()); e.printStackTrace(); } catch (Throwable t) { t.printStackTrace(); } System.exit(1); }
From source file:imageSearching.DetectImage.java
License:Open Source License
/** * Connects to the Vision API using Application Default Credentials. *//*from w w w .jav a 2s . com*/ public static Vision getVisionService() throws IOException, GeneralSecurityException { File credentialsFile = new File("license/license.txt"); InputStream credentialsStream = new FileInputStream(credentialsFile); GoogleCredential credential = GoogleCredential.fromStream(credentialsStream); credential = credential.createScoped(VisionScopes.all()); JsonFactory jsonFactory = JacksonFactory.getDefaultInstance(); return new Vision.Builder(GoogleNetHttpTransport.newTrustedTransport(), jsonFactory, credential) .setApplicationName(APPLICATION_NAME).build(); }
From source file:io.cloudex.cloud.impl.google.auth.CmdLineAuthenticationProvider.java
License:Apache License
/** * Create an instance of Credential/*from ww w. j a v a 2 s.com*/ * @return * @throws IOException */ protected Credential getCredential() throws IOException { Validate.notNull(this.clientSecretsFile); Validate.notNull(this.scopes); // initialize the transport try { httpTransport = GoogleNetHttpTransport.newTrustedTransport(); } catch (GeneralSecurityException e) { log.error("failed to create transport", e); throw new IOException(e); } // initialize the data store factory dataStoreFactory = new FileDataStoreFactory(DATA_STORE_DIR); // load client secrets GoogleClientSecrets clientSecrets = GoogleClientSecrets.load(JSON_FACTORY, new InputStreamReader( CmdLineAuthenticationProvider.class.getResourceAsStream(this.clientSecretsFile))); // Set up authorization code flow. GoogleAuthorizationCodeFlow flow = new GoogleAuthorizationCodeFlow.Builder(httpTransport, JSON_FACTORY, clientSecrets, scopes).setDataStoreFactory(dataStoreFactory).build(); // authorize return new AuthorizationCodeInstalledApp(flow, new LocalServerReceiver()).authorize("user"); }
From source file:io.cloudex.cloud.impl.google.GoogleCloudServiceImpl.java
License:Apache License
/** * Create a new instance of the HTTP transport * @return/*from ww w . j a v a 2 s . co m*/ * @throws IOException */ protected HttpTransport getHttpTransport() throws IOException { if (httpTransport == null) { try { httpTransport = GoogleNetHttpTransport.newTrustedTransport(); } catch (GeneralSecurityException e) { log.error("failed to create transport", e); throw new IOException(e); } } return httpTransport; }
From source file:io.druid.storage.google.GoogleStorageDruidModule.java
License:Apache License
@Provides @LazySingleton/*w w w . j a va 2s .com*/ public GoogleStorage getGoogleStorage(final GoogleAccountConfig config) throws IOException, GeneralSecurityException { LOG.info("Building Cloud Storage Client..."); HttpTransport httpTransport = GoogleNetHttpTransport.newTrustedTransport(); JsonFactory jsonFactory = JacksonFactory.getDefaultInstance(); GoogleCredential credential = GoogleCredential.getApplicationDefault(httpTransport, jsonFactory); if (credential.createScopedRequired()) { credential = credential.createScoped(StorageScopes.all()); } Storage storage = new Storage.Builder(httpTransport, jsonFactory, credential) .setApplicationName(APPLICATION_NAME).build(); return new GoogleStorage(storage); }
From source file:io.github.nathanross.listupload.GroupsMigrationBackend.java
License:Apache License
public static void initializeClient(boolean force) { try {//from www .j a v a 2s. c om //if we're not forcing a reinitialization, // and already initialized, just return; if (tokenInitializationTime > 0 && !force) { return; } tokenInitializationTime = System.currentTimeMillis(); httpTransport = GoogleNetHttpTransport.newTrustedTransport(); dataStoreFactory = new FileDataStoreFactory(new java.io.File("C:/email/store/oauth2_sample")); // service account credential (uncomment setServiceAccountUser for domain-wide delegation) cred = GroupsMigrationBackend.authorize(); setupAccessor(); // set up global GroupsMigration instance //get this by having a message sent off from your group. //in the header of the original should be a param x-google-group-id } catch (IOException e) { e.printStackTrace(); System.err.println(e.getMessage()); } catch (Throwable t) { t.printStackTrace(); } }
From source file:io.github.nathanross.listupload.GroupsMigrationBackend.java
License:Apache License
public static void sendEmailTest(String[] args) { //this is like calling initializeClient() and sendEmail() at once. // but here, the client is stored in a local variable, // and not as a class member variable. so after the email is sent // and the function ends, the client is closed. // this is kept here for easy comparison to Google's sample code. // obviously you will have to set the constants back to static to // make this work. try {//from w w w . j a v a2 s. co m // initialize the transport httpTransport = GoogleNetHttpTransport.newTrustedTransport(); dataStoreFactory = new FileDataStoreFactory(new java.io.File("C:/email/store/oauth2_sample")); // service account credential (uncomment setServiceAccountUser for domain-wide delegation) Credential cred = GroupsMigrationBackend.authorize(); // set up global GroupsMigration instance client = new GroupsMigration.Builder(httpTransport, JSON_FACTORY, cred) .setApplicationName(APPLICATION_NAME).build(); Archive accessor = client.archive(); //get this by having a message sent off from your group. //in the header of the original should be a param x-google-group-id String groupID = GROUP_EMAIL_ADDR; AbstractInputStreamContent mediaContent = new FileContent("message/rfc822", new File("test_email.eml")); Insert req = accessor.insert(groupID, mediaContent); req.setOauthToken(cred.getAccessToken()); //System.out.println("hello world"); req.execute(); } catch (IOException e) { e.printStackTrace(); System.err.println(e.getMessage()); } catch (Throwable t) { t.printStackTrace(); } System.exit(1); }
From source file:io.imaravic.log4j.logging.GoogleCloudLoggingManager.java
License:Apache License
public static GoogleCloudLoggingManager getManager(final String name, final GoogleCloudCredentials googleCloudCredentials, final String googleCloudProjectId, final String googleCloudZone, final String googleCloudLogName, final String virtualMachineId, final int maxRetryTimeMillis) { return AbstractManager.getManager(name, new ManagerFactory<GoogleCloudLoggingManager, Object>() { @Override//w w w . j ava2s . c o m public GoogleCloudLoggingManager createManager(String name, Object data) { try { final HttpTransport transport = GoogleNetHttpTransport.newTrustedTransport(); final GoogleCloudMetadata googleCloudMetadata = new GoogleCloudMetadata(transport); return new GoogleCloudLoggingManager(name, transport, googleCloudMetadata, googleCloudCredentials, googleCloudProjectId, googleCloudZone, googleCloudLogName, virtualMachineId, maxRetryTimeMillis); } catch (final Throwable e) { LOGGER.error("Failed to initialize GoogleCloudLoggingManager", e); } return null; } }, null); }
From source file:io.imaravic.log4j.pubsub.GoogleCloudPubsubManager.java
License:Apache License
public static GoogleCloudPubsubManager getManager(final String name, final GoogleCloudCredentials googleCloudCredentials, final String googleCloudProjectId, final String topic, final boolean autoCreateTopic, final int maxRetryTimeMillis) { return AbstractManager.getManager(name, new ManagerFactory<GoogleCloudPubsubManager, Object>() { @Override//w w w.java2s .com public GoogleCloudPubsubManager createManager(String name, Object data) { try { final HttpTransport transport = GoogleNetHttpTransport.newTrustedTransport(); final GoogleCloudMetadata googleCloudMetadata = new GoogleCloudMetadata(transport); return new GoogleCloudPubsubManager(name, transport, googleCloudMetadata, googleCloudCredentials, googleCloudProjectId, topic, autoCreateTopic, maxRetryTimeMillis); } catch (final Throwable e) { LOGGER.error("Failed to initialize GoogleCloudLoggingManager", e); } return null; } }, null); }
From source file:io.konig.gcp.common.GoogleCloudService.java
License:Apache License
public SQLAdmin sqlAdmin() { if (sqlAdmin == null) { try {//from ww w. ja v a2 s . com HttpTransport httpTransport = GoogleNetHttpTransport.newTrustedTransport(); JsonFactory jsonFactory = JacksonFactory.getDefaultInstance(); GoogleCredential credential = GoogleCredential.fromStream(new FileInputStream(credentialsFile)); if (credential.createScopedRequired()) { credential = credential .createScoped(Arrays.asList("https://www.googleapis.com/auth/cloud-platform")); } SQLAdmin.Builder builder = new SQLAdmin.Builder(httpTransport, jsonFactory, credential); builder = builder.setApplicationName(projectId); sqlAdmin = builder.build(); } catch (IOException e) { throw new RuntimeException(e); } catch (GeneralSecurityException e) { throw new RuntimeException(e); } catch (Exception e) { throw new RuntimeException(e); } } return sqlAdmin; }