当前位置: 首页>>代码示例>>Java>>正文


Java HttpTransportFactory类代码示例

本文整理汇总了Java中com.google.auth.http.HttpTransportFactory的典型用法代码示例。如果您正苦于以下问题:Java HttpTransportFactory类的具体用法?Java HttpTransportFactory怎么用?Java HttpTransportFactory使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


HttpTransportFactory类属于com.google.auth.http包,在下文中一共展示了HttpTransportFactory类的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: createApplicationDefaultCredential

import com.google.auth.http.HttpTransportFactory; //导入依赖的package包/类
private static GoogleCredentials createApplicationDefaultCredential() throws IOException {
  final MockTokenServerTransport transport = new MockTokenServerTransport();
  transport.addServiceAccount(ServiceAccount.EDITOR.getEmail(), ACCESS_TOKEN);

  // Set the GOOGLE_APPLICATION_CREDENTIALS environment variable for application-default
  // credentials. This requires us to write the credentials to the location specified by the
  // environment variable.
  File credentialsFile = File.createTempFile("google-test-credentials", "json");
  PrintWriter writer = new PrintWriter(Files.newBufferedWriter(credentialsFile.toPath(), UTF_8));
  writer.print(ServiceAccount.EDITOR.asString());
  writer.close();
  Map<String, String> environmentVariables =
      ImmutableMap.<String, String>builder()
          .put("GOOGLE_APPLICATION_CREDENTIALS", credentialsFile.getAbsolutePath())
          .build();
  TestUtils.setEnvironmentVariables(environmentVariables);
  credentialsFile.deleteOnExit();

  return GoogleCredentials.getApplicationDefault(new HttpTransportFactory() {
    @Override
    public HttpTransport create() {
      return transport;
    }
  });
}
 
开发者ID:firebase,项目名称:firebase-admin-java,代码行数:26,代码来源:FirebaseAuthTest.java

示例2: createRefreshTokenCredential

import com.google.auth.http.HttpTransportFactory; //导入依赖的package包/类
private static GoogleCredentials createRefreshTokenCredential() throws IOException {

    final MockTokenServerTransport transport = new MockTokenServerTransport();
    transport.addClient(CLIENT_ID, CLIENT_SECRET);
    transport.addRefreshToken(REFRESH_TOKEN, ACCESS_TOKEN);

    Map<String, Object> secretJson = new HashMap<>();
    secretJson.put("client_id", CLIENT_ID);
    secretJson.put("client_secret", CLIENT_SECRET);
    secretJson.put("refresh_token", REFRESH_TOKEN);
    secretJson.put("type", "authorized_user");
    InputStream refreshTokenStream =
        new ByteArrayInputStream(JSON_FACTORY.toByteArray(secretJson));

    return UserCredentials.fromStream(refreshTokenStream, new HttpTransportFactory() {
      @Override
      public HttpTransport create() {
        return transport;
      }
    });
  }
 
开发者ID:firebase,项目名称:firebase-admin-java,代码行数:22,代码来源:FirebaseAuthTest.java

示例3: getApplicationDefaultCredentials

import com.google.auth.http.HttpTransportFactory; //导入依赖的package包/类
/**
 * Ensures initialization of Google Application Default Credentials. Any test that depends on
 * ADC should consider this as a fixture, and invoke it before hand. Since ADC are initialized
 * once per JVM, this makes sure that all dependent tests get the same ADC instance, and
 * can reliably reason about the tokens minted using it.
 */
public static synchronized GoogleCredentials getApplicationDefaultCredentials()
    throws IOException {
  if (defaultCredentials != null) {
    return defaultCredentials;
  }
  final MockTokenServerTransport transport = new MockTokenServerTransport();
  transport.addServiceAccount(ServiceAccount.EDITOR.getEmail(), TEST_ADC_ACCESS_TOKEN);
  File serviceAccount = new File("src/test/resources/service_accounts", "editor.json");
  Map<String, String> environmentVariables =
      ImmutableMap.<String, String>builder()
          .put("GOOGLE_APPLICATION_CREDENTIALS", serviceAccount.getAbsolutePath())
          .build();
  setEnvironmentVariables(environmentVariables);
  defaultCredentials = GoogleCredentials.getApplicationDefault(new HttpTransportFactory() {
    @Override
    public HttpTransport create() {
      return transport;
    }
  });
  return defaultCredentials;
}
 
开发者ID:firebase,项目名称:firebase-admin-java,代码行数:28,代码来源:TestUtils.java

示例4: wrap

import com.google.auth.http.HttpTransportFactory; //导入依赖的package包/类
private static HttpTransportFactory wrap(final HttpTransport transport) {
  checkNotNull(transport, "HttpTransport must not be null");
  return new HttpTransportFactory() {
    @Override
    public HttpTransport create() {
      return transport;
    }
  };
}
 
开发者ID:firebase,项目名称:firebase-admin-java,代码行数:10,代码来源:FirebaseCredentials.java

示例5: createCertificateCredential

import com.google.auth.http.HttpTransportFactory; //导入依赖的package包/类
private static GoogleCredentials createCertificateCredential() throws IOException {
  final MockTokenServerTransport transport = new MockTokenServerTransport();
  transport.addServiceAccount(ServiceAccount.EDITOR.getEmail(), ACCESS_TOKEN);
  return ServiceAccountCredentials.fromStream(ServiceAccount.EDITOR.asStream(),
      new HttpTransportFactory() {
        @Override
        public HttpTransport create() {
          return transport;
        }
      });
}
 
开发者ID:firebase,项目名称:firebase-admin-java,代码行数:12,代码来源:FirebaseAuthTest.java

示例6: getHttpTransportOptions

import com.google.auth.http.HttpTransportFactory; //导入依赖的package包/类
/**
 * Creates and returns HttpTransportOptions from the given connection parameters.
 * 
 * @param parameters
 *          the connection parameters
 * @return the HttpTransportOptions
 */
private static HttpTransportOptions getHttpTransportOptions(ConnectionParameters parameters) {
  HttpTransportOptions.Builder httpOptionsBuilder = HttpTransportOptions.newBuilder();
  httpOptionsBuilder.setConnectTimeout(parameters.getConnectionTimeout());
  httpOptionsBuilder.setReadTimeout(parameters.getReadTimeout());

  HttpTransportFactory httpTransportFactory = parameters.getHttpTransportFactory();
  if (httpTransportFactory != null) {
    httpOptionsBuilder.setHttpTransportFactory(httpTransportFactory);
  }
  return httpOptionsBuilder.build();
}
 
开发者ID:sai-pullabhotla,项目名称:catatumbo,代码行数:19,代码来源:EntityManagerFactory.java

示例7: getTransportFactory

import com.google.auth.http.HttpTransportFactory; //导入依赖的package包/类
@VisibleForTesting
HttpTransportFactory getTransportFactory(final HttpClient httpClient)
{
  return () -> new ApacheHttpTransport(httpClient);
}
 
开发者ID:drcrallen,项目名称:gswagon-maven-plugin,代码行数:6,代码来源:GSWagon.java

示例8: TestApp

import com.google.auth.http.HttpTransportFactory; //导入依赖的package包/类
public TestApp()  {

    String projectId = ServiceOptions.getDefaultProjectId();
	try {

		//export GRPC_PROXY_EXP=localhost:3128
		HttpHost proxy = new HttpHost("127.0.0.1",3128);
		DefaultHttpClient httpClient = new DefaultHttpClient();
		httpClient.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy);
					
		httpClient.addRequestInterceptor(new HttpRequestInterceptor(){            
			@Override
			public void process(org.apache.http.HttpRequest request, HttpContext context) throws HttpException, IOException {
					//if (request.getRequestLine().getMethod().equals("CONNECT"))                 
					//   request.addHeader(new BasicHeader("Proxy-Authorization","Basic dXNlcjE6dXNlcjE="));
				}
			});
		
		mHttpTransport =  new ApacheHttpTransport(httpClient);		

		HttpTransportFactory hf = new HttpTransportFactory(){
			@Override
			public HttpTransport create() {
				return mHttpTransport;
			}
		};            
		
		credential = GoogleCredentials.getApplicationDefault(hf);

		CredentialsProvider credentialsProvider =  new GoogleCredentialsProvider(){
			public List<String> getScopesToApply(){
				return Arrays.asList("https://www.googleapis.com/auth/pubsub");
			   }

			public Credentials getCredentials()  {
				return credential;
			}
		};

		TopicAdminSettings topicAdminSettings =
		     TopicAdminSettings.newBuilder().setCredentialsProvider(credentialsProvider)
				 .build();
				 
		 TopicAdminClient topicAdminClient =
		     TopicAdminClient.create(topicAdminSettings);
		
		//TopicAdminClient topicAdminClient = TopicAdminClient.create();
		ProjectName project = ProjectName.create(projectId);
		for (Topic element : topicAdminClient.listTopics(project).iterateAll()) 
	  		System.out.println(element.getName());
	
	} catch (Exception ex) 
	{
		System.out.println("ERROR " + ex);
	}
  }
 
开发者ID:salrashid123,项目名称:gcpsamples,代码行数:57,代码来源:TestApp.java

示例9: configure

import com.google.auth.http.HttpTransportFactory; //导入依赖的package包/类
@Override
protected final void configure() {
  requireBinding(HttpTransportFactory.class);
  requireBinding(Key.get(new TypeLiteral<List<String>>() {}, Scopes.class));
}
 
开发者ID:GoogleCloudPlatform,项目名称:cloud-trace-java,代码行数:6,代码来源:DefaultCredentialsModule.java

示例10: provideCredentials

import com.google.auth.http.HttpTransportFactory; //导入依赖的package包/类
@Provides
@Singleton
final Credentials provideCredentials(HttpTransportFactory transport, @Scopes List<String> scopes)
    throws IOException {
  return GoogleCredentials.getApplicationDefault(checkNotNull(transport)).createScoped(scopes);
}
 
开发者ID:GoogleCloudPlatform,项目名称:cloud-trace-java,代码行数:7,代码来源:DefaultCredentialsModule.java

示例11: getHttpTransportFactory

import com.google.auth.http.HttpTransportFactory; //导入依赖的package包/类
/**
 * Returns the HttpTransportFactory.
 * 
 * @return the HttpTransportFactory.
 */
public HttpTransportFactory getHttpTransportFactory() {
  return httpTransportFactory;
}
 
开发者ID:sai-pullabhotla,项目名称:catatumbo,代码行数:9,代码来源:ConnectionParameters.java

示例12: setHttpTransportFactory

import com.google.auth.http.HttpTransportFactory; //导入依赖的package包/类
/**
 * Sets the HttpTransportFactory.
 * 
 * @param httpTransportFactory
 *          the HttpTransportFactory
 */
public void setHttpTransportFactory(HttpTransportFactory httpTransportFactory) {
  this.httpTransportFactory = httpTransportFactory;
}
 
开发者ID:sai-pullabhotla,项目名称:catatumbo,代码行数:10,代码来源:ConnectionParameters.java


注:本文中的com.google.auth.http.HttpTransportFactory类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。