com.google.appengine.api.urlfetch.HTTPResponse.getResponseCode()方法的使用及代码示例

x33g5p2x  于2022-01-20 转载在 其他  
字(8.6k)|赞(0)|评价(0)|浏览(144)

本文整理了Java中com.google.appengine.api.urlfetch.HTTPResponse.getResponseCode()方法的一些代码示例,展示了HTTPResponse.getResponseCode()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。HTTPResponse.getResponseCode()方法的具体详情如下:
包路径:com.google.appengine.api.urlfetch.HTTPResponse
类名称:HTTPResponse
方法名:getResponseCode

HTTPResponse.getResponseCode介绍

暂无

代码示例

代码示例来源:origin: googlemaps/google-maps-services-java

private boolean shouldRetry(HTTPResponse response) {
 return RETRY_ERROR_CODES.contains(response.getResponseCode())
   && cumulativeSleepTime < errorTimeOut
   && (maxRetries == null || retryCounter < maxRetries);
}

代码示例来源:origin: googlemaps/google-maps-services-java

&& contentType.startsWith("image")
  && responseClass == ImageResult.Response.class
  && response.getResponseCode() == 200) {
 ImageResult result = new ImageResult(contentType, bytes);
 return (T) result;
} catch (JsonSyntaxException e) {
 if (response.getResponseCode() > 399) {
    String.format(
      "Server Error: %d %s",
      response.getResponseCode(),
      new String(response.getContent(), Charset.defaultCharset())));

代码示例来源:origin: com.google.http-client/google-http-client-appengine

@Override
public int getStatusCode() {
 return fetchResponse.getResponseCode();
}

代码示例来源:origin: com.google.http-client/google-http-client-extensions

@Override
public int getStatusCode() {
 return fetchResponse.getResponseCode();
}

代码示例来源:origin: com.google.maps/google-maps-services

private boolean shouldRetry(HTTPResponse response) {
 return RETRY_ERROR_CODES.contains(response.getResponseCode())
   && cumulativeSleepTime < errorTimeOut
   && (maxRetries == null || retryCounter < maxRetries);
}

代码示例来源:origin: com.threewks.thundr/thundr-gae

@Override
public int getStatus() {
  return response().getResponseCode();
}

代码示例来源:origin: GoogleCloudPlatform/appengine-gcs-client

static void appendResponse(HTTPResponse resp, StringBuilder b) {
 byte[] content = resp.getContent();
 b.append(resp.getResponseCode()).append(" with ").append(content == null ? 0 : content.length);
 b.append(" bytes of content");
 for (HTTPHeader h : resp.getHeadersUncombined()) {
  b.append('\n').append(h.getName()).append(": ").append(h.getValue());
 }
 b.append('\n').append(content == null ? "" : new String(content, UTF_8)).append('\n');
}

代码示例来源:origin: GoogleCloudPlatform/appengine-gcs-client

public static IOException error(HTTPRequestInfo req, HTTPResponse resp) throws IOException {
  return error(resp.getResponseCode(), URLFetchUtils.describeRequestAndResponse(req, resp));
 }
}

代码示例来源:origin: com.dropbox.core/dropbox-core-sdk

private static Response toRequestorResponse(HTTPResponse response) {
  Map<String, List<String>> headers = new HashMap<String, List<String>>();
  for (HTTPHeader header : response.getHeadersUncombined()) {
    List<String> existing = headers.get(header.getName());
    if (existing == null) {
      existing = new ArrayList<String>();
      headers.put(header.getName(), existing);
    }
    existing.add(header.getValue());
  }
  return new Response(response.getResponseCode(),
            new ByteArrayInputStream(response.getContent()),
            headers);
}

代码示例来源:origin: GoogleCloudPlatform/appengine-tck

public void handle(HTTPResponse response) throws Exception {
    Assert.assertEquals(302, response.getResponseCode());
  }
});

代码示例来源:origin: GoogleCloudPlatform/appengine-tck

public void handle(HTTPResponse response) throws Exception {
    Assert.assertEquals(302, response.getResponseCode());
  }
});

代码示例来源:origin: stackoverflow.com

String pivotalUrl = "http://www.pivotaltracker.com/services/v3/projects/"+projectID+"/stories"

String body = "<story><story_type>feature</story_type><name>Story name</name><requested_by>James Kirk</requested_by></story>"

URLFetchService fetchService = URLFetchServiceFactory.getURLFetchService();
HTTPRequest request =  new HTTPRequest(pivotalUrl, HTTPMethod.POST, FetchOptions.Builder.withDeadline(30));
request.addHeader(new HTTPHeader("X-TrackerToken","putTokenHere"));
request.addHeader(new HTTPHeader("Content-type","application/xml"));

HTTPResponse response = fetchService.fetch(request);
if (response.getResponseCode() != 200) {
  // something went wrong
}

代码示例来源:origin: jclouds/legacy-jclouds

@Test
void testConvertWithHeaders() throws IOException {
 HTTPResponse gaeResponse = createMock(HTTPResponse.class);
 expect(gaeResponse.getResponseCode()).andReturn(200);
 List<HTTPHeader> headers = Lists.newArrayList();
 headers.add(new HTTPHeader(HttpHeaders.CONTENT_TYPE, "text/xml"));
 expect(gaeResponse.getHeaders()).andReturn(headers);
 expect(gaeResponse.getContent()).andReturn(null).atLeastOnce();
 replay(gaeResponse);
 HttpResponse response = req.apply(gaeResponse);
 assertEquals(response.getStatusCode(), 200);
 assertEquals(response.getPayload(), null);
 assertEquals(response.getHeaders().size(), 0);
}

代码示例来源:origin: apache/jclouds

@Test
void testConvertWithHeaders() throws IOException {
 HTTPResponse gaeResponse = createMock(HTTPResponse.class);
 expect(gaeResponse.getResponseCode()).andReturn(200);
 List<HTTPHeader> headers = Lists.newArrayList();
 headers.add(new HTTPHeader(HttpHeaders.CONTENT_TYPE, "text/xml"));
 expect(gaeResponse.getHeaders()).andReturn(headers);
 expect(gaeResponse.getContent()).andReturn(null).atLeastOnce();
 replay(gaeResponse);
 HttpResponse response = req.apply(gaeResponse);
 assertEquals(response.getStatusCode(), 200);
 assertEquals(response.getPayload(), null);
 assertEquals(response.getHeaders().size(), 0);
}

代码示例来源:origin: jclouds/legacy-jclouds

@Test
void testConvertWithContent() throws IOException {
 HTTPResponse gaeResponse = createMock(HTTPResponse.class);
 expect(gaeResponse.getResponseCode()).andReturn(200);
 List<HTTPHeader> headers = Lists.newArrayList();
 headers.add(new HTTPHeader(HttpHeaders.CONTENT_TYPE, "text/xml"));
 expect(gaeResponse.getHeaders()).andReturn(headers);
 expect(gaeResponse.getContent()).andReturn("hello".getBytes()).atLeastOnce();
 replay(gaeResponse);
 HttpResponse response = req.apply(gaeResponse);
 assertEquals(response.getStatusCode(), 200);
 assertEquals(Strings2.toString(response.getPayload()), "hello");
 assertEquals(response.getHeaders().size(), 0);
 assertEquals(response.getPayload().getContentMetadata().getContentType(), "text/xml");
}

代码示例来源:origin: GoogleCloudPlatform/appengine-tck

protected String fetchUrl(String url, int expectedResponse) throws IOException {
  URLFetchService urlFetchService = URLFetchServiceFactory.getURLFetchService();
  HTTPResponse httpResponse = urlFetchService.fetch(new URL(url));
  assertEquals(url, expectedResponse, httpResponse.getResponseCode());
  return new String(httpResponse.getContent());
}

代码示例来源:origin: GoogleCloudPlatform/appengine-gcs-client

@Override
public void putObject(GcsFilename filename, GcsFileOptions options, ByteBuffer content,
  long timeoutMillis) throws IOException {
 HTTPRequest req = makeRequest(filename, null, PUT, timeoutMillis, content);
 addOptionsHeaders(req, options);
 HTTPResponse resp;
 try {
  resp = urlfetch.fetch(req);
 } catch (IOException e) {
  throw createIOException(new HTTPRequestInfo(req), e);
 }
 if (resp.getResponseCode() != 200) {
  throw HttpErrorHandler.error(new HTTPRequestInfo(req), resp);
 }
}

代码示例来源:origin: org.codehaus.groovy.modules.http-builder/http-builder

public HttpResponse receiveResponseHeader()
  throws HttpException, IOException {
  if (this.response == null) {
   flush();
  }

  HttpResponse response = new BasicHttpResponse(new ProtocolVersion("HTTP", 1, 1),
             this.response.getResponseCode(),
             null);
//     System.err.println("RECV: " + response.getStatusLine());

  for (HTTPHeader h : this.response.getHeaders()) {
//       System.err.println("RECV: " + h.getName() + ": " + h.getValue());
   response.addHeader(h.getName(), h.getValue());
  }

  return response;
 }

代码示例来源:origin: jgritman/httpbuilder

public HttpResponse receiveResponseHeader()
  throws HttpException, IOException {
  if (this.response == null) {
   flush();
  }

  HttpResponse response = new BasicHttpResponse(new ProtocolVersion("HTTP", 1, 1),
             this.response.getResponseCode(),
             null);
//     System.err.println("RECV: " + response.getStatusLine());

  for (HTTPHeader h : this.response.getHeaders()) {
//       System.err.println("RECV: " + h.getName() + ": " + h.getValue());
   response.addHeader(h.getName(), h.getValue());
  }

  return response;
 }

代码示例来源:origin: GoogleCloudPlatform/appengine-tck

@Test(expected = IOException.class)
public void fetchNonExistentLocalAppThrowsException() throws Exception {
  URL selfURL = new URL("BOGUS-" + appUrlBase + "/");
  FetchOptions fetchOptions = FetchOptions.Builder.withDefaults()
    .doNotFollowRedirects()
    .setDeadline(10.0);
  HTTPRequest httpRequest = new HTTPRequest(selfURL, HTTPMethod.GET, fetchOptions);
  URLFetchService urlFetchService = URLFetchServiceFactory.getURLFetchService();
  HTTPResponse httpResponse = urlFetchService.fetch(httpRequest);
  fail("expected exception, got " + httpResponse.getResponseCode());
}

相关文章