List of usage examples for com.google.api.client.googleapis.javanet GoogleNetHttpTransport newTrustedTransport
public static NetHttpTransport newTrustedTransport() throws GeneralSecurityException, IOException
From source file:cloud.google.com.windows.example.ExampleCode.java
License:Open Source License
public static void main(String[] args) { ExampleCode ec = new ExampleCode(); try {/*from w w w .j a v a 2 s . co m*/ // Initialize Transport object. httpTransport = GoogleNetHttpTransport.newTrustedTransport(); // Reset the password. ec.resetPassword(); } catch (Exception e) { e.printStackTrace(); System.exit(1); } }
From source file:com.aalmeida.lightning.external.auth.GoogleAuthorizationImpl.java
License:Apache License
/** * Instantiates a new google authorization impl. * * @param pUrl/* w w w . j av a 2 s . co m*/ * the url * @param pAppName * the app name * @param pLog * the log */ public GoogleAuthorizationImpl(String pUrl, String pAppName, Logger pLog) { super(null, pLog); appName = pAppName; try { jsonFactory = JacksonFactory.getDefaultInstance(); httpTransport = GoogleNetHttpTransport.newTrustedTransport(); dataStoreFactory = new FileDataStoreFactory(new File(".store/BillsManagement")); if (credential == null) { credential = authorize(pUrl); } isAuthorized = true; } catch (Exception e) { isAuthorized = false; this.log.error(e); } }
From source file:com.appengine.pubsub.HelloAppEngine.java
License:Open Source License
public void initialize() throws Exception { System.out.println("Initialize the Google APIs Client Library client"); log.info("Initialize the Google APIs Client Library client with logger"); // build the transport NetHttpTransport httpTransport = GoogleNetHttpTransport.newTrustedTransport(); JacksonFactory jsonFactory = JacksonFactory.getDefaultInstance(); // get the credentials List<String> scopeList = Arrays.asList(ALL_SCOPES); GoogleCredential credential = GoogleCredential.getApplicationDefault(); if (credential.createScopedRequired()) { credential = credential.createScoped(scopeList); }//from w w w .jav a2 s. c o m // create the client stub this.client = new Pubsub.Builder(httpTransport, jsonFactory, credential) .setApplicationName(APPLICATION_NAME).build(); }
From source file:com.arm.connector.bridge.coordinator.processors.google.GoogleCloudMQTTProcessor.java
License:Open Source License
private CloudIot createCloudIoTInstance() { CloudIot inst = null;/*from w w w . j a v a2 s. co m*/ // Log into Google Cloud this.m_google_cloud_logged_in = this.googleCloudLogin(this.m_google_cloud_project_id, this.m_google_cloud_auth_json); if (this.m_google_cloud_logged_in == true) { try { // JSON factory JsonFactory jsonFactory = JacksonFactory.getDefaultInstance(); // setup the Http wrapper HttpRequestInitializer init = new RetryHttpInitializerWrapper(this.m_credential); // create the CloudIot instance inst = new CloudIot.Builder(GoogleNetHttpTransport.newTrustedTransport(), jsonFactory, init) .setApplicationName(this.m_google_cloud_application_name).build(); } catch (GeneralSecurityException | IOException ex) { this.errorLogger().critical("Google: Unable to create CloudIot instance: " + ex.getMessage()); inst = null; } } // return our instance return inst; }
From source file:com.arm.connector.bridge.coordinator.processors.google.GoogleCloudMQTTProcessor.java
License:Open Source License
private Pubsub createPubSubInstance() { Pubsub inst = null;//from ww w . j a v a2s . co m // only if logged in... if (this.m_google_cloud_logged_in == true) { try { // JSON factory JsonFactory jsonFactory = JacksonFactory.getDefaultInstance(); // setup the Http wrapper HttpRequestInitializer init = new RetryHttpInitializerWrapper(this.m_credential); // create the Pubsub instance inst = new Pubsub.Builder(GoogleNetHttpTransport.newTrustedTransport(), jsonFactory, init) .setApplicationName(this.m_google_cloud_application_name).build(); } catch (GeneralSecurityException | IOException ex) { this.errorLogger().critical("Google: Unable to create Pubsub instance: " + ex.getMessage()); inst = null; } } // return our instance return inst; }
From source file:com.bucketoperations.controller.StorageFactory.java
License:Open Source License
private static Storage buildService() throws IOException, GeneralSecurityException { HttpTransport transport = GoogleNetHttpTransport.newTrustedTransport(); JsonFactory jsonFactory = new JacksonFactory(); GoogleCredential credential = GoogleCredential.getApplicationDefault(transport, jsonFactory); // Depending on the environment that provides the default credentials (for // example: Compute Engine, App Engine), the credentials may require us to // specify the scopes we need explicitly. Check for this case, and inject // the Cloud Storage scope if required. if (credential.createScopedRequired()) { Collection<String> scopes = StorageScopes.all(); credential = credential.createScoped(scopes); }//from w ww . ja va 2s . c om return new Storage.Builder(transport, jsonFactory, credential).setApplicationName("Data_upload").build(); }
From source file:com.cloudera.director.google.internal.GoogleCredentials.java
License:Apache License
private Compute buildCompute() { try {//from w w w.j a v a 2s. c o m JsonFactory JSON_FACTORY = JacksonFactory.getDefaultInstance(); HttpTransport httpTransport = GoogleNetHttpTransport.newTrustedTransport(); GoogleCredential credential; if (jsonKey != null) { credential = GoogleCredential .fromStream(new ByteArrayInputStream(jsonKey.getBytes()), httpTransport, JSON_FACTORY) .createScoped(Collections.singleton(ComputeScopes.COMPUTE)); } else { Collection COMPUTE_SCOPES = Collections.singletonList(ComputeScopes.COMPUTE); credential = GoogleCredential.getApplicationDefault(httpTransport, JSON_FACTORY) .createScoped(COMPUTE_SCOPES); } return new Compute.Builder(httpTransport, JSON_FACTORY, null) .setApplicationName(Names.buildApplicationNameVersionTag(applicationProperties)) .setHttpRequestInitializer(credential).build(); } catch (Exception e) { throw new RuntimeException(e); } }
From source file:com.cloudera.director.google.internal.GoogleCredentials.java
License:Apache License
private SQLAdmin buildSQLAdmin() { try {/*from ww w .j a va2s .c o m*/ JsonFactory JSON_FACTORY = JacksonFactory.getDefaultInstance(); HttpTransport httpTransport = GoogleNetHttpTransport.newTrustedTransport(); GoogleCredential credential; if (jsonKey != null) { credential = GoogleCredential .fromStream(new ByteArrayInputStream(jsonKey.getBytes()), httpTransport, JSON_FACTORY) .createScoped(Collections.singleton(SQLAdminScopes.SQLSERVICE_ADMIN)); } else { Collection SQLSERVICE_ADMIN_SCOPES = Collections.singletonList(SQLAdminScopes.SQLSERVICE_ADMIN); credential = GoogleCredential.getApplicationDefault(httpTransport, JSON_FACTORY) .createScoped(SQLSERVICE_ADMIN_SCOPES); } return new SQLAdmin.Builder(httpTransport, JSON_FACTORY, null) .setApplicationName(Names.buildApplicationNameVersionTag(applicationProperties)) .setHttpRequestInitializer(credential).build(); } catch (Exception e) { throw new RuntimeException(e); } }
From source file:com.cmh.SslSocketFactory.java
License:Open Source License
private static SQLAdmin createAdminApiClient(Credential credential) { HttpTransport httpTransport;//from ww w. j a v a 2 s .c o m try { httpTransport = GoogleNetHttpTransport.newTrustedTransport(); } catch (GeneralSecurityException | IOException e) { throw new RuntimeException("Unable to initialize HTTP transport", e); } String rootUrl = System.getProperty(API_ROOT_URL_PROPERTY); String servicePath = System.getProperty(API_SERVICE_PATH_PROPERTY); JsonFactory jsonFactory = JacksonFactory.getDefaultInstance(); SQLAdmin.Builder adminApiBuilder = new Builder(httpTransport, jsonFactory, credential) .setApplicationName("Cloud SQL Java Socket Factory"); if (rootUrl != null) { logTestPropertyWarning(API_ROOT_URL_PROPERTY); adminApiBuilder.setRootUrl(rootUrl); } if (servicePath != null) { logTestPropertyWarning(API_SERVICE_PATH_PROPERTY); adminApiBuilder.setServicePath(servicePath); } return adminApiBuilder.build(); }
From source file:com.codeu.team34.label.LabelApp.java
License:Open Source License
/** * Connects to the Vision API using Application Default Credentials. *///from w w w .j a va2s. c om public static Vision getVisionService() throws IOException, GeneralSecurityException { GoogleCredential credential = GoogleCredential.getApplicationDefault().createScoped(VisionScopes.all()); JsonFactory jsonFactory = JacksonFactory.getDefaultInstance(); return new Vision.Builder(GoogleNetHttpTransport.newTrustedTransport(), jsonFactory, credential) .setApplicationName(APPLICATION_NAME).build(); }