本文整理汇总了Java中com.google.api.client.http.apache.ApacheHttpTransport.Builder方法的典型用法代码示例。如果您正苦于以下问题:Java ApacheHttpTransport.Builder方法的具体用法?Java ApacheHttpTransport.Builder怎么用?Java ApacheHttpTransport.Builder使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.api.client.http.apache.ApacheHttpTransport
的用法示例。
在下文中一共展示了ApacheHttpTransport.Builder方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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();
}
}
示例2: 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")
;
});
}
示例3: 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.");
}
示例4: 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.");
}
示例5: execute
import com.google.api.client.http.apache.ApacheHttpTransport; //导入方法依赖的package包/类
/**
* Executes the HTTP request for a temporary or long-lived token.
*
* @throws IOException
*/
public final HttpResponse execute() throws IOException {
ApacheHttpTransport.Builder builder = new ApacheHttpTransport.Builder();
if(this.proxyEnabled) {
builder.setProxy(this.proxy);
}
transport = builder.build();
if(usePost && body != null){
requestBody = ByteArrayContent.fromString(null, body);
}
HttpHeaders headers = new HttpHeaders();
headers.setUserAgent(config.getUserAgent());
headers.setAccept(accept != null ? accept : config.getAccept());
headers.setContentType(contentType == null ? "application/xml" : contentType);
if(ifModifiedSince != null) {
//System.out.println("Set Header " + this.ifModifiedSince);
headers.setIfModifiedSince(this.ifModifiedSince);
}
HttpRequestFactory requestFactory = transport.createRequestFactory();
HttpRequest request;
HttpResponse response = null;
request = requestFactory.buildRequest(this.httpMethod, Url, requestBody);
request.setConnectTimeout(connectTimeout);
request.setReadTimeout(readTimeout);
request.setHeaders(headers);
createParameters().intercept(request);
response = request.execute();
response.setContentLoggingLimit(0);
return response;
}
示例6: createApacheHttpTransport
import com.google.api.client.http.apache.ApacheHttpTransport; //导入方法依赖的package包/类
/**
* Create an {@link ApacheHttpTransport} for calling Google APIs with an optional HTTP proxy.
*
* @param proxy Optional HTTP proxy to use with the transport.
* @return The resulting HttpTransport.
* @throws IOException If there is an issue connecting to Google's certification server.
* @throws GeneralSecurityException If there is a security issue with the keystore.
*/
public static ApacheHttpTransport createApacheHttpTransport(@Nullable HttpHost proxy)
throws IOException, GeneralSecurityException {
ApacheHttpTransport.Builder builder = new ApacheHttpTransport.Builder();
builder.trustCertificates(GoogleUtils.getCertificateTrustStore());
builder.setProxy(proxy);
return builder.build();
}