com.google.api.client.http.HttpRequestInitializer

Here are the examples of the java api class com.google.api.client.http.HttpRequestInitializer taken from open source projects.

1. InjectorUtils#getClient()

Project: DataflowJavaSDK
Source File: InjectorUtils.java
View license
/**
   * Builds a new Pubsub client and returns it.
   */
public static Pubsub getClient(final HttpTransport httpTransport, final JsonFactory jsonFactory) throws IOException {
    Preconditions.checkNotNull(httpTransport);
    Preconditions.checkNotNull(jsonFactory);
    GoogleCredential credential = GoogleCredential.getApplicationDefault(httpTransport, jsonFactory);
    if (credential.createScopedRequired()) {
        credential = credential.createScoped(PubsubScopes.all());
    }
    if (credential.getClientAuthentication() != null) {
        System.out.println("\n***Warning! You are not using service account credentials to " + "authenticate.\nYou need to use service account credentials for this example," + "\nsince user-level credentials do not have enough pubsub quota,\nand so you will run " + "out of PubSub quota very quickly.\nSee " + "https://developers.google.com/identity/protocols/application-default-credentials.");
        System.exit(1);
    }
    HttpRequestInitializer initializer = new RetryHttpInitializerWrapper(credential);
    return new Pubsub.Builder(httpTransport, jsonFactory, initializer).setApplicationName(APP_NAME).build();
}

2. HttpServiceOptions#httpRequestInitializer()

Project: gcloud-java
Source File: HttpServiceOptions.java
View license
/**
   * Returns a request initializer responsible for initializing requests according to service
   * options.
   */
public HttpRequestInitializer httpRequestInitializer() {
    final HttpRequestInitializer delegate = authCredentials() != null && authCredentials().credentials() != null ? new HttpCredentialsAdapter(authCredentials().credentials().createScoped(scopes())) : null;
    return new HttpRequestInitializer() {

        @Override
        public void initialize(HttpRequest httpRequest) throws IOException {
            if (delegate != null) {
                delegate.initialize(httpRequest);
            }
            if (connectTimeout >= 0) {
                httpRequest.setConnectTimeout(connectTimeout);
            }
            if (readTimeout >= 0) {
                httpRequest.setReadTimeout(readTimeout);
            }
        }
    };
}

3. InjectorUtils#getClient()

Project: incubator-beam
Source File: InjectorUtils.java
View license
/**
   * Builds a new Pubsub client and returns it.
   */
public static Pubsub getClient(final HttpTransport httpTransport, final JsonFactory jsonFactory) throws IOException {
    checkNotNull(httpTransport);
    checkNotNull(jsonFactory);
    GoogleCredential credential = GoogleCredential.getApplicationDefault(httpTransport, jsonFactory);
    if (credential.createScopedRequired()) {
        credential = credential.createScoped(PubsubScopes.all());
    }
    if (credential.getClientAuthentication() != null) {
        System.out.println("\n***Warning! You are not using service account credentials to " + "authenticate.\nYou need to use service account credentials for this example," + "\nsince user-level credentials do not have enough pubsub quota,\nand so you will run " + "out of PubSub quota very quickly.\nSee " + "https://developers.google.com/identity/protocols/application-default-credentials.");
        System.exit(1);
    }
    HttpRequestInitializer initializer = new RetryHttpInitializerWrapper(credential);
    return new Pubsub.Builder(httpTransport, jsonFactory, initializer).setApplicationName(APP_NAME).build();
}

4. CloudBackend#getMBSEndpoint()

Project: io2014-codelabs
Source File: CloudBackend.java
View license
// building CloudBackend endpoints and configuring authentication and
// exponential back-off policy
private Mobilebackend getMBSEndpoint() {
    // check if credential has account name
    final GoogleAccountCredential gac = mCredential == null || mCredential.getSelectedAccountName() == null ? null : mCredential;
    // create HttpRequestInitializer
    HttpRequestInitializer hri = new HttpRequestInitializer() {

        @Override
        public void initialize(HttpRequest request) throws IOException {
            request.setBackOffPolicy(new ExponentialBackOffPolicy());
            if (gac != null) {
                gac.initialize(request);
            }
        }
    };
    // (specify gac or hri as the third parameter)
    return new Mobilebackend.Builder(AndroidHttp.newCompatibleTransport(), new GsonFactory(), hri).setRootUrl(Consts.ENDPOINT_ROOT_URL).build();
}

5. GmailService#getServiceWithRetries()

Project: mail-importer
Source File: GmailService.java
View license
Gmail getServiceWithRetries() {
    HttpRequestInitializer httpRequestInitializer =  request -> {
        credential.initialize(request);
        new UnsuccessfulResponseHandlerChainer().chain(request.getUnsuccessfulResponseHandler(), new HttpBackOffUnsuccessfulResponseHandler(backOffProvider.get()));
    };
    return new Gmail.Builder(httpTransport, jsonFactory, httpRequestInitializer).setApplicationName(GmailServiceModule.APP_NAME).build();
}

6. ServiceAccountConfiguration#createPubsubClient()

View license
public static Pubsub createPubsubClient(String serviceAccountEmail, String privateKeyFilePath) throws IOException, GeneralSecurityException {
    HttpTransport transport = GoogleNetHttpTransport.newTrustedTransport();
    GoogleCredential credential = new GoogleCredential.Builder().setTransport(transport).setJsonFactory(JSON_FACTORY).setServiceAccountScopes(PubsubScopes.all()).setServiceAccountId(// (and put the e-mail address into your system property obviously)
    serviceAccountEmail).setServiceAccountPrivateKeyFromP12File(// https://console.developers.google.com/
    new File(privateKeyFilePath)).build();
    // Please use custom HttpRequestInitializer for automatic
    // retry upon failures.  We provide a simple reference
    // implementation in the "Retry Handling" section.
    HttpRequestInitializer initializer = new RetryHttpInitializerWrapper(credential);
    return new Pubsub.Builder(transport, JSON_FACTORY, initializer).setApplicationName("PubSub Example").build();
}