本文整理汇总了Java中com.google.api.client.http.HttpResponse.getStatusCode方法的典型用法代码示例。如果您正苦于以下问题:Java HttpResponse.getStatusCode方法的具体用法?Java HttpResponse.getStatusCode怎么用?Java HttpResponse.getStatusCode使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.api.client.http.HttpResponse
的用法示例。
在下文中一共展示了HttpResponse.getStatusCode方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: delete
import com.google.api.client.http.HttpResponse; //导入方法依赖的package包/类
protected Response delete(String endPoint) throws IOException {
HttpResponse resp = null;
OAuthRequestResource req = new OAuthRequestResource(config, signerFactory, endPoint, "DELETE", null, null);
req.setToken(token);
req.setTokenSecret(tokenSecret);
try {
resp = req.execute();
// No-Content Returned from Xero API
if (resp.getStatusCode() == 204) {
return unmarshallResponse("<Response><Status>DELETED</Status></Response>", Response.class);
}
return unmarshallResponse(resp.parseAsString(), Response.class);
} catch (IOException ioe) {
throw xeroExceptionHandler.convertException(ioe);
}
}
示例2: sendPostMultipart
import com.google.api.client.http.HttpResponse; //导入方法依赖的package包/类
public static int sendPostMultipart(String urlString, Map<String, String> parameters)
throws IOException {
MultipartContent postBody = new MultipartContent()
.setMediaType(new HttpMediaType("multipart/form-data"));
postBody.setBoundary(MULTIPART_BOUNDARY);
for (Map.Entry<String, String> entry : parameters.entrySet()) {
HttpContent partContent = ByteArrayContent.fromString( // uses UTF-8 internally
null /* part Content-Type */, entry.getValue());
HttpHeaders partHeaders = new HttpHeaders()
.set("Content-Disposition", "form-data; name=\"" + entry.getKey() + "\"");
postBody.addPart(new MultipartContent.Part(partHeaders, partContent));
}
GenericUrl url = new GenericUrl(new URL(urlString));
HttpRequest request = transport.createRequestFactory().buildPostRequest(url, postBody);
request.setHeaders(new HttpHeaders().setUserAgent(CloudToolsInfo.USER_AGENT));
request.setConnectTimeout(DEFAULT_CONNECT_TIMEOUT_MS);
request.setReadTimeout(DEFAULT_READ_TIMEOUT_MS);
HttpResponse response = request.execute();
return response.getStatusCode();
}
示例3: executeStmt
import com.google.api.client.http.HttpResponse; //导入方法依赖的package包/类
public String executeStmt(String method, String urlString, String statement, List<NameValuePair> qparams)
throws IOException {
Check.notNull(statement);
GenericUrl url = setParams(new GenericUrl(urlString), qparams);
UrlEncodedContent urlEntity = setMediaType(getUrlEncodedSql(statement));
HttpRequestFactory rf = httpTransport.createRequestFactory(credential);
HttpResponse response = rf.buildRequest(method, url, urlEntity).execute();
String result = readGoogleResponse(response);
if (response.getStatusCode() != HttpServletResponse.SC_OK)
throw new RuntimeException(result.toString() + statement);
return result;
}
示例4: processStatusCheck
import com.google.api.client.http.HttpResponse; //导入方法依赖的package包/类
public String processStatusCheck(String modelId) throws IOException, GeneralSecurityException {
HttpResponse httpResponse = client.trainedmodels().get(Constants.PROJECT_NAME, modelId).executeUnparsed();
int status = httpResponse.getStatusCode();
System.out.println("HTTP Status : " + status);
String trainingStatus = null;
if (status == 200) {
Insert2 res = responseToObject(httpResponse.parseAsString());
trainingStatus = res.getTrainingStatus();
System.out.println("Training Status : " + trainingStatus);
if (trainingStatus.compareTo("DONE") == 0) {
System.out.println("training complete");
System.out.println(res.getModelInfo());
}
} else {
httpResponse.ignore();
}
return trainingStatus;
}
示例5: fetch
import com.google.api.client.http.HttpResponse; //导入方法依赖的package包/类
/**
* Fetches the service configuration with the given service name and service version.
*
* @param serviceName the given service name
* @param serviceVersion the given service version
* @return a {@link Service} object generated by the JSON response from Google Service Management.
*/
private Service fetch(String serviceName, @Nullable String serviceVersion) {
Preconditions.checkArgument(
!Strings.isNullOrEmpty(serviceName), "service name must be specified");
if (serviceVersion == null) {
serviceVersion = fetchLatestServiceVersion(serviceName);
}
final HttpResponse httpResponse;
try {
httpResponse = serviceManagement.services().configs().get(serviceName, serviceVersion)
.setFields(FIELD_MASKS)
.executeUnparsed();
} catch (IOException exception) {
throw new ServiceConfigException(exception);
}
int statusCode = httpResponse.getStatusCode();
if (statusCode != HttpStatusCodes.STATUS_CODE_OK) {
String message = MessageFormat.format(
"Failed to fetch service config (status code {0})",
statusCode);
throw new ServiceConfigException(message);
}
Service service = parseHttpResponse(httpResponse);
validateServiceConfig(service, serviceName, serviceVersion);
return service;
}
示例6: exchangeAuthorizationForToken
import com.google.api.client.http.HttpResponse; //导入方法依赖的package包/类
public OauthToken exchangeAuthorizationForToken(String code, String clientId, String clientSecret, Map<String, Object> options) throws DnsimpleException, IOException {
Map<String, Object> attributes = new HashMap<String, Object>();
attributes.put("code", code);
attributes.put("client_id", clientId);
attributes.put("client_secret", clientSecret);
attributes.put("grant_type", "authorization_code");
if (options.containsKey("state")) {
attributes.put("state", options.remove("state"));
}
if (options.containsKey("redirect_uri")) {
attributes.put("redirect_uri", options.remove("redirect_uri"));
}
HttpResponse response = client.post("oauth/access_token", attributes);
InputStream in = response.getContent();
if (in == null) {
throw new DnsimpleException("Response was empty", null, response.getStatusCode());
} else {
try {
JsonParser jsonParser = GsonFactory.getDefaultInstance().createJsonParser(in);
return jsonParser.parse(OauthToken.class);
} finally {
in.close();
}
}
}
示例7: postRequest
import com.google.api.client.http.HttpResponse; //导入方法依赖的package包/类
@VisibleForTesting
InputStream postRequest(String url, String boundary, String content) throws IOException {
HttpRequestFactory requestFactory = new NetHttpTransport().createRequestFactory();
HttpRequest request = requestFactory.buildPostRequest(new GenericUrl(url),
ByteArrayContent.fromString("multipart/form-data; boundary=" + boundary, content));
request.setReadTimeout(60000); // 60 seconds is the max App Engine request time
HttpResponse response = request.execute();
if (response.getStatusCode() >= 300) {
throw new IOException("Client Generation failed at server side: " + response.getContent());
} else {
return response.getContent();
}
}
示例8: 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;
}
示例9: executeStmt
import com.google.api.client.http.HttpResponse; //导入方法依赖的package包/类
public String executeStmt(String method, String urlString, String statement, List<NameValuePair> qparams)
throws IOException {
Check.notNull(statement);
GenericUrl url = setParams(new GenericUrl(urlString), qparams);
UrlEncodedContent urlEntity = setMediaType(getUrlEncodedSql(statement));
HttpRequestFactory rf = httpTransport.createRequestFactory(credential);
HttpResponse response = rf.buildRequest(method, url, urlEntity).execute();
String result = readGoogleResponse(response);
if (response.getStatusCode() != HttpServletResponse.SC_OK)
throw new IOException(result.toString() + statement);
return result;
}
示例10: put
import com.google.api.client.http.HttpResponse; //导入方法依赖的package包/类
@Override
public void put(Collection<SinkRecord> collection) {
if (collection.isEmpty()) {
log.trace("No records in collection.");
return;
}
try {
log.trace("Posting {} message(s) to {}", collection.size(), this.eventCollectorUrl);
SinkRecordContent sinkRecordContent = new SinkRecordContent(collection);
if (log.isTraceEnabled()) {
try (ByteArrayOutputStream outputStream = new ByteArrayOutputStream()) {
sinkRecordContent.writeTo(outputStream);
outputStream.flush();
byte[] buffer = outputStream.toByteArray();
log.trace("Posting\n{}", new String(buffer, "UTF-8"));
} catch (IOException ex) {
if (log.isTraceEnabled()) {
log.trace("exception thrown while previewing post", ex);
}
}
}
HttpRequest httpRequest = this.httpRequestFactory.buildPostRequest(this.eventCollectorUrl, sinkRecordContent);
HttpResponse httpResponse = httpRequest.execute();
if (httpResponse.getStatusCode() == 403) {
throw new ConnectException("Authentication was not successful. Please check the token with Splunk.");
}
if (httpResponse.getStatusCode() == 417) {
log.warn("This exception happens when too much content is pushed to splunk per call. Look at this blog post " +
"http://blogs.splunk.com/2016/08/12/handling-http-event-collector-hec-content-length-too-large-errors-without-pulling-your-hair-out/" +
" Setting consumer.max.poll.records to a lower value will decrease the number of message posted to Splunk " +
"at once.");
throw new ConnectException("Status 417: Content-Length of XXXXX too large (maximum is 1000000). Verify Splunk config or " +
" lower the value in consumer.max.poll.records.");
}
if (JSON_MEDIA_TYPE.equalsIgnoreParameters(httpResponse.getMediaType())) {
SplunkStatusMessage statusMessage = httpResponse.parseAs(SplunkStatusMessage.class);
if (!statusMessage.isSuccessful()) {
throw new RetriableException(statusMessage.toString());
}
} else {
throw new RetriableException("Media type of " + Json.MEDIA_TYPE + " was not returned.");
}
} catch (IOException e) {
throw new RetriableException(
String.format("Exception while posting data to %s.", this.eventCollectorUrl),
e
);
}
}
示例11: isRateLimitExceeded
import com.google.api.client.http.HttpResponse; //导入方法依赖的package包/类
private boolean isRateLimitExceeded(HttpResponse response) {
return response.getStatusCode() == HttpStatusCodes.STATUS_CODE_FORBIDDEN
&& isRateLimitExceeded(GoogleJsonResponseException.from(JSON_FACTORY, response));
}