Example usage for com.google.api.client.googleapis.javanet GoogleNetHttpTransport newTrustedTransport

List of usage examples for com.google.api.client.googleapis.javanet GoogleNetHttpTransport newTrustedTransport

Introduction

In this page you can find the example usage for com.google.api.client.googleapis.javanet GoogleNetHttpTransport newTrustedTransport.

Prototype

public static NetHttpTransport newTrustedTransport() throws GeneralSecurityException, IOException 

Source Link

Document

Returns a new instance of NetHttpTransport that uses GoogleUtils#getCertificateTrustStore() for the trusted certificates using com.google.api.client.http.javanet.NetHttpTransport.Builder#trustCertificates(KeyStore) .

Usage

From source file:com.macquarie.analytics.CoreReportingApiReferenceSample.java

License:Apache License

/**
 * Main demo. This first initializes an Analytics service object. It then queries for the top 25
 * organic search keywords and traffic sources by visits. Finally each important part of the
 * response is printed to the screen./*w  ww  . j av a  2s .c om*/
 *
 * @param args command line args.
 */
public static void main(String[] args) {
    try {
        HTTP_TRANSPORT = GoogleNetHttpTransport.newTrustedTransport();
        DATA_STORE_FACTORY = new FileDataStoreFactory(DATA_STORE_DIR);
        Analytics analytics = initializeAnalytics();
        GaData gaData = executeDataQuery(analytics, TABLE_ID);

        printReportInfo(gaData);
        printProfileInfo(gaData);
        printQueryInfo(gaData);
        printPaginationInfo(gaData);
        printTotalsForAllResults(gaData);
        printColumnHeaders(gaData);
        printDataTable(gaData);

    } catch (GoogleJsonResponseException e) {
        System.err.println(
                "There was a service error: " + e.getDetails().getCode() + " : " + e.getDetails().getMessage());
    } catch (Throwable t) {
        t.printStackTrace();
    }
}

From source file:com.macquarie.analytics.HelloAnalyticsApiSample.java

License:Apache License

/**
 * Main demo. This first initializes an analytics service object. It then uses the Google
 * Analytics Management API to get the first profile ID for the authorized user. It then uses the
 * Core Reporting API to retrieve the top 25 organic search terms. Finally the results are printed
 * to the screen. If an API error occurs, it is printed here.
 *
 * @param args command line args./*from   w w w. j  a  v  a 2  s .  c o  m*/
 */
public static void main(String[] args) {
    try {
        httpTransport = GoogleNetHttpTransport.newTrustedTransport();
        dataStoreFactory = new FileDataStoreFactory(DATA_STORE_DIR);
        Analytics analytics = initializeAnalytics();
        String profileId = getFirstProfileId(analytics);
        if (profileId == null) {
            System.err.println("No profiles found.");
        } else {
            GaData gaData = executeDataQuery(analytics, profileId);
            printGaData(gaData);
        }
    } catch (GoogleJsonResponseException e) {
        System.err.println(
                "There was a service error: " + e.getDetails().getCode() + " : " + e.getDetails().getMessage());
    } catch (Throwable t) {
        t.printStackTrace();
    }
}

From source file:com.macquarie.analytics.ManagementApiReferenceSample.java

License:Apache License

/**
 * Main demo. An Analytics service object is instantiated and then it is used to traverse and
 * print all the Management API entities. If any exceptions occur, they are caught and printed.
 *
 * @param args command line args.//  w  ww . j a v  a 2  s.  com
 */
public static void main(String args[]) {
    try {
        HTTP_TRANSPORT = GoogleNetHttpTransport.newTrustedTransport();
        DATA_STORE_FACTORY = new FileDataStoreFactory(DATA_STORE_DIR);
        Analytics analytics = initializeAnalytics();
        printManagementEntities(analytics);

    } catch (GoogleJsonResponseException e) {
        System.err.println(
                "There was a service error: " + e.getDetails().getCode() + " : " + e.getDetails().getMessage());
    } catch (Throwable t) {
        t.printStackTrace();
    }
}

From source file:com.macquarie.analytics.McfReportingApiReferenceSample.java

License:Apache License

/**
 * Main demo. This first initializes an analytics service object. It then uses the MCF API to
 * retrieve the top 25 source paths with most total conversions. It will also retrieve the top 25
 * organic sources with most total conversions. Finally the results are printed to the screen. If
 * an API error occurs, it is printed here.
 *
 * @param args command line args./*from   w ww  . j  a  va 2  s  .c  om*/
 */
public static void main(String[] args) {
    try {
        HTTP_TRANSPORT = GoogleNetHttpTransport.newTrustedTransport();
        DATA_STORE_FACTORY = new FileDataStoreFactory(DATA_STORE_DIR);
        Analytics analytics = initializeAnalytics();

        McfData mcfPathData = executePathQuery(analytics, TABLE_ID);
        printAllInfo(mcfPathData);

        McfData mcfInteractionData = executeInteractionQuery(analytics, TABLE_ID);
        printAllInfo(mcfInteractionData);

    } catch (GoogleJsonResponseException e) {
        System.err.println(
                "There was a service error: " + e.getDetails().getCode() + " : " + e.getDetails().getMessage());
    } catch (Throwable t) {
        t.printStackTrace();
    }
}

From source file:com.madhu.oauth2.OAuth2Sample.java

License:Apache License

public static void main(String[] args) {
    try {/*from w  w  w  . j ava 2s.c  om*/
        httpTransport = GoogleNetHttpTransport.newTrustedTransport();
        dataStoreFactory = new FileDataStoreFactory(DATA_STORE_DIR);
        // authorization
        Credential credential = authorize();
        // set up global Oauth2 instance
        oauth2 = new Oauth2.Builder(httpTransport, JSON_FACTORY, credential)
                .setApplicationName(APPLICATION_NAME).build();
        // run commands
        tokenInfo(credential.getAccessToken());
        userInfo();
        // success!
        return;
    } catch (IOException e) {
        System.err.println(e.getMessage());
    } catch (Throwable t) {
        t.printStackTrace();
    }
    System.exit(1);
}

From source file:com.neology.google.AuthorizeGoogleUser.java

License:Open Source License

public static void doLogin(String user) {
    try {/* w w w  . j  a  v  a 2s  . c  o  m*/
        httpTransport = GoogleNetHttpTransport.newTrustedTransport();
        dataStoreFactory = new FileDataStoreFactory(DATA_STORE_DIR);
        Credential credential = authorize(user);
        oauth2 = new Oauth2.Builder(httpTransport, JSON_FACTORY, credential)
                .setApplicationName(APPLICATION_NAME).build();
        String picture = oauth2.userinfo().get().execute().getPicture();
        //name = oauth2.userinfo().get().execute().getName();
        downloadProfileImage(picture, user.toLowerCase());

    } catch (IOException e) {
        System.err.println(e.getMessage());
    } catch (Exception t) {

    }
}

From source file:com.netflix.spinnaker.clouddriver.artifacts.gcs.GcsArtifactCredentials.java

License:Apache License

public GcsArtifactCredentials(String applicationName, GcsArtifactAccount account)
        throws IOException, GeneralSecurityException {
    HttpTransport transport = GoogleNetHttpTransport.newTrustedTransport();
    JsonFactory jsonFactory = JacksonFactory.getDefaultInstance();
    String credentialsPath = account.getJsonPath();

    GoogleCredential credential;//from   ww w.java  2 s.  c om

    if (!StringUtils.isEmpty(credentialsPath)) {
        FileInputStream stream = new FileInputStream(credentialsPath);
        credential = GoogleCredential.fromStream(stream, transport, jsonFactory)
                .createScoped(Collections.singleton(StorageScopes.DEVSTORAGE_READ_ONLY));

        log.info("Loaded credentials from {}", credentialsPath);
    } else {
        log.info(
                "artifacts.gcs.enabled without artifacts.gcs.[].jsonPath. Using default application credentials.");

        credential = GoogleCredential.getApplicationDefault();
    }

    name = account.getName();
    storage = new Storage.Builder(transport, jsonFactory, credential).setApplicationName(applicationName)
            .build();
}

From source file:com.netflix.spinnaker.clouddriver.google.security.GoogleNamedAccountCredentials.java

License:Apache License

private HttpTransport buildHttpTransport() {
    try {/*from  www .  java  2 s . c  o  m*/
        return GoogleNetHttpTransport.newTrustedTransport();
    } catch (Exception e) {
        throw new RuntimeException("Failed to create trusted transport", e);
    }
}

From source file:com.netflix.spinnaker.front50.model.GcsStorageService.java

License:Apache License

public GcsStorageService(String bucketName, String bucketLocation, String basePath, String projectName,
        String credentialsPath, String applicationVersion, String dataFilename) {
    Storage storage;//  w  w w  .  j ava 2 s .co m

    try {
        HttpTransport httpTransport = GoogleNetHttpTransport.newTrustedTransport();
        JsonFactory jsonFactory = JacksonFactory.getDefaultInstance();
        GoogleCredential credential = loadCredential(httpTransport, jsonFactory, credentialsPath);

        String applicationName = "Spinnaker/" + applicationVersion;
        storage = new Storage.Builder(httpTransport, jsonFactory, credential)
                .setApplicationName(applicationName).build();
    } catch (IOException | java.security.GeneralSecurityException e) {
        throw new IllegalStateException(e);
    }

    this.bucketName = bucketName;
    this.bucketLocation = bucketLocation;
    this.basePath = basePath;
    this.projectName = projectName;
    this.storage = storage;
    this.obj_api = this.storage.objects();
    this.dataFilename = dataFilename;
}

From source file:com.netflix.spinnaker.halyard.core.provider.v1.google.GoogleCredentials.java

License:Apache License

public static HttpTransport buildHttpTransport() {
    try {//from   w  w w. j a v  a2s. c o m
        return GoogleNetHttpTransport.newTrustedTransport();
    } catch (GeneralSecurityException | IOException e) {
        throw new RuntimeException("Failed to build trusted transport", e);
    }
}