本文整理汇总了Java中com.google.api.client.http.HttpResponse.isSuccessStatusCode方法的典型用法代码示例。如果您正苦于以下问题:Java HttpResponse.isSuccessStatusCode方法的具体用法?Java HttpResponse.isSuccessStatusCode怎么用?Java HttpResponse.isSuccessStatusCode使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.api.client.http.HttpResponse
的用法示例。
在下文中一共展示了HttpResponse.isSuccessStatusCode方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: execute
import com.google.api.client.http.HttpResponse; //导入方法依赖的package包/类
public boolean execute() throws IOException {
try {
HttpResponse response = request.execute();
isSuccess = response.isSuccessStatusCode();
if (isSuccess) {
Map<String, String> oauthKeys = getQueryMap(response.parseAsString());
this.token = oauthKeys.get("oauth_token");
this.tokenSecret = oauthKeys.get("oauth_token_secret");
this.sessionHandle = oauthKeys.get("oauth_session_handle");
this.tokenTimestamp = System.currentTimeMillis() / 1000l;
isSuccess = true;
} else {
}
} catch (HttpResponseException e) {
Map<String, String> oauthError = getQueryMap(e.getMessage());
this.problem = oauthError.get("oauth_problem");
this.advice = oauthError.get("oauth_problem_advice");
isSuccess = false;
}
return isSuccess;
}
示例2: getClientEmail
import com.google.api.client.http.HttpResponse; //导入方法依赖的package包/类
public static String getClientEmail(String accessToken) throws IOException {
/*
* Get loggined user info as described in
* https://developers.google.com/accounts/docs/OAuth2Login#userinfocall
*/
GenericUrl url = new GenericUrl("https://www.googleapis.com/oauth2/v1/userinfo?access_token=" + accessToken);
HttpRequest request = HTTP_REQUEST_FACTORY.buildGetRequest(url);
HttpResponse response = request.execute();
if (!response.isSuccessStatusCode()) {
throw new IOException(response.getStatusMessage());
}
JsonElement jsonElement = new JsonParser().parse(new InputStreamReader(response.getContent(), "utf-8"));
JsonObject jsonObj = jsonElement.getAsJsonObject();
return jsonObj.get("email").getAsString();
}
示例3: handleResponse
import com.google.api.client.http.HttpResponse; //导入方法依赖的package包/类
@Override
public boolean handleResponse(
HttpRequest httpRequest,
HttpResponse httpResponse, boolean supportsRetry) throws IOException {
if (!httpResponse.isSuccessStatusCode() && httpResponse.getStatusCode() == ACCESS_DENIED) {
throwNullCredentialException();
}
return supportsRetry;
}
示例4: executeAndParse
import com.google.api.client.http.HttpResponse; //导入方法依赖的package包/类
<T> T executeAndParse(HttpRequest request, Class<T> cls) throws IOException {
if (log.isDebugEnabled()) {
log.debug("Calling {} on {}", request.getRequestMethod(), request.getUrl());
}
HttpResponse response = request.execute();
if (response.isSuccessStatusCode()) {
return response.parseAs(cls);
} else {
SalesforceException exception = response.parseAs(SalesforceException.class);
throw exception;
}
}