List of usage examples for com.google.api.client.googleapis.javanet GoogleNetHttpTransport newTrustedTransport
public static NetHttpTransport newTrustedTransport() throws GeneralSecurityException, IOException
From source file:couk.cleverthinking.tof.Main.java
License:Open Source License
/** * initialise the Google library Oauth objects */// w ww. j a va2s.c o m private static void oauthInit() { JSON_FACTORY = JacksonFactory.getDefaultInstance(); try { HTTP_TRANSPORT = GoogleNetHttpTransport.newTrustedTransport(); } catch (Exception e) { e.printStackTrace(); l("[M57] Fatal Error. Could not create HTTP Transport " + e); } }
From source file:custom.application.login.java
License:Apache License
public String oAuth2callback() throws ApplicationException { HttpServletRequest request = (HttpServletRequest) this.context.getAttribute("HTTP_REQUEST"); HttpServletResponse response = (HttpServletResponse) this.context.getAttribute("HTTP_RESPONSE"); Reforward reforward = new Reforward(request, response); TokenResponse oauth2_response;/*from w ww . jav a2 s .c o m*/ try { if (this.getVariable("google_client_secrets") == null) { clientSecrets = GoogleClientSecrets.load(JSON_FACTORY, new InputStreamReader(login.class.getResourceAsStream("/clients_secrets.json"))); if (clientSecrets.getDetails().getClientId().startsWith("Enter") || clientSecrets.getDetails().getClientSecret().startsWith("Enter ")) { System.out.println("Enter Client ID and Secret from https://code.google.com/apis/console/ "); } this.setVariable(new ObjectVariable("google_client_secrets", clientSecrets)); } else clientSecrets = (GoogleClientSecrets) this.getVariable("google_client_secrets").getValue(); GoogleAuthorizationCodeFlow flow = new GoogleAuthorizationCodeFlow.Builder( GoogleNetHttpTransport.newTrustedTransport(), JSON_FACTORY, clientSecrets, SCOPES).build(); oauth2_response = flow.newTokenRequest(request.getParameter("code")) .setRedirectUri(this.getLink("oauth2callback")).execute(); System.out.println("Ok:" + oauth2_response.toPrettyString()); } catch (IOException e1) { // TODO Auto-generated catch block throw new ApplicationException(e1.getMessage(), e1); } catch (GeneralSecurityException e) { // TODO Auto-generated catch block throw new ApplicationException(e.getMessage(), e); } try { HttpClient httpClient = new DefaultHttpClient(); String url = "https://www.google.com/m8/feeds/contacts/default/full"; url = "https://www.googleapis.com/oauth2/v1/userinfo"; HttpGet httpget = new HttpGet(url + "?access_token=" + oauth2_response.getAccessToken()); httpClient.getParams().setParameter(HttpProtocolParams.HTTP_CONTENT_CHARSET, "UTF-8"); HttpResponse http_response = httpClient.execute(httpget); HeaderIterator iterator = http_response.headerIterator(); while (iterator.hasNext()) { Header next = iterator.nextHeader(); System.out.println(next.getName() + ":" + next.getValue()); } InputStream instream = http_response.getEntity().getContent(); ByteArrayOutputStream out = new ByteArrayOutputStream(); byte[] bytes = new byte[1024]; int len; while ((len = instream.read(bytes)) != -1) { out.write(bytes, 0, len); } instream.close(); out.close(); Struct struct = new Builder(); struct.parse(new String(out.toByteArray(), "utf-8")); this.usr = new User(); this.usr.setEmail(struct.toData().getFieldInfo("email").stringValue()); if (this.usr.findOneByKey("email", this.usr.getEmail()).size() == 0) { usr.setPassword(""); usr.setUsername(usr.getEmail()); usr.setLastloginIP(request.getRemoteAddr()); usr.setLastloginTime(new Date()); usr.setRegistrationTime(new Date()); usr.append(); } new passport(request, response, "waslogined").setLoginAsUser(this.usr.getId()); reforward.setDefault(URLDecoder.decode(this.getVariable("from").getValue().toString(), "utf8")); reforward.forward(); return new String(out.toByteArray(), "utf-8"); } catch (ClientProtocolException e) { throw new ApplicationException(e.getMessage(), e); } catch (IOException e) { throw new ApplicationException(e.getMessage(), e); } catch (ParseException e) { throw new ApplicationException(e.getMessage(), e); } }
From source file:de.elomagic.mag.google.BatchGoogleDriveClientFactory.java
License:Apache License
public BatchGoogleDriveClientFactory() { try {//from w w w . j a v a 2s . c om this.httpTransport = GoogleNetHttpTransport.newTrustedTransport();//new NetHttpTransport(); } catch (Exception ex) { LOGGER.error(ex.getMessage(), ex); } }
From source file:de.elomagic.mag.google.DriveService.java
License:Apache License
/** * Build and return an authorized Drive client service. * * @param credential/*ww w. ja v a 2s . c om*/ * @return Returns an authorized Drive client service or null when something went wrong */ public static Drive getDriveService(final Credential credential) { Drive result = null; try { HttpTransport httpTransport = GoogleNetHttpTransport.newTrustedTransport();//new NetHttpTransport(); result = new Drive.Builder(httpTransport, JacksonFactory.getDefaultInstance(), credential) .setApplicationName("MailAttachmentGateway").build(); } catch (Exception ex) { LOGGER.error(ex.getMessage(), ex); } return result; }
From source file:de.pfabulist.googledrive.GoogleDriveElsewhere.java
License:BSD License
public GoogleDriveElsewhere(Path credentialStore) { try {//from www. ja v a2s . c o m this.httpTransport = GoogleNetHttpTransport.newTrustedTransport(); dataStoreFactory = new FileDataStoreFactory(credentialStore.toFile()); } catch (GeneralSecurityException | IOException e) { throw u(e); } try { credential = authorize(GoogleDriveElsewhere.class.getResourceAsStream("/client_secrets.json")); } catch (Exception e) { throw u(e); } drive = new Drive.Builder(httpTransport, JSON_FACTORY, credential).setApplicationName(APPLICATION_NAME) .build(); }
From source file:de.tbosch.tools.googleapps.googleplus.PlusSample.java
License:Apache License
public static void main(String[] args) { try {/* w ww.j a v a2 s.c o m*/ httpTransport = GoogleNetHttpTransport.newTrustedTransport(); dataStoreFactory = new FileDataStoreFactory(DATA_STORE_DIR); // authorization Credential credential = authorize(); // set up global Plus instance plus = new Plus.Builder(httpTransport, JSON_FACTORY, credential).setApplicationName(APPLICATION_NAME) .build(); // run commands listActivities(); getActivity(); getProfile(); getEmails(credential); getCalendar(); getAllContacts(credential); getUserinfo(credential); // success! return; } catch (IOException e) { System.err.println(e.getMessage()); } catch (Throwable t) { t.printStackTrace(); } System.exit(1); }
From source file:de.vproductions.pdi.plugin.step.googleanalyticsmanagementapi.GoogleAnalyticsManagementApiFramework.java
License:Apache License
public static GoogleAnalyticsManagementApiFramework createFor(String application, String oauthServiceAccount, String oauthKeyFile)/*from w w w. ja va2 s . co m*/ throws GeneralSecurityException, IOException, KettleFileException { return new GoogleAnalyticsManagementApiFramework(GoogleNetHttpTransport.newTrustedTransport(), JacksonFactory.getDefaultInstance(), application, oauthServiceAccount, new File(KettleVFS.getFileObject(oauthKeyFile).getURL().getPath())); }
From source file:Diary.DriveSample.java
License:Apache License
public void mainfunc() throws InterruptedException { if (netIsAvailable()) { downloadstatus.setText("It will take some time , Please wait . . ."); downloadstatus.setText("Congrats! Your secrets are on your cloud :) "); btn.setVisible(false);// w w w . ja va 2 s. co m Thread.sleep(2000); } else if (!netIsAvailable()) { downloadstatus.setText("Seems like you are not connected to Internet!"); btn.setText("Retry"); } Preconditions.checkArgument( !UPLOAD_FILE_PATH.startsWith("Enter ") && !DIR_FOR_DOWNLOADS.startsWith("Enter "), "Please enter the upload file path and download directory in %s", DriveSample.class); try { httpTransport = GoogleNetHttpTransport.newTrustedTransport(); dataStoreFactory = new FileDataStoreFactory(DATA_STORE_DIR); // authorization Credential credential = authorize(); // set up the global Drive instance drive = new Drive.Builder(httpTransport, JSON_FACTORY, credential).setApplicationName(APPLICATION_NAME) .build(); // run commands //downloadstatus.setText("Starting Resumable Media Upload"); //View.header1("Starting Resumable Media Upload"); //File uploadedFile = uploadFile(false); //downloadstatus.setText("Updating Uploaded File Name"); //View.header1("Updating Uploaded File Name"); //File updatedFile = updateFileWithTestSuffix(uploadedFile.getId()); //downloadstatus.setText("Starting Resumable Media Download"); View.header1("Starting Simple Media Upload"); uploadFile(true); ///View.header1("Success!"); return; } catch (IOException e) { System.err.println(e.getMessage()); } catch (Throwable t) { t.printStackTrace(); } }
From source file:domain.bsu.dektiarev.service.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);*/ GoogleCredential credential = GoogleCredential .fromStream(new FileInputStream("resources/APNewsFeed-7e0946ab6fb1.json")) .createScoped(Collections.singleton(StorageScopes.DEVSTORAGE_READ_WRITE)); if (credential.createScopedRequired()) { Collection<String> bigqueryScopes = StorageScopes.all(); credential = credential.createScoped(bigqueryScopes); }/*from w ww. java2s . c o m*/ return new Storage.Builder(transport, jsonFactory, credential).setApplicationName("newsfeedforhybridcloud") .build(); }
From source file:edu.internet2.middleware.changelogconsumer.googleapps.GoogleGrouperConnector.java
License:Open Source License
public void initialize(String consumerName, final GoogleAppsSyncProperties properties) throws GeneralSecurityException, IOException { this.consumerName = consumerName; this.properties = properties; final HttpTransport httpTransport = GoogleNetHttpTransport.newTrustedTransport(); final GoogleCredential googleDirectoryCredential = GoogleAppsSdkUtils.getGoogleDirectoryCredential( properties.getServiceAccountEmail(), properties.getServiceAccountPKCS12FilePath(), properties.getServiceImpersonationUser(), httpTransport, JSON_FACTORY); final GoogleCredential googleGroupssettingsCredential = GoogleAppsSdkUtils .getGoogleGroupssettingsCredential(properties.getServiceAccountEmail(), properties.getServiceAccountPKCS12FilePath(), properties.getServiceImpersonationUser(), httpTransport, JSON_FACTORY); directoryClient = new Directory.Builder(httpTransport, JSON_FACTORY, googleDirectoryCredential) .setApplicationName("Google Apps Grouper Provisioner").build(); groupssettingsClient = new Groupssettings.Builder(httpTransport, JSON_FACTORY, googleGroupssettingsCredential).setApplicationName("Google Apps Grouper Provisioner").build(); addressFormatter.setGroupIdentifierExpression(properties.getGroupIdentifierExpression()) .setSubjectIdentifierExpression(properties.getSubjectIdentifierExpression()) .setDomain(properties.getGoogleDomain()); GoogleCacheManager.googleUsers().setCacheValidity(properties.getGoogleUserCacheValidity()); GoogleCacheManager.googleGroups().setCacheValidity(properties.getGoogleGroupCacheValidity()); grouperSubjects.setCacheValidity(5); grouperSubjects.seed(1000);/*from ww w.java 2 s. c o m*/ grouperGroups.setCacheValidity(5); grouperGroups.seed(100); recentlyManipulatedObjectsList = new RecentlyManipulatedObjectsList( properties.getRecentlyManipulatedQueueSize(), properties.getRecentlyManipulatedQueueDelay()); }