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:org.esn.esobase.data.GoogleDocsService.java

private static Credential authorize2() throws Exception {
    // load client secrets
    FileDataStoreFactory dataStoreFactory = new FileDataStoreFactory(new File("/home/scraelos/"));
    NetHttpTransport httpTransport = GoogleNetHttpTransport.newTrustedTransport();
    JsonFactory jsonFactory = JacksonFactory.getDefaultInstance();
    GoogleClientSecrets clientSecrets = GoogleClientSecrets.load(jsonFactory,
            new InputStreamReader(new FileInputStream(
                    "/home/scraelos/client_secret_949902383727-vijtpirvq0i6q4lnsua6bn44v9441dpa.apps.googleusercontent.com.json")));

    // set up authorization code flow
    GoogleAuthorizationCodeFlow flow = new GoogleAuthorizationCodeFlow.Builder(httpTransport, jsonFactory,
            clientSecrets, Collections.singleton("https://spreadsheets.google.com/feeds"))
                    .setAccessType("offline").setDataStoreFactory(dataStoreFactory).build();
    // authorize//from  ww w .  ja va2  s. c o  m
    return new AuthorizationCodeInstalledApp(flow, new LocalServerReceiver()).authorize("user");
}

From source file:org.excalibur.driver.google.compute.GoogleCompute.java

License:Open Source License

public GoogleCompute(UserProviderCredentials credentials) {
    this.credentials_ = checkNotNull(credentials, "[%s] credential is null", this.getClass().getName());

    checkState(!isNullOrEmpty(credentials.getLoginCredentials().getCredentialName()),
            "[%s] credential is null or empty [%s]", this.getClass().getName(),
            credentials.getLoginCredentials().getCredentialName());

    checkNotNull(credentials.getRegion(), "[%s] region is null", this.getClass().getName());
    checkState(!isNullOrEmpty(credentials.getRegion().getName()), "[%s] region's name is null",
            this.getClass().getName());
    checkState(!isNullOrEmpty(credentials.getRegion().getEndpoint()), "[%s] region's endpoint is null",
            this.getClass().getName());

    try {//from  www . ja v a2s.co  m
        httpTransport = GoogleNetHttpTransport.newTrustedTransport();
        Credential credential = authorize();
        compute = new Compute.Builder(httpTransport, JSON_FACTORY, null).setHttpRequestInitializer(credential)
                .setApplicationName("excalibur").build();

    } catch (IOException | GeneralSecurityException e) {
        throw new RuntimeException(e);
    }
}

From source file:org.geocachingtools.geoui.OAuthServlet.java

License:Open Source License

/**
 * Processes requests for both HTTP <code>GET</code> and <code>POST</code>
 * methods.//from   w w  w  .j a v  a  2  s  . co m
 *
 * @param request servlet request
 * @param response servlet response
 * @throws ServletException if a servlet-specific error occurs
 * @throws IOException if an I/O error occurs
 */
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    try {
        // Set up the HTTP transport and JSON factory
        HttpTransport transport = GoogleNetHttpTransport.newTrustedTransport();
        JsonFactory jsonFactory = JacksonFactory.getDefaultInstance();

        GoogleIdTokenVerifier verifier = new GoogleIdTokenVerifier.Builder(transport, jsonFactory)
                .setAudience(Collections.singletonList(CLIENT_ID)).build();

        // (Receive idTokenString by HTTPS POST)
        GoogleIdToken idToken = verifier.verify(request.getParameter("idtoken"));
        if (idToken != null) {
            Payload payload = idToken.getPayload();

            // Print user identifier
            String userId = payload.getSubject();
            System.out.println("User ID: " + userId);

            // Get profile information from payload
            String email = payload.getEmail();
            boolean emailVerified = payload.getEmailVerified();
            String name = (String) payload.get("name");
            String pictureUrl = (String) payload.get("picture");
            String locale = (String) payload.get("locale");
            String familyName = (String) payload.get("family_name");
            String givenName = (String) payload.get("given_name");

            System.out.println(email);
            // Use or store profile information
            // ...
        } else {
            System.out.println("Invalid ID token.");
        }
    } catch (GeneralSecurityException ex) {
        Logger.getLogger(OAuthServlet.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:org.glassmaker.ui.editor.CardEditor.java

License:Open Source License

private void previewOnGlass() {
    try {/*from w w w  .  ja va  2 s. co  m*/
        Credential cred = GoogleLogin.getInstance().getCredential();
        cred.getAccessToken();
        Mirror m = new Mirror.Builder(GoogleNetHttpTransport.newTrustedTransport(), new JacksonFactory(), cred)
                .setApplicationName("Glassmaker Plugin").build();

        String editorText = getDocumentProvider().getDocument(textEditor.getEditorInput()).get();
        deletePreviewFiles();
        TimelineItem timelineItem = CardUtil.createTimeline(editorText);
        Mirror.Timeline timeline = m.timeline();
        timeline.insert(timelineItem).execute();

    } catch (Exception e) {
        GlassmakerUIPlugin.logError(e.getMessage(), e);
    }
}

From source file:org.gradle.internal.resource.transport.gcp.gcs.GcsClient.java

License:Apache License

public static GcsClient create(GcsConnectionProperties gcsConnectionProperties)
        throws GeneralSecurityException, IOException {
    HttpTransport transport = GoogleNetHttpTransport.newTrustedTransport();
    JsonFactory jsonFactory = new JacksonFactory();
    Storage.Builder builder = new Storage.Builder(transport, jsonFactory, null);
    if (gcsConnectionProperties.requiresAuthentication()) {
        Supplier<Credential> credentialSupplier = getCredentialSupplier(transport, jsonFactory);
        builder.setHttpRequestInitializer(new RetryHttpInitializerWrapper(credentialSupplier));
    }/*w ww .  jav  a  2  s.  co m*/
    if (gcsConnectionProperties.getEndpoint().isPresent()) {
        builder.setRootUrl(gcsConnectionProperties.getEndpoint().get().toString());
    }
    if (gcsConnectionProperties.getServicePath().isPresent()) {
        builder.setServicePath(gcsConnectionProperties.getServicePath().get());
    }
    builder.setApplicationName("gradle");
    return new GcsClient(builder.build());
}

From source file:org.jraf.irondad.handler.googlegif.GoogleGifHandler.java

License:Open Source License

private Customsearch getCustomsearch(HandlerContext handlerContext) {
    Customsearch res = (Customsearch) handlerContext.get("customsearch");
    if (res == null) {
        Customsearch.Builder customSearchBuilder;
        try {/* w ww . ja  v a 2 s  . c  o m*/
            customSearchBuilder = new Customsearch.Builder(GoogleNetHttpTransport.newTrustedTransport(),
                    JSON_FACTORY, null);
            customSearchBuilder.setApplicationName(APPLICATION_NAME);
            String key = ((GoogleGifHandlerConfig) handlerContext.getHandlerConfig()).getKey();
            customSearchBuilder.setCustomsearchRequestInitializer(new CustomsearchRequestInitializer(key));
            res = customSearchBuilder.build();

            handlerContext.put("customsearch", res);
        } catch (Exception e) {
            Log.e(TAG,
                    "GoogleGifHandler Could not initialize! GoogleGifHandler will not work until this problem is resolved",
                    e);
        }
    }
    return res;
}

From source file:org.jraf.irondad.handler.pixgame.PixGameHandler.java

License:Open Source License

private Customsearch getCustomsearch(HandlerContext handlerContext) {
    Customsearch res = (Customsearch) handlerContext.get("customsearch");
    if (res == null) {
        Customsearch.Builder customSearchBuilder;
        try {/*from ww  w .j  a  v a 2 s  .  c  om*/
            customSearchBuilder = new Customsearch.Builder(GoogleNetHttpTransport.newTrustedTransport(),
                    JSON_FACTORY, null);
            customSearchBuilder.setApplicationName(APPLICATION_NAME);
            String key = ((PixGameHandlerConfig) handlerContext.getHandlerConfig()).getKey();
            customSearchBuilder.setCustomsearchRequestInitializer(new CustomsearchRequestInitializer(key));
            res = customSearchBuilder.build();

            handlerContext.put("customsearch", res);
        } catch (Exception e) {
            Log.e(TAG,
                    "PixGameHandler Could not initialize! PixGameHandler will not work until this problem is resolved",
                    e);
        }
    }
    return res;
}

From source file:org.jraf.irondad.handler.twitter.follow.TwitterFollowHandler.java

License:Open Source License

private static Urlshortener newUrlshortener() throws Exception {
    return new Urlshortener.Builder(GoogleNetHttpTransport.newTrustedTransport(), new JacksonFactory(), null)
            .build();/*  ww w  . ja v a  2s  .  c om*/
}

From source file:org.jraf.irondad.handler.wikipedia.WikipediaHandler.java

License:Open Source License

private Customsearch getCustomsearch(HandlerContext handlerContext) {
    Customsearch res = (Customsearch) handlerContext.get("customsearch");
    if (res == null) {
        Customsearch.Builder customSearchBuilder;
        try {/*from  w  w w .jav  a 2  s .co m*/
            customSearchBuilder = new Customsearch.Builder(GoogleNetHttpTransport.newTrustedTransport(),
                    JSON_FACTORY, null);
            customSearchBuilder.setApplicationName(APPLICATION_NAME);
            String key = ((WikipediaHandlerConfig) handlerContext.getHandlerConfig()).getKey();
            customSearchBuilder.setCustomsearchRequestInitializer(new CustomsearchRequestInitializer(key));
            res = customSearchBuilder.build();

            handlerContext.put("customsearch", res);
        } catch (Exception e) {
            Log.e(TAG,
                    "WikipediaHandler Could not initialize! WikipediaHandler will not work until this problem is resolved",
                    e);
        }
    }
    return res;
}

From source file:org.kie.google.GooglePlusClient.java

License:Apache License

Plus gPlus() throws GeneralSecurityException, IOException {
    final HttpTransport httpTransport = GoogleNetHttpTransport.newTrustedTransport();
    final JsonFactory jsonFactory = JacksonFactory.getDefaultInstance();

    return new Plus.Builder(httpTransport, jsonFactory, credential(httpTransport, jsonFactory))
            .setApplicationName(GooglePlusProperties.APPLICATION_NAME).build();
}