本文整理了Java中com.google.api.client.http.HttpResponse.getStatusMessage()
方法的一些代码示例,展示了HttpResponse.getStatusMessage()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。HttpResponse.getStatusMessage()
方法的具体详情如下:
包路径:com.google.api.client.http.HttpResponse
类名称:HttpResponse
方法名:getStatusMessage
暂无
代码示例来源: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
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 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
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 <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: 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: googleapis/google-cloud-java
response = httpRequest.execute();
code = response.getStatusCode();
message = response.getStatusMessage();
} catch (HttpResponseException ex) {
exception = ex;
代码示例来源:origin: googleapis/google-cloud-java
response = httpRequest.execute();
code = response.getStatusCode();
message = response.getStatusMessage();
} catch (HttpResponseException ex) {
exception = ex;
代码示例来源:origin: googleapis/google-cloud-java
GoogleJsonError error = new GoogleJsonError();
error.setCode(response.getStatusCode());
error.setMessage(response.getStatusMessage());
throw translate(error);
代码示例来源:origin: GoogleCloudPlatform/java-docs-samples
throw new RuntimeException(response.getStatusMessage());
代码示例来源:origin: GoogleCloudPlatform/java-docs-samples
throw new RuntimeException(response.getStatusMessage());
代码示例来源:origin: googleads/googleads-java-lib
/**
* Constructs a new instance from a {@link HttpResponse}.
*
* @param httpResponse the response
* @param totalContentLength the total content length for the batch job, including the length
* from this response's corresponding request
* @param resumableSessionURI the URI to use for further incremental uploads
* @throws IOException if unable to get attributes of the response
* @throws NullPointerException is {@code httpResponse} is null.
*/
public BatchJobUploadResponse(HttpResponse httpResponse, long totalContentLength,
@Nullable URI resumableSessionURI) throws IOException {
this(Preconditions.checkNotNull(httpResponse, "Null HTTP response").getContent(),
httpResponse.getStatusCode(), httpResponse.getStatusMessage(), totalContentLength,
resumableSessionURI);
}
代码示例来源:origin: deric/gitlab-ci-mesos
public void content(HttpResponse response) throws IOException {
//Result result = response.parseAs(Result.class);
System.out.println(response.getStatusCode());
System.out.println(response.getStatusMessage());
System.out.println(response.getContentType());
InputStream is = response.getContent();
int ch;
while ((ch = is.read()) != -1) {
System.out.print((char) ch);
}
response.disconnect();
}
代码示例来源:origin: com.google.api-ads/ads-lib
/**
* Constructs a new instance from a {@link HttpResponse}.
*
* @param httpResponse the response
* @param totalContentLength the total content length for the batch job, including the length
* from this response's corresponding request
* @param resumableSessionURI the URI to use for further incremental uploads
* @throws IOException if unable to get attributes of the response
* @throws NullPointerException is {@code httpResponse} is null.
*/
public BatchJobUploadResponse(HttpResponse httpResponse, long totalContentLength,
@Nullable URI resumableSessionURI) throws IOException {
this(Preconditions.checkNotNull(httpResponse, "Null HTTP response").getContent(),
httpResponse.getStatusCode(), httpResponse.getStatusMessage(), totalContentLength,
resumableSessionURI);
}
代码示例来源: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());
}
}
代码示例来源:origin: googleads/googleads-java-lib
@Override
public void interceptResponse(HttpResponse response) throws IOException {
if (response == null) {
return;
}
reportServiceLogger.logRequest(
response.getRequest(), response.getStatusCode(), response.getStatusMessage());
}
}
内容来源于网络,如有侵权,请联系作者删除!