本文整理汇总了Java中com.google.api.client.http.apache.ApacheHttpTransport类的典型用法代码示例。如果您正苦于以下问题:Java ApacheHttpTransport类的具体用法?Java ApacheHttpTransport怎么用?Java ApacheHttpTransport使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ApacheHttpTransport类属于com.google.api.client.http.apache包,在下文中一共展示了ApacheHttpTransport类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: connect
import com.google.api.client.http.apache.ApacheHttpTransport; //导入依赖的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
示例2: build
import com.google.api.client.http.apache.ApacheHttpTransport; //导入依赖的package包/类
public OAuthAccessToken build() throws IOException {
Url = new GenericUrl(config.getAccessTokenUrl());
transport = new ApacheHttpTransport();
HttpRequestFactory requestFactory = transport.createRequestFactory();
request = requestFactory.buildRequest(HttpMethods.GET, Url, null);
HttpHeaders headers = new HttpHeaders();
headers.setUserAgent(config.getUserAgent());
headers.setAccept(config.getAccept());
request.setHeaders(headers);
createRefreshParameters().intercept(request);
return this;
}
开发者ID:XeroAPI,项目名称:Xero-Java,代码行数:18,代码来源:OAuthAccessToken.java
示例3: testBrokenPipe_ApacheHttpTransport
import com.google.api.client.http.apache.ApacheHttpTransport; //导入依赖的package包/类
@Test
public void testBrokenPipe_ApacheHttpTransport() throws IOException, Failure {
HttpRequestFactory factory = new ApacheHttpTransport().createRequestFactory();
TestService.Iface client = new TestService.Client(new HttpClientHandler(
this::endpoint, factory, provider));
try {
// The request must be larger than the socket read buffer, to force it to fail the write to socket.
client.test(new Request(Strings.times("request ", 1024 * 1024)));
fail("No exception");
} catch (SocketException ex) {
// TODO: This should be a HttpResponseException
assertThat(ex.getMessage(), anyOf(
containsString("Broken pipe"),
is("Connection reset"),
is("Software caused connection abort: socket write error")));
}
}
开发者ID:morimekta,项目名称:providence,代码行数:20,代码来源:HttpClientHandlerNetworkTest.java
示例4: testThriftClient
import com.google.api.client.http.apache.ApacheHttpTransport; //导入依赖的package包/类
@Test
public void testThriftClient() throws TException, IOException, Failure {
ApacheHttpTransport transport = new ApacheHttpTransport();
THttpClient httpClient = new THttpClient(endpoint().toString(), transport.getHttpClient());
TBinaryProtocol protocol = new TBinaryProtocol(httpClient);
net.morimekta.test.thrift.service.TestService.Iface client =
new net.morimekta.test.thrift.service.TestService.Client(protocol);
doAnswer(i -> new Response("reply"))
.when(impl)
.test(any(Request.class));
net.morimekta.test.thrift.service.Response response =
client.test(new net.morimekta.test.thrift.service.Request("call"));
assertThat(response.getText(), is("reply"));
verify(impl).test(any(Request.class));
verify(instrumentation).onComplete(anyDouble(), any(PServiceCall.class), any(PServiceCall.class));
verifyNoMoreInteractions(impl, instrumentation);
}
开发者ID:morimekta,项目名称:providence,代码行数:21,代码来源:ProvidenceServlet_ThriftClientTest.java
示例5: testThriftClient_void
import com.google.api.client.http.apache.ApacheHttpTransport; //导入依赖的package包/类
@Test
public void testThriftClient_void() throws TException, IOException, Failure {
ApacheHttpTransport transport = new ApacheHttpTransport();
THttpClient httpClient = new THttpClient(endpoint().toString(), transport.getHttpClient());
TBinaryProtocol protocol = new TBinaryProtocol(httpClient);
net.morimekta.test.thrift.service.TestService.Iface client =
new net.morimekta.test.thrift.service.TestService.Client(protocol);
AtomicBoolean called = new AtomicBoolean();
doAnswer(i -> {
called.set(true);
return null;
}).when(impl).voidMethod(55);
client.voidMethod(55);
waitAtMost(Duration.ONE_HUNDRED_MILLISECONDS).untilTrue(called);
verify(impl).voidMethod(55);
verify(instrumentation).onComplete(anyDouble(), any(PServiceCall.class), any(PServiceCall.class));
verifyNoMoreInteractions(impl, instrumentation);
}
开发者ID:morimekta,项目名称:providence,代码行数:23,代码来源:ProvidenceServlet_ThriftClientTest.java
示例6: testThriftClient_oneway
import com.google.api.client.http.apache.ApacheHttpTransport; //导入依赖的package包/类
@Test
public void testThriftClient_oneway() throws TException, IOException, Failure {
ApacheHttpTransport transport = new ApacheHttpTransport();
THttpClient httpClient = new THttpClient(endpoint().toString(), transport.getHttpClient());
TBinaryProtocol protocol = new TBinaryProtocol(httpClient);
net.morimekta.test.thrift.service.TestService.Iface client =
new net.morimekta.test.thrift.service.TestService.Client(protocol);
AtomicBoolean called = new AtomicBoolean();
doAnswer(i -> {
called.set(true);
return null;
}).when(impl).ping();
client.ping();
waitAtMost(Duration.ONE_HUNDRED_MILLISECONDS).untilTrue(called);
verify(impl).ping();
verify(instrumentation).onComplete(anyDouble(), any(PServiceCall.class), isNull());
verifyNoMoreInteractions(impl, instrumentation);
}
开发者ID:morimekta,项目名称:providence,代码行数:23,代码来源:ProvidenceServlet_ThriftClientTest.java
示例7: testThriftClient_failure
import com.google.api.client.http.apache.ApacheHttpTransport; //导入依赖的package包/类
@Test
public void testThriftClient_failure() throws TException, IOException, Failure {
ApacheHttpTransport transport = new ApacheHttpTransport();
THttpClient httpClient = new THttpClient(endpoint().toString(), transport.getHttpClient());
TBinaryProtocol protocol = new TBinaryProtocol(httpClient);
net.morimekta.test.thrift.service.TestService.Iface client =
new net.morimekta.test.thrift.service.TestService.Client(protocol);
AtomicBoolean called = new AtomicBoolean();
doAnswer(i -> {
called.set(true);
throw new Failure("test");
}).when(impl).voidMethod(55);
try {
client.voidMethod(55);
} catch (net.morimekta.test.thrift.service.Failure e) {
assertEquals("test", e.getText());
}
waitAtMost(Duration.ONE_HUNDRED_MILLISECONDS).untilTrue(called);
verify(impl).voidMethod(55);
verify(instrumentation).onComplete(anyDouble(), any(PServiceCall.class), any(PServiceCall.class));
verifyNoMoreInteractions(impl, instrumentation);
}
开发者ID:morimekta,项目名称:providence,代码行数:27,代码来源:ProvidenceServlet_ThriftClientTest.java
示例8: GcsAuthentication
import com.google.api.client.http.apache.ApacheHttpTransport; //导入依赖的package包/类
public GcsAuthentication(String authMethod, Optional<String> serviceAccountEmail,
Optional<String> p12KeyFilePath, Optional<String> jsonKeyFilePath, String applicationName)
throws IOException, GeneralSecurityException
{
this.serviceAccountEmail = serviceAccountEmail;
this.p12KeyFilePath = p12KeyFilePath;
this.jsonKeyFilePath = jsonKeyFilePath;
this.applicationName = applicationName;
this.httpTransport = new ApacheHttpTransport.Builder().build();
this.jsonFactory = new JacksonFactory();
if (authMethod.equals("compute_engine")) {
this.credentials = getComputeCredential();
}
else if (authMethod.toLowerCase().equals("json_key")) {
this.credentials = getServiceAccountCredentialFromJsonFile();
}
else {
this.credentials = getServiceAccountCredential();
}
}
开发者ID:embulk,项目名称:embulk-output-gcs,代码行数:23,代码来源:GcsAuthentication.java
示例9: callApi
import com.google.api.client.http.apache.ApacheHttpTransport; //导入依赖的package包/类
public HttpResponse callApi(String apimethod, String httpmethod) throws IOException {
HttpTransport http_transport = new ApacheHttpTransport();
OAuthParameters parameters = tokmgr.getOAuthParameters();
HttpRequestFactory factory = http_transport.createRequestFactory(parameters);
GenericUrl url = new GenericUrl(API_URL + apimethod);
HttpRequest req = factory.buildGetRequest(url);
req.setRequestMethod(httpmethod);
HttpResponse resp = req.execute();
return resp;
}
开发者ID:phwoelfel,项目名称:FireHydrantLocator,代码行数:11,代码来源:OSMApi.java
示例10: signWithHostHeader
import com.google.api.client.http.apache.ApacheHttpTransport; //导入依赖的package包/类
@Test
public void signWithHostHeader() throws URISyntaxException, IOException, RequestSigningException {
HttpTransport HTTP_TRANSPORT = new ApacheHttpTransport();
HttpRequestFactory requestFactory = HTTP_TRANSPORT.createRequestFactory();
URI uri = URI.create("https://ignored-hostname.com/billing-usage/v1/reportSources");
HttpRequest request = requestFactory.buildGetRequest(new GenericUrl(uri));
request.getHeaders().put("Host", "ignored-hostname.com");
GoogleHttpClientEdgeGridRequestSigner googleHttpSigner = new GoogleHttpClientEdgeGridRequestSigner(credential);
googleHttpSigner.sign(request);
// NOTE: The library lower-cases all header names.
assertThat(request.getHeaders().containsKey("Host"), is(false));
assertThat(request.getHeaders().containsKey("host"), is(true));
assertThat((String) request.getHeaders().get("host"), equalTo("endpoint.net"));
assertThat(request.getUrl().getHost(), equalTo("endpoint.net"));
assertThat(request.getHeaders().containsKey("authorization"), is(true));
assertThat(request.getHeaders().getAuthorization(), not(isEmptyOrNullString()));
}
开发者ID:akamai,项目名称:AkamaiOPEN-edgegrid-java,代码行数:20,代码来源:GoogleHttpClientEdgeGridRequestSignerTest.java
示例11: testBuildTransportOptions
import com.google.api.client.http.apache.ApacheHttpTransport; //导入依赖的package包/类
@Test
public void testBuildTransportOptions()
{
gsWagon.swapAndCloseConnection(connectionPOJO);
final HttpTransportOptions transportOptions = (HttpTransportOptions) gsWagon.buildTransportOptions(connectionPOJO.client);
assertEquals(ApacheHttpTransport.class, transportOptions.getHttpTransportFactory().create().getClass());
assertEquals(gsWagon.getTimeout(), transportOptions.getConnectTimeout());
assertEquals(gsWagon.getReadTimeout(), transportOptions.getReadTimeout());
assertEquals(
connectionPOJO.client,
((ApacheHttpTransport) transportOptions.getHttpTransportFactory().create()).getHttpClient()
);
}
开发者ID:drcrallen,项目名称:gswagon-maven-plugin,代码行数:14,代码来源:GSWagonTest.java
示例12: execute
import com.google.api.client.http.apache.ApacheHttpTransport; //导入依赖的package包/类
public void execute() {
OAuthSigner signer = signerFactory.createSigner(null);
tokenRequest = new OAuthGetTemporaryToken(config.getRequestTokenUrl());
tokenRequest.consumerKey = config.getConsumerKey();
tokenRequest.callback = config.getRedirectUri();
ApacheHttpTransport.Builder transBuilder = new ApacheHttpTransport.Builder();
if (config.getProxyHost() != null && "" != config.getProxyHost()) {
String proxy_host = config.getProxyHost();
long proxy_port = config.getProxyPort();
boolean proxyHttps = config.getProxyHttpsEnabled();
String proxy_schema = proxyHttps == true ? "https" : "http";
System.out.println("proxy.host=" + proxy_host + ", proxy.port=" + proxy_port + ", proxy_schema=" + proxy_schema);
HttpHost proxy = new HttpHost(proxy_host, (int) proxy_port, proxy_schema);
transBuilder.setProxy(proxy);
tokenRequest.transport = transBuilder.build();
} else {
tokenRequest.transport = new ApacheHttpTransport();
}
tokenRequest.signer = signer;
OAuthCredentialsResponse temporaryTokenResponse = null;
try {
temporaryTokenResponse = tokenRequest.execute();
tempToken = temporaryTokenResponse.token;
tempTokenSecret = temporaryTokenResponse.tokenSecret;
} catch (IOException e) {
e.printStackTrace();
}
}
开发者ID:XeroAPI,项目名称:Xero-Java,代码行数:34,代码来源:OAuthRequestToken.java
示例13: doInBackground
import com.google.api.client.http.apache.ApacheHttpTransport; //导入依赖的package包/类
@Override
protected Void doInBackground(Uri... params) {
try {
signer.clientSharedSecret = Constants.CONSUMER_SECRET;
OAuthGetTemporaryToken temporaryToken = new OAuthGetTemporaryToken(Constants.REQUEST_URL);
temporaryToken.transport = new ApacheHttpTransport();
temporaryToken.signer = signer;
temporaryToken.consumerKey = Constants.CONSUMER_KEY;
temporaryToken.callback = Constants.OAUTH_CALLBACK_URL;
OAuthCredentialsResponse tempCredentials = temporaryToken.execute();
signer.tokenSharedSecret = tempCredentials.tokenSecret;
OAuthAuthorizeTemporaryTokenUrl authorizeUrl = new OAuthAuthorizeTemporaryTokenUrl(Constants.AUTHORIZE_URL);
authorizeUrl.temporaryToken = tempCredentials.token;
authorizationUrl = authorizeUrl.build();
handled = false;
} catch (Exception ex) {
ex.printStackTrace();
}
return null;
}
开发者ID:ipragmatech,项目名称:OAuth-Magento-Rest-Api-Retrofit,代码行数:28,代码来源:WebActivity.java
示例14: getOAuthAccessToken
import com.google.api.client.http.apache.ApacheHttpTransport; //导入依赖的package包/类
public OAuthGetAccessToken getOAuthAccessToken(String requestToken) {
signer.clientSharedSecret = Constants.CONSUMER_SECRET;
OAuthGetAccessToken accessToken = new OAuthGetAccessToken(Constants.ACCESS_URL);
accessToken.transport = new ApacheHttpTransport();
accessToken.temporaryToken = requestToken;
accessToken.signer = signer;
accessToken.consumerKey = Constants.CONSUMER_KEY;
return accessToken;
}
开发者ID:ipragmatech,项目名称:OAuth-Magento-Rest-Api-Retrofit,代码行数:10,代码来源:WebActivity.java
示例15: testSimpleRequest_connectionRefused_apacheHttpTransport
import com.google.api.client.http.apache.ApacheHttpTransport; //导入依赖的package包/类
@Test
public void testSimpleRequest_connectionRefused_apacheHttpTransport() throws IOException, Failure {
HttpRequestFactory factory = new ApacheHttpTransport().createRequestFactory();
GenericUrl url = new GenericUrl("http://localhost:" + (port - 10) + "/" + ENDPOINT);
TestService.Iface client = new TestService.Client(new HttpClientHandler(
() -> url, factory, provider));
try {
client.test(new Request("request"));
fail("No exception");
} catch (HttpHostConnectException ex) {
assertThat(ex.getMessage(), is(startsWith("Connect to localhost:" + (port - 10) + " failed: Connection refused")));
}
}
开发者ID:morimekta,项目名称:providence,代码行数:16,代码来源:HttpClientHandlerNetworkTest.java
示例16: HttpClientAssist
import com.google.api.client.http.apache.ApacheHttpTransport; //导入依赖的package包/类
public HttpClientAssist(@Nullable HttpClientConfig conf, @Nullable ProxySelector proxySelector) {
HttpClientConfig hcc = conf == null ? defaultHcc : conf.clone();
// httpTransport = new NetHttpTransport.Builder()
// .setConnectionFactory(url -> {
// Proxy proxy = hcc.proxy;
// if (proxyPicker != null)
// proxy = proxyPicker.pick();
// HttpURLConnection conn = (HttpURLConnection) (proxy == null ? url.openConnection()
// : url.openConnection(proxy));
// return conn;
// }).build();
ApacheHttpTransport.Builder apacheBuilder = new ApacheHttpTransport.Builder().setProxySelector(proxySelector);
HttpParams httpParams = apacheBuilder.getHttpParams();
HttpConnectionParams.setSoTimeout(httpParams, hcc.soTimeout);
HttpConnectionParams.setConnectionTimeout(httpParams, hcc.connectionTimeout);
ConnManagerParams.setMaxTotalConnections(httpParams, hcc.maxTotalConnections);
ConnManagerParams.setMaxConnectionsPerRoute(httpParams, new ConnPerRouteBean(hcc.maxConnectionsPerRoute));
httpTransport = apacheBuilder.build();
reqFactory = httpTransport.createRequestFactory(req -> {
req.setConnectTimeout(hcc.connectionTimeout)
.setReadTimeout(hcc.soTimeout)
.setSuppressUserAgentSuffix(true)
.setThrowExceptionOnExecuteError(false)
;
if (hcc.headers != null) {
req.getHeaders().putAll(hcc.headers);
}
req.getHeaders()
.setUserAgent(hcc.userAgent)
.put(HttpHeaders.CONNECTION, hcc.isKeepAlive ? "keep-alive" : "close")
;
});
}
开发者ID:myshzzx,项目名称:mlib,代码行数:38,代码来源:HttpClientAssist.java
示例17: getUserByIdToken
import com.google.api.client.http.apache.ApacheHttpTransport; //导入依赖的package包/类
public User getUserByIdToken(String idTokenString) throws GeneralSecurityException, IOException, IllegalArgumentException, ObjectNotFoundException, NdexException {
ApacheHttpTransport.Builder builder = new ApacheHttpTransport.Builder();
GoogleIdTokenVerifier localVerifier = new GoogleIdTokenVerifier.Builder(builder.build(), new JacksonFactory())
.setAudience(Collections.singletonList(clientID))
// Or, if multiple clients access the backend:
//.setAudience(Arrays.asList(CLIENT_ID_1, CLIENT_ID_2, CLIENT_ID_3))
.build();
GoogleIdToken idToken = localVerifier.verify(idTokenString);
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 = Boolean.valueOf(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"); */
try (UserDAO userDao = new UserDAO()) {
User user = userDao.getUserByEmail(email.toLowerCase(),true);
return user;
} catch ( SQLException e1) {
e1.printStackTrace();
throw new UnauthorizedOperationException("SQL Error when getting user by email: " + e1.getMessage());
}
}
throw new UnauthorizedOperationException("Invalid OAuth ID token.");
}
开发者ID:ndexbio,项目名称:ndex-rest,代码行数:39,代码来源:GoogleOpenIDAuthenticator.java
示例18: getUserUUIDByIdToken
import com.google.api.client.http.apache.ApacheHttpTransport; //导入依赖的package包/类
public UUID getUserUUIDByIdToken(String idTokenString) throws GeneralSecurityException, IOException, IllegalArgumentException, ObjectNotFoundException, NdexException {
ApacheHttpTransport.Builder builder = new ApacheHttpTransport.Builder();
GoogleIdTokenVerifier localVerifier = new GoogleIdTokenVerifier.Builder(builder.build(), new JacksonFactory())
.setAudience(Collections.singletonList(clientID))
// Or, if multiple clients access the backend:
//.setAudience(Arrays.asList(CLIENT_ID_1, CLIENT_ID_2, CLIENT_ID_3))
.build();
GoogleIdToken idToken = localVerifier.verify(idTokenString);
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();
try (UserDAO userDao = new UserDAO()) {
UUID userUUID = userDao.getUUIDByEmail(email.toLowerCase());
return userUUID;
} catch ( SQLException e1) {
e1.printStackTrace();
throw new UnauthorizedOperationException("SQL Error when getting user by email: " + e1.getMessage());
}
}
throw new UnauthorizedOperationException("Invalid OAuth ID token.");
}
开发者ID:ndexbio,项目名称:ndex-rest,代码行数:35,代码来源:GoogleOpenIDAuthenticator.java
示例19: HttpTail
import com.google.api.client.http.apache.ApacheHttpTransport; //导入依赖的package包/类
public HttpTail(String aUrl, long aStartingOffset, long aDelay) {
url = new GenericUrl(aUrl);
HttpTransport transport = new ApacheHttpTransport();
requestFactory = transport.createRequestFactory();
startingOffset = aStartingOffset;
delay = aDelay;
}
开发者ID:myfreeweb,项目名称:rxjava-http-tail,代码行数:8,代码来源:HttpTail.java
示例20: createSigningRequestFactory
import com.google.api.client.http.apache.ApacheHttpTransport; //导入依赖的package包/类
private HttpRequestFactory createSigningRequestFactory() {
HttpTransport httpTransport = new ApacheHttpTransport();
return httpTransport.createRequestFactory(new HttpRequestInitializer() {
@Override
public void initialize(HttpRequest request) throws IOException {
request.setInterceptor(new GoogleHttpClientEdgeGridInterceptor(credential));
}
});
}
开发者ID:akamai,项目名称:AkamaiOPEN-edgegrid-java,代码行数:10,代码来源:GoogleHttpClientEdgeGridInterceptorTest.java
注:本文中的com.google.api.client.http.apache.ApacheHttpTransport类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论