當前位置: 首頁>>代碼示例>>Java>>正文


Java HttpRequestInitializer類代碼示例

本文整理匯總了Java中com.google.api.client.http.HttpRequestInitializer的典型用法代碼示例。如果您正苦於以下問題:Java HttpRequestInitializer類的具體用法?Java HttpRequestInitializer怎麽用?Java HttpRequestInitializer使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


HttpRequestInitializer類屬於com.google.api.client.http包,在下文中一共展示了HttpRequestInitializer類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: getClient

import com.google.api.client.http.HttpRequestInitializer; //導入依賴的package包/類
/** 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();
}
 
開發者ID:mdvorsky,項目名稱:DataflowSME,代碼行數:25,代碼來源:InjectorUtils.java

示例2: getClient

import com.google.api.client.http.HttpRequestInitializer; //導入依賴的package包/類
/**
 * 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();
}
 
開發者ID:davorbonaci,項目名稱:beam-portability-demo,代碼行數:28,代碼來源:InjectorUtils.java

示例3: getTubeService

import com.google.api.client.http.HttpRequestInitializer; //導入依賴的package包/類
private synchronized YouTube getTubeService()
{
	if( tubeService == null )
	{
		tubeService = new YouTube.Builder(new NetHttpTransport(), new JacksonFactory(),
			new HttpRequestInitializer()
			{
				@Override
				public void initialize(HttpRequest request) throws IOException
				{
					// Nothing?
				}
			}).setApplicationName(EQUELLA).build();
	}
	return tubeService;
}
 
開發者ID:equella,項目名稱:Equella,代碼行數:17,代碼來源:GoogleServiceImpl.java

示例4: connect

import com.google.api.client.http.HttpRequestInitializer; //導入依賴的package包/類
@Override
protected Drive connect(final HostKeyCallback callback, final LoginCallback prompt) {
    authorizationService = new OAuth2RequestInterceptor(builder.build(this, prompt).build(), host.getProtocol())
        .withRedirectUri(host.getProtocol().getOAuthRedirectUrl());
    final HttpClientBuilder configuration = builder.build(this, prompt);
    configuration.addInterceptorLast(authorizationService);
    configuration.setServiceUnavailableRetryStrategy(new OAuth2ErrorResponseInterceptor(authorizationService));
    this.transport = new ApacheHttpTransport(configuration.build());
    return new Drive.Builder(transport, json, new HttpRequestInitializer() {
        @Override
        public void initialize(HttpRequest request) throws IOException {
            request.setSuppressUserAgentSuffix(true);
            // OAuth Bearer added in interceptor
        }
    })
        .setApplicationName(useragent.get())
        .build();
}
 
開發者ID:iterate-ch,項目名稱:cyberduck,代碼行數:19,代碼來源:DriveSession.java

示例5: YouTubeSingleton

import com.google.api.client.http.HttpRequestInitializer; //導入依賴的package包/類
private YouTubeSingleton() {

        credential = GoogleAccountCredential.usingOAuth2(
                YTApplication.getAppContext(), Arrays.asList(SCOPES))
                .setBackOff(new ExponentialBackOff());

        youTube = new YouTube.Builder(new NetHttpTransport(), new JacksonFactory(), new HttpRequestInitializer() {
            @Override
            public void initialize(HttpRequest httpRequest) throws IOException {

            }
        }).setApplicationName(YTApplication.getAppContext().getString(R.string.app_name))
                .build();

        youTubeWithCredentials = new YouTube.Builder(new NetHttpTransport(), new JacksonFactory(), credential)
                .setApplicationName(YTApplication.getAppContext().getString(R.string.app_name))
                .build();
    }
 
開發者ID:pawelpaszki,項目名稱:youtube_background_android,代碼行數:19,代碼來源:YouTubeSingleton.java

示例6: ServiceConfigSupplier

import com.google.api.client.http.HttpRequestInitializer; //導入依賴的package包/類
@VisibleForTesting
ServiceConfigSupplier(
    Environment environment,
    HttpTransport httpTransport,
    JsonFactory jsonFactory,
    final GoogleCredential credential) {
  this.environment = environment;
  HttpRequestInitializer requestInitializer = new HttpRequestInitializer() {
    @Override
    public void initialize(HttpRequest request) throws IOException {
      request.setThrowExceptionOnExecuteError(false);
      credential.initialize(request);
    }
  };
  this.serviceManagement =
      new ServiceManagement.Builder(httpTransport, jsonFactory, requestInitializer)
          .setApplicationName("Endpoints Frameworks Java")
          .build();
}
 
開發者ID:cloudendpoints,項目名稱:endpoints-management-java,代碼行數:20,代碼來源:ServiceConfigSupplier.java

示例7: YouTubeSingleton

import com.google.api.client.http.HttpRequestInitializer; //導入依賴的package包/類
private YouTubeSingleton(Context context)
{
    String appName = context.getString(R.string.app_name);
    credential = GoogleAccountCredential
            .usingOAuth2(context, Arrays.asList(SCOPES))
            .setBackOff(new ExponentialBackOff());

    youTube = new YouTube.Builder(
            new NetHttpTransport(),
            new JacksonFactory(),
            new HttpRequestInitializer()
            {
                @Override
                public void initialize(HttpRequest httpRequest) throws IOException {}
            }
    ).setApplicationName(appName).build();

    youTubeWithCredentials = new YouTube.Builder(
            new NetHttpTransport(),
            new JacksonFactory(),
            credential
    ).setApplicationName(appName).build();
}
 
開發者ID:teocci,項目名稱:YouTube-In-Background,代碼行數:24,代碼來源:YouTubeSingleton.java

示例8: getApiService

import com.google.api.client.http.HttpRequestInitializer; //導入依賴的package包/類
/**
 * Get an instance of the language service.
 *
 * @param document
 * @return
 */
public CloudNaturalLanguageAPI getApiService(GoogleCredential credential) {
  final GoogleCredential cred = credential;
  CloudNaturalLanguageAPI api = null;
  try {
    api = new CloudNaturalLanguageAPI.Builder(
            GoogleNetHttpTransport.newTrustedTransport(),
            JacksonFactory.getDefaultInstance(),
            new HttpRequestInitializer() {
      @Override
      public void initialize(HttpRequest httpRequest) throws IOException {
        cred.initialize(httpRequest);
      }
    }).setApplicationName(getApplicationName()).build();
  } catch (Exception ex) {
    throw new GateRuntimeException("Could not establish Google Service API", ex);
  }
  //System.err.println("DEBUG: API instance established: " + api);
  return api;
}
 
開發者ID:GateNLP,項目名稱:gateplugin-Tagger_GoogleNLP,代碼行數:26,代碼來源:TaggerGoogleNLP.java

示例9: googleStorage

import com.google.api.client.http.HttpRequestInitializer; //導入依賴的package包/類
@Bean
public Storage googleStorage() {
  JsonFactory jsonFactory = JacksonFactory.getDefaultInstance();
  String applicationName = "Spinnaker/Halyard";
  HttpRequestInitializer requestInitializer;
  try {
    requestInitializer = GoogleCredentials.setHttpTimeout(GoogleCredential.getApplicationDefault());
    log.info("Loaded application default credential for reading BOMs & profiles.");
  } catch (Exception e) {
    requestInitializer = GoogleCredentials.retryRequestInitializer();
    log.debug("No application default credential could be loaded for reading BOMs & profiles. Continuing unauthenticated: {}", e.getMessage());
  }

  return new Storage.Builder(GoogleCredentials.buildHttpTransport(), jsonFactory, requestInitializer)
      .setApplicationName(applicationName)
      .build();
}
 
開發者ID:spinnaker,項目名稱:halyard,代碼行數:18,代碼來源:GoogleProfileReader.java

示例10: provideDns

import com.google.api.client.http.HttpRequestInitializer; //導入依賴的package包/類
@Provides
static Dns provideDns(
    HttpTransport transport,
    JsonFactory jsonFactory,
    Function<Set<String>, ? extends HttpRequestInitializer> credential,
    @Config("projectId") String projectId,
    @Config("cloudDnsRootUrl") Optional<String> rootUrl,
    @Config("cloudDnsServicePath") Optional<String> servicePath) {
  Dns.Builder builder =
      new Dns.Builder(transport, jsonFactory, credential.apply(DnsScopes.all()))
          .setApplicationName(projectId);

  rootUrl.ifPresent(builder::setRootUrl);
  servicePath.ifPresent(builder::setServicePath);

  return builder.build();
}
 
開發者ID:google,項目名稱:nomulus,代碼行數:18,代碼來源:CloudDnsWriterModule.java

示例11: before

import com.google.api.client.http.HttpRequestInitializer; //導入依賴的package包/類
@Before
public void before() throws Exception {
  when(subfactory.create(
      anyString(),
      any(HttpTransport.class),
      any(JsonFactory.class),
      any(HttpRequestInitializer.class)))
          .thenReturn(bigquery);
  when(bigquery.datasets()).thenReturn(bigqueryDatasets);
  when(bigqueryDatasets.insert(eq("Project-Id"), any(Dataset.class)))
      .thenReturn(bigqueryDatasetsInsert);
  when(bigquery.tables()).thenReturn(bigqueryTables);
  when(bigqueryTables.insert(eq("Project-Id"), any(String.class), any(Table.class)))
      .thenReturn(bigqueryTablesInsert);
  factory = new BigqueryFactory();
  factory.subfactory = subfactory;
  factory.bigquerySchemas =
      new ImmutableMap.Builder<String, ImmutableList<TableFieldSchema>>()
          .put(
              "Table-Id",
              ImmutableList.of(new TableFieldSchema().setName("column1").setType(STRING.name())))
          .put(
              "Table2",
              ImmutableList.of(new TableFieldSchema().setName("column1").setType(STRING.name())))
          .build();
}
 
開發者ID:google,項目名稱:nomulus,代碼行數:27,代碼來源:BigqueryFactoryTest.java

示例12: setup

import com.google.api.client.http.HttpRequestInitializer; //導入依賴的package包/類
@Before
public void setup() throws Exception {
  when(bigqueryFactory.create(anyString(), anyString(), anyString())).thenReturn(bigquery);
  when(bigqueryFactory.create(
      anyString(),
      Matchers.any(HttpTransport.class),
      Matchers.any(JsonFactory.class),
      Matchers.any(HttpRequestInitializer.class)))
          .thenReturn(bigquery);

  when(bigquery.tabledata()).thenReturn(tabledata);
  when(tabledata.insertAll(
      anyString(),
      anyString(),
      anyString(),
      Matchers.any(TableDataInsertAllRequest.class))).thenReturn(insertAll);
  action = new MetricsExportAction();
  action.bigqueryFactory = bigqueryFactory;
  action.insertId = "insert id";
  action.parameters = parameters;
  action.projectId = "project id";
  action.tableId = "eppMetrics";
}
 
開發者ID:google,項目名稱:nomulus,代碼行數:24,代碼來源:MetricsExportActionTest.java

示例13: getGoogleTasksService

import com.google.api.client.http.HttpRequestInitializer; //導入依賴的package包/類
public static Tasks getGoogleTasksService(final Context context, String accountName) {
    final GoogleAccountCredential credential =
            GoogleAccountCredential.usingOAuth2(context, ListManager.TASKS_SCOPES);
    credential.setSelectedAccountName(accountName);
    Tasks googleService =
        new Tasks.Builder(TRANSPORT, JSON_FACTORY, credential)
                 .setApplicationName(DateUtils.getAppName(context))
                 .setHttpRequestInitializer(new HttpRequestInitializer() {
                     @Override
                     public void initialize(HttpRequest httpRequest) {
                         credential.initialize(httpRequest);
                         httpRequest.setConnectTimeout(3 * 1000);  // 3 seconds connect timeout
                         httpRequest.setReadTimeout(3 * 1000);  // 3 seconds read timeout
                     }
                 })
                 .build();
    return googleService;
}
 
開發者ID:danielebufarini,項目名稱:Reminders,代碼行數:19,代碼來源:Reminders.java

示例14: GcloudPubsub

import com.google.api.client.http.HttpRequestInitializer; //導入依賴的package包/類
/**
 * Constructor that will automatically instantiate a Google Cloud Pub/Sub instance.
 *
 * @throws IOException when the initialization of the Google Cloud Pub/Sub client fails.
 */
public GcloudPubsub() throws IOException {
  if (CLOUD_PUBSUB_PROJECT_ID == null) {
    throw new IllegalStateException(GCLOUD_PUBSUB_PROJECT_ID_NOT_SET_ERROR);
  }
  try {
    serverName = InetAddress.getLocalHost().getCanonicalHostName();
  } catch (UnknownHostException e) {
    throw new IllegalStateException("Unable to retrieve the hostname of the system");
  }
  HttpTransport httpTransport = checkNotNull(Utils.getDefaultTransport());
  JsonFactory jsonFactory = checkNotNull(Utils.getDefaultJsonFactory());
  GoogleCredential credential = GoogleCredential.getApplicationDefault(
      httpTransport, jsonFactory);
  if (credential.createScopedRequired()) {
    credential = credential.createScoped(PubsubScopes.all());
  }
  HttpRequestInitializer initializer =
      new RetryHttpInitializerWrapper(credential);
  pubsub = new Pubsub.Builder(httpTransport, jsonFactory, initializer).build();
  logger.info("Google Cloud Pub/Sub Initialization SUCCESS");
}
 
開發者ID:GoogleCloudPlatform,項目名稱:cloud-pubsub-mqtt-proxy,代碼行數:27,代碼來源:GcloudPubsub.java

示例15: YouTubeRetriever

import com.google.api.client.http.HttpRequestInitializer; //導入依賴的package包/類
public YouTubeRetriever(Credentials credentials) throws Exception {
    super(credentials);

    if (credentials.getClientId() == null || credentials.getKey() == null) {
        logger.error("YouTube requires authentication.");
        throw new Exception("YouTube requires authentication.");
    }
    apiKey = credentials.getKey();

    youtube = new YouTube.Builder(
    		HTTP_TRANSPORT, 
    		JSON_FACTORY, 
    		new HttpRequestInitializer() {
    			public void initialize(HttpRequest request) throws IOException {
    			
    			}
    		}
    	).setApplicationName(credentials.getClientId()).build();
}
 
開發者ID:MKLab-ITI,項目名稱:simmo-stream-manager,代碼行數:20,代碼來源:YouTubeRetriever.java


注:本文中的com.google.api.client.http.HttpRequestInitializer類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。