本文整理了Java中com.google.api.client.http.HttpResponse.getStatusCode()
方法的一些代码示例,展示了HttpResponse.getStatusCode()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。HttpResponse.getStatusCode()
方法的具体详情如下:
包路径:com.google.api.client.http.HttpResponse
类名称:HttpResponse
方法名:getStatusCode
暂无
代码示例来源:origin: GoogleContainerTools/jib
/** @return the HTTP status code of the response */
public int getStatusCode() {
return httpResponse.getStatusCode();
}
代码示例来源:origin: google/data-transfer-project
private static void validateResponse(HttpResponse response, int expectedCode) throws IOException {
if (response.getStatusCode() != expectedCode) {
throw new IOException("Unexpected return code: "
+ response.getStatusCode()
+ "\nMessage:\n"
+ response.getStatusMessage()
+ "\nHeaders:\n"
+ response.getHeaders());
}
}
代码示例来源:origin: google/data-transfer-project
private static void validateResponse(
HttpRequest request, HttpResponse response, int expectedCode) throws IOException {
if (response.getStatusCode() != expectedCode) {
throw new IOException("Unexpected return code: "
+ response.getStatusCode()
+ "\nMessage:\n"
+ response.getStatusMessage()
+ "\nfrom:\n"
+ request.getUrl()
+ "\nHeaders:\n"
+ response.getHeaders());
}
}
代码示例来源:origin: google/data-transfer-project
static <T> T makePostRequest(HttpTransport httpTransport, String url, HttpContent httpContent,
Class<T> clazz) throws IOException {
HttpRequestFactory factory = httpTransport.createRequestFactory();
HttpRequest postRequest = factory.buildPostRequest(new GenericUrl(url), httpContent);
HttpResponse response = postRequest.execute();
int statusCode = response.getStatusCode();
if (statusCode != 200) {
throw new IOException(
"Bad status code: " + statusCode + " error: " + response.getStatusMessage());
}
String result = CharStreams
.toString(new InputStreamReader(response.getContent(), Charsets.UTF_8));
return new ObjectMapper().readValue(result, clazz);
}
}
代码示例来源:origin: google/data-transfer-project
private <T> T makeGetRequest(String url, Optional<Map<String, String>> parameters, Class<T> clazz)
throws IOException {
HttpRequestFactory requestFactory = httpTransport.createRequestFactory();
HttpRequest getRequest = requestFactory
.buildGetRequest(new GenericUrl(url + "?" + generateParamsString(parameters)));
HttpResponse response = getRequest.execute();
int statusCode = response.getStatusCode();
if (statusCode != 200) {
throw new IOException(
"Bad status code: " + statusCode + " error: " + response.getStatusMessage());
}
String result = CharStreams
.toString(new InputStreamReader(response.getContent(), Charsets.UTF_8));
return objectMapper.readValue(result, clazz);
}
代码示例来源:origin: google/data-transfer-project
private String getToken(String frob) throws IOException {
URL signedUrl =
signatureGenerator.getSignature(
GET_TOKEN_URL, ImmutableMap.of("frob", frob, "method", GET_TOKEN_METHOD));
HttpRequestFactory requestFactory = HTTP_TRANSPORT.createRequestFactory();
HttpRequest getRequest = requestFactory.buildGetRequest(new GenericUrl(signedUrl));
HttpResponse response = getRequest.execute();
int statusCode = response.getStatusCode();
if (statusCode != 200) {
throw new IOException(
"Bad status code: " + statusCode + " error: " + response.getStatusMessage());
}
AuthElement authElement = xmlMapper.readValue(response.getContent(), AuthElement.class);
Preconditions.checkState(authElement.stat.equals("ok"), "state must be ok: %s", authElement);
Preconditions.checkState(
!Strings.isNullOrEmpty(authElement.auth.token), "token must not be empty", authElement);
return authElement.auth.token;
}
}
代码示例来源:origin: google/data-transfer-project
private <T> T makeRequest(String url, Class<T> clazz, TokensAndUrlAuthData authData)
throws IOException {
HttpRequestFactory requestFactory = httpTransport.createRequestFactory();
HttpRequest getRequest =
requestFactory.buildGetRequest(
new GenericUrl(url + "?access_token=" + authData.getAccessToken()));
HttpResponse response = getRequest.execute();
int statusCode = response.getStatusCode();
if (statusCode != 200) {
throw new IOException(
"Bad status code: " + statusCode + " error: " + response.getStatusMessage());
}
String result =
CharStreams.toString(new InputStreamReader(response.getContent(), Charsets.UTF_8));
return objectMapper.readValue(result, clazz);
}
}
代码示例来源:origin: google/data-transfer-project
<T> T makePostRequest(String url, Optional<Map<String, String>> parameters,
HttpContent httpContent, Class<T> clazz)
throws IOException {
HttpRequestFactory requestFactory = httpTransport.createRequestFactory();
HttpRequest postRequest = requestFactory
.buildPostRequest(new GenericUrl(url + "?" + generateParamsString(parameters)),
httpContent);
HttpResponse response = postRequest.execute();
int statusCode = response.getStatusCode();
if (statusCode != 200) {
throw new IOException(
"Bad status code: " + statusCode + " error: " + response.getStatusMessage());
}
String result = CharStreams
.toString(new InputStreamReader(response.getContent(), Charsets.UTF_8));
if (clazz.isAssignableFrom(String.class)) {
return (T) result;
} else {
return objectMapper.readValue(result, clazz);
}
}
代码示例来源:origin: google/data-transfer-project
private String makeCall(HttpTransport transport) throws IOException {
HttpRequest get =
transport.createRequestFactory()
.buildPostRequest(new GenericUrl(INRPUT_LOGIN_SERVER), null)
.setFollowRedirects(false)
.setThrowExceptionOnExecuteError(false);
HttpResponse response = get.execute();
if (response.getStatusCode() != 302) {
throw new IOException("Unexpected return code: "
+ response.getStatusCode()
+ "\nMessage:\n"
+ response.getStatusMessage());
}
String cookieValue = response.getHeaders().getFirstHeaderStringValue("set-cookie");
if (Strings.isNullOrEmpty(cookieValue)) {
throw new IOException("Couldn't extract cookie value from headers: " + response.getHeaders());
}
return cookieValue;
}
}
代码示例来源:origin: google/data-transfer-project
/**
* Parses the contents of a URL to produce an RDF model.
*/
public Model getModel(String url) throws IOException {
HttpRequestFactory factory = TRANSPORT.createRequestFactory();
HttpRequest rootGetRequest = factory.buildGetRequest(
new GenericUrl(url));
HttpHeaders headers = new HttpHeaders();
headers.setCookie(authCookie);
headers.setAccept("text/turtle");
rootGetRequest.setHeaders(headers);
HttpResponse response = rootGetRequest.execute();
if (response.getStatusCode() != 200) {
throw new IOException("Unexpected return code: "
+ response.getStatusCode()
+ "\nMessage:\n"
+ response.getStatusMessage());
}
StringWriter writer = new StringWriter();
IOUtils.copy(response.getContent(), writer, "UTF-8");
String fixedString = fixProblematicPeriods(writer.toString());
Model defaultModel = ModelFactory.createDefaultModel();
return defaultModel.read(
new StringReader(fixedString),
url,
"TURTLE");
}
代码示例来源:origin: google/data-transfer-project
private <T extends RememberTheMilkResponse> T makeRequest(
Map<String, String> parameters, Class<T> dataClass) throws IOException {
URL signedUrl = signatureGenerator.getSignature(BASE_URL, parameters);
HttpRequestFactory requestFactory = HTTP_TRANSPORT.createRequestFactory();
HttpRequest getRequest = requestFactory.buildGetRequest(new GenericUrl(signedUrl));
HttpResponse response = getRequest.execute();
int statusCode = response.getStatusCode();
if (statusCode != 200) {
throw new IOException(
"Bad status code: " + statusCode + " error: " + response.getStatusMessage());
}
T parsedResponse = xmlMapper.readValue(response.getContent(), dataClass);
if (parsedResponse.error != null) {
throw new IOException(
"Error making call to " + signedUrl + " error: " + parsedResponse.error);
}
return parsedResponse;
}
代码示例来源:origin: googleapis/google-cloud-java
try {
response = httpRequest.execute();
code = response.getStatusCode();
message = response.getStatusMessage();
} catch (HttpResponseException ex) {
代码示例来源:origin: googleapis/google-cloud-java
try {
response = httpRequest.execute();
code = response.getStatusCode();
message = response.getStatusMessage();
} catch (HttpResponseException ex) {
代码示例来源:origin: googleapis/google-cloud-java
if (response.getStatusCode() != 200) {
GoogleJsonError error = new GoogleJsonError();
error.setCode(response.getStatusCode());
error.setMessage(response.getStatusMessage());
throw translate(error);
代码示例来源:origin: google/google-api-java-client-samples
if (response.getStatusCode() == 200) {
trainingModel = response.parseAs(Insert2.class);
String trainingStatus = trainingModel.getTrainingStatus();
代码示例来源:origin: com.google.oauth-client/google-oauth-client-servlet
public boolean handleResponse(
HttpRequest request, HttpResponse response, boolean retrySupported) {
if (response.getStatusCode() == HttpStatusCodes.STATUS_CODE_UNAUTHORIZED) {
// If the token was revoked, we must mark our credential as invalid
token = null;
}
// We didn't do anything to fix the problem
return false;
}
代码示例来源:origin: com.google.auth/google-auth-library-oauth2-http
public boolean isRequired(HttpResponse response) {
int code = response.getStatusCode();
return (
// Server error --- includes timeout errors, which use 500 instead of 408
code / 100 == 5
// Forbidden error --- for historical reasons, used for rate_limit_exceeded
// errors instead of 429, but there currently seems no robust automatic way to
// distinguish these cases: see
// https://github.com/google/google-api-java-client/issues/662
|| code == 403);
}
}));
代码示例来源:origin: GoogleCloudPlatform/java-docs-samples
if (response.getStatusCode() != 200) {
throw new RuntimeException(response.getStatusMessage());
代码示例来源:origin: GoogleCloudPlatform/java-docs-samples
if (response.getStatusCode() != 200) {
throw new RuntimeException(response.getStatusMessage());
代码示例来源:origin: com.google.api-ads/ads-lib
@Override
public void interceptResponse(HttpResponse response) throws IOException {
if (response == null) {
return;
}
reportServiceLogger.logRequest(
response.getRequest(), response.getStatusCode(), response.getStatusMessage());
}
}
内容来源于网络,如有侵权,请联系作者删除!