List of usage examples for com.google.api.client.googleapis.javanet GoogleNetHttpTransport newTrustedTransport
public static NetHttpTransport newTrustedTransport() throws GeneralSecurityException, IOException
From source file:org.nuxeo.vision.google.GoogleVisionProvider.java
License:Apache License
protected com.google.api.services.vision.v1.Vision getVisionClient() throws IOException, GeneralSecurityException { // thread safe lazy initialization of the google vision client // see https://en.wikipedia.org/wiki/Double-checked_locking com.google.api.services.vision.v1.Vision result = visionClient; if (result == null) { synchronized (this) { result = visionClient;/*from w ww.ja v a2s. c o m*/ if (result == null) { GoogleCredential credential = null; if (usesServiceAccount()) { File file = new File(getCredentialFilePath()); credential = GoogleCredential.fromStream(new FileInputStream(file)) .createScoped(VisionScopes.all()); } JsonFactory jsonFactory = JacksonFactory.getDefaultInstance(); result = visionClient = new com.google.api.services.vision.v1.Vision.Builder( GoogleNetHttpTransport.newTrustedTransport(), jsonFactory, credential) .setApplicationName(getAppName()).build(); } } } return result; }
From source file:org.pentaho.di.trans.steps.googleanalytics.GoogleAnalyticsApiFacade.java
License:Open Source License
public static GoogleAnalyticsApiFacade createFor(String application, String oauthServiceAccount, String oauthKeyFile) throws GeneralSecurityException, IOException, KettleFileException { return new GoogleAnalyticsApiFacade(GoogleNetHttpTransport.newTrustedTransport(), JacksonFactory.getDefaultInstance(), application, oauthServiceAccount, new File(KettleVFS.getFileObject(oauthKeyFile).getURL().getPath())); }
From source file:org.pentaho.googledrive.vfs.GoogleDriveFileObject.java
License:Apache License
protected GoogleDriveFileObject(final AbstractFileName fileName, final GoogleDriveFileSystem fileSystem) throws FileSystemException { super(fileName, fileSystem); try {/*from w w w .j a v a2s . c o m*/ HTTP_TRANSPORT = GoogleNetHttpTransport.newTrustedTransport(); DATA_STORE_FACTORY = new CustomDataStoreFactory(DATA_STORE_DIR); driveService = getDriveService(); resolveFileMetadata(); } catch (Exception e) { throw new FileSystemException(e); } }
From source file:org.pharmgkb.common.io.google.GoogleApiHelper.java
License:Mozilla Public License
/** * Constructs a {@link GoogleCredential}. *//*from w w w .j av a2 s . c o m*/ public GoogleApiHelper(@Nonnull String userId, @Nonnull String privateKey, String... scopes) throws IOException, GeneralSecurityException { Preconditions.checkNotNull(userId); Preconditions.checkNotNull(privateKey); m_jsonFactory = GsonFactory.getDefaultInstance(); m_httpTransport = GoogleNetHttpTransport.newTrustedTransport(); m_credential = new GoogleCredential.Builder().setTransport(m_httpTransport).setJsonFactory(m_jsonFactory) .setServiceAccountId(userId).setServiceAccountPrivateKey(getPrivateKey(privateKey)) .setServiceAccountScopes(Lists.newArrayList(scopes)).build(); }
From source file:org.salvian.sonar.plugins.oauth2.provider.GoogleProvider.java
License:Apache License
@Override public GenericProfile validateTokenAndGetUser(Settings settings, OAuthJSONAccessTokenResponse tokenResponse) { try {// w w w. j a va 2 s.c om //TODO: use general method to validate Oauth2 token (instead of using 1 library per provider) HttpTransport transport = GoogleNetHttpTransport.newTrustedTransport(); JsonFactory jsonFactory = JacksonFactory.getDefaultInstance(); GoogleIdTokenVerifier verifier = new GoogleIdTokenVerifier.Builder(transport, jsonFactory) .setAudience(Collections.singletonList(settings.getString(OAuth2Client.PROPERTY_CLIENT_ID))) .build(); GoogleIdToken googleToken = verifier.verify(tokenResponse.getParam("id_token")); if (googleToken != null) { GoogleIdToken.Payload payload = googleToken.getPayload(); if (!payload.getHostedDomain().equals(PROPERTY_GOOGLE_HD)) { LOG.error("Use your " + PROPERTY_GOOGLE_HD + " google account to log in"); } GenericProfile googleProfile = new GenericProfile(); String email = payload.getEmail(); googleProfile.setEmail(email); googleProfile.setName(email.substring(0, email.indexOf("@"))); return googleProfile; } else { LOG.error("Nice try, but.. nope"); } } catch (Exception e) { LOG.error("You are not logged in"); } return null; }
From source file:org.silverpeas.core.admin.domain.driver.googledriver.GoogleDirectoryRequester.java
License:Open Source License
private Directory getDirectoryService() throws AdminException { try {/* w ww. jav a 2s . co m*/ final NetHttpTransport httpTransport = GoogleNetHttpTransport.newTrustedTransport(); return new Directory.Builder(httpTransport, JSON_FACTORY, getServiceAccountCredentials(httpTransport)) .setApplicationName(APPLICATION_NAME).build(); } catch (Exception e) { throw new AdminException(e); } }
From source file:org.skfiy.typhon.rnsd.service.handler.GooglePlayRechargingHandler.java
License:Apache License
public GooglePlayRechargingHandler() { try {/* ww w. ja va 2s . c om*/ transport = GoogleNetHttpTransport.newTrustedTransport(); PrivateKey privateKey = SecurityUtils.loadPrivateKeyFromKeyStore(SecurityUtils.getPkcs12KeyStore(), getClass().getClassLoader().getResourceAsStream("eagle7.p12"), "notasecret", "privatekey", "notasecret"); GoogleCredential credential = new GoogleCredential.Builder().setTransport(transport) .setJsonFactory(JacksonFactory.getDefaultInstance()) .setServiceAccountId( "123224341041-5j8ahccu09vst950kt6bkpu1r3l1qbta@developer.gserviceaccount.com") .setServiceAccountScopes(AndroidPublisherScopes.all()).setServiceAccountPrivateKey(privateKey) .build(); publisher = new AndroidPublisher.Builder(transport, JacksonFactory.getDefaultInstance(), credential) .build(); } catch (Exception ex) { throw new RuntimeException(ex); } }
From source file:org.sobotics.guttenberg.search.InternetSearch.java
License:Open Source License
public static void main(String[] args) throws GeneralSecurityException, IOException { String searchQuery = "test"; //The query to search String cx = "002845322276752338984:vxqzfa86nqc"; //Your search engine //Instance Customsearch Customsearch cs = new Customsearch.Builder(GoogleNetHttpTransport.newTrustedTransport(), JacksonFactory.getDefaultInstance(), null).setApplicationName("MyApplication") .setGoogleClientRequestInitializer(new CustomsearchRequestInitializer("your api key")) .build();/*from w w w. j a v a 2 s. c om*/ //Set search parameter Customsearch.Cse.List list = cs.cse().list(searchQuery).setCx(cx); //Execute search Search result = list.execute(); if (result.getItems() != null) { for (Result ri : result.getItems()) { //Get title, link, body etc. from search System.out.println(ri.getTitle() + ", " + ri.getLink()); } } }
From source file:org.sobotics.guttenberg.search.InternetSearch.java
License:Open Source License
/** * Google search/*from www . j a v a2 s . c o m*/ * * @param st * @return * @throws IOException */ public SearchResult google(Post post, SearchTerms st) throws IOException { Customsearch cs; try { cs = new Customsearch.Builder(GoogleNetHttpTransport.newTrustedTransport(), JacksonFactory.getDefaultInstance(), null).setApplicationName("Guttenberg") .setGoogleClientRequestInitializer(new CustomsearchRequestInitializer( Guttenberg.getLoginProperties().getProperty("google-api", ""))) .build(); } catch (GeneralSecurityException e) { throw new IOException("Can't instance GoogleNetHttpTransport", e); } Customsearch.Cse.List list = cs.cse().list(st.getQuery()).setCx("002845322276752338984:vxqzfa86nqc"); if (st.getExactTerm() != null) { list.setExactTerms(st.getExactTerm()); } SearchResult sr = new SearchResult(post); Search result = list.execute(); if (result.getItems() != null) { for (Result ri : result.getItems()) { boolean onsite = ri.getLink().toLowerCase().contains("stackoverflow.com"); SearchItem si = new SearchItem(ri.getTitle(), ri.getLink(), onsite); sr.getItems().add(si); } } return sr; }
From source file:org.terasology.crashreporter.logic.GoogleDriveConnector.java
License:Apache License
public GoogleDriveConnector() throws GeneralSecurityException, IOException { httpTransport = GoogleNetHttpTransport.newTrustedTransport(); credential = authorize(httpTransport); drive = new Drive.Builder(httpTransport, JSON_FACTORY, credential).setApplicationName(APPLICATION_NAME) .build();//from w ww . j ava2 s. com }