List of usage examples for com.google.api.client.googleapis GoogleUtils getCertificateTrustStore
public static synchronized KeyStore getCertificateTrustStore() throws IOException, GeneralSecurityException
From source file:com.datafrog.mms.bak.DriveSample.java
License:Apache License
public static void main(final String[] args) { Preconditions.checkArgument(//from w w w .j a v a 2 s . co m !UPLOAD_FILE_PATH.startsWith("Enter ") && !DIR_FOR_DOWNLOADS.startsWith("Enter "), "Please enter the upload file path and download directory in %s", DriveSample.class); try { NetHttpTransport.Builder builder = new NetHttpTransport.Builder(); builder.trustCertificates(GoogleUtils.getCertificateTrustStore()); builder.setProxy( new Proxy(Proxy.Type.HTTP, new InetSocketAddress("rb-proxy-unix-de01.bosch.com", 8080))); Authenticator authenticator = new Authenticator() { @Override public PasswordAuthentication getPasswordAuthentication() { return (new PasswordAuthentication("csk1kor", "bosch.password3".toCharArray())); } }; Authenticator.setDefault(authenticator); // httpTransport = GoogleNetHttpTransport.newTrustedTransport(); httpTransport = builder.build(); dataStoreFactory = new MemoryDataStoreFactory();// 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 View.header1("Starting Resumable Media Upload"); File uploadedFile = uploadFile(false); View.header1("Updating Uploaded File Name"); File updatedFile = updateFileWithTestSuffix(uploadedFile.getId()); View.header1("Starting Resumable Media Download"); downloadFile(false, updatedFile); View.header1("Starting Simple Media Upload"); uploadedFile = uploadFile(true); View.header1("Starting Simple Media Download"); downloadFile(true, uploadedFile); View.header1("Success!"); return; } catch (IOException e) { e.printStackTrace(); System.err.println(e.getMessage()); } catch (Throwable t) { t.printStackTrace(); } System.exit(1); }
From source file:com.google.cloud.hadoop.util.HttpTransportFactory.java
License:Open Source License
/** * Create an {@link ApacheHttpTransport} for calling Google APIs with an optional HTTP proxy. * * @param proxy Optional HTTP proxy to use with the transport. * @return The resulting HttpTransport./*from w ww .j a v a 2 s. c o m*/ * @throws IOException If there is an issue connecting to Google's certification server. * @throws GeneralSecurityException If there is a security issue with the keystore. */ public static ApacheHttpTransport createApacheHttpTransport(@Nullable HttpHost proxy) throws IOException, GeneralSecurityException { ApacheHttpTransport.Builder builder = new ApacheHttpTransport.Builder(); builder.trustCertificates(GoogleUtils.getCertificateTrustStore()); builder.setProxy(proxy); return builder.build(); }
From source file:com.google.cloud.hadoop.util.HttpTransportFactory.java
License:Open Source License
/** * Create an {@link NetHttpTransport} for calling Google APIs with an optional HTTP proxy. * * @param proxy Optional HTTP proxy to use with the transport. * @return The resulting HttpTransport.//from w w w . j a v a 2 s . c om * @throws IOException If there is an issue connecting to Google's certification server. * @throws GeneralSecurityException If there is a security issue with the keystore. */ public static NetHttpTransport createNetHttpTransport(@Nullable Proxy proxy) throws IOException, GeneralSecurityException { NetHttpTransport.Builder builder = new NetHttpTransport.Builder(); builder.trustCertificates(GoogleUtils.getCertificateTrustStore()); builder.setProxy(proxy); return builder.build(); }
From source file:gobblin.source.extractor.extract.google.GoogleCommon.java
License:Apache License
/** * Provides HttpTransport. If both proxyUrl and postStr is defined, it provides transport with Proxy. * @param proxyUrl Optional./*from w ww . ja v a 2 s.co m*/ * @param portStr Optional. String type for port so that user can easily pass null. (e.g: state.getProp(key)) * @return * @throws NumberFormatException * @throws GeneralSecurityException * @throws IOException */ public static HttpTransport newTransport(String proxyUrl, String portStr) throws NumberFormatException, GeneralSecurityException, IOException { if (!StringUtils.isEmpty(proxyUrl) && !StringUtils.isEmpty(portStr)) { return new NetHttpTransport.Builder().trustCertificates(GoogleUtils.getCertificateTrustStore()) .setProxy( new Proxy(Proxy.Type.HTTP, new InetSocketAddress(proxyUrl, Integer.parseInt(portStr)))) .build(); } return GoogleNetHttpTransport.newTrustedTransport(); }