com.google.appengine.api.urlfetch.HTTPRequest.<init>()方法的使用及代码示例

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

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

HTTPRequest.<init>介绍

暂无

代码示例

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

@Override
public <T, R extends ApiResponse<T>> PendingResult<T> handle(
  String hostName,
  String url,
  String userAgent,
  Class<R> clazz,
  FieldNamingPolicy fieldNamingPolicy,
  long errorTimeout,
  Integer maxRetries,
  ExceptionsAllowedToRetry exceptionsAllowedToRetry) {
 FetchOptions fetchOptions = FetchOptions.Builder.withDeadline(10);
 HTTPRequest req;
 try {
  req = new HTTPRequest(new URL(hostName + url), HTTPMethod.POST, fetchOptions);
 } catch (MalformedURLException e) {
  LOG.error("Request: {}{}", hostName, url, e);
  throw (new RuntimeException(e));
 }
 return new GaePendingResult<>(
   req, client, clazz, fieldNamingPolicy, errorTimeout, maxRetries, exceptionsAllowedToRetry);
}

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

@Override
public <T, R extends ApiResponse<T>> PendingResult<T> handlePost(
  String hostName,
  String url,
  String payload,
  String userAgent,
  Class<R> clazz,
  FieldNamingPolicy fieldNamingPolicy,
  long errorTimeout,
  Integer maxRetries,
  ExceptionsAllowedToRetry exceptionsAllowedToRetry) {
 FetchOptions fetchOptions = FetchOptions.Builder.withDeadline(10);
 HTTPRequest req = null;
 try {
  req = new HTTPRequest(new URL(hostName + url), HTTPMethod.POST, fetchOptions);
  req.setHeader(new HTTPHeader("Content-Type", "application/json; charset=utf-8"));
  req.setPayload(payload.getBytes(UTF_8));
 } catch (MalformedURLException e) {
  LOG.error("Request: {}{}", hostName, url, e);
  throw (new RuntimeException(e));
 }
 return new GaePendingResult<>(
   req, client, clazz, fieldNamingPolicy, errorTimeout, maxRetries, exceptionsAllowedToRetry);
}

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

String lResponse = new HTTPRequest().execute( pURL ).get();

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

UrlFetchRequest(HTTPMethod method, String url) throws IOException {
 request = new HTTPRequest(new URL(url), method, OPTIONS);
}

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

UrlFetchRequest(FetchOptions fetchOptions, HTTPMethod method, String url) throws IOException {
 request = new HTTPRequest(new URL(url), method, fetchOptions);
}

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

URL fetchurl = new URL(url);

String nameAndPassword = credentials.get("name")+":"+credentials.get("password");
String authorizationString = "Basic " + Base64.encode(nameAndPassword.getBytes());

HTTPRequest request = new HTTPRequest(fetchurl);
request.addHeader(new HTTPHeader("Authorization", authorizationString));

HTTPResponse response = URLFetchServiceFactory.getURLFetchService().fetch(request);
System.out.println(new String(response.getContent()));

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

@Override
public <T, R extends ApiResponse<T>> PendingResult<T> handle(
  String hostName,
  String url,
  String userAgent,
  Class<R> clazz,
  FieldNamingPolicy fieldNamingPolicy,
  long errorTimeout,
  Integer maxRetries,
  ExceptionsAllowedToRetry exceptionsAllowedToRetry) {
 FetchOptions fetchOptions = FetchOptions.Builder.withDeadline(10);
 HTTPRequest req;
 try {
  req = new HTTPRequest(new URL(hostName + url), HTTPMethod.POST, fetchOptions);
 } catch (MalformedURLException e) {
  LOG.error("Request: {}{}", hostName, url, e);
  throw (new RuntimeException(e));
 }
 return new GaePendingResult<>(
   req, client, clazz, fieldNamingPolicy, errorTimeout, maxRetries, exceptionsAllowedToRetry);
}

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

private HTTPRequest newRequest(String url, HTTPMethod method, Iterable<Header> headers) throws IOException {
  HTTPRequest request = new HTTPRequest(new URL(url), method, options);
  for (Header header : headers) {
    request.addHeader(new HTTPHeader(header.getKey(), header.getValue()));
  }
  return request;
}

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

@Override
public <T, R extends ApiResponse<T>> PendingResult<T> handlePost(
  String hostName,
  String url,
  String payload,
  String userAgent,
  Class<R> clazz,
  FieldNamingPolicy fieldNamingPolicy,
  long errorTimeout,
  Integer maxRetries,
  ExceptionsAllowedToRetry exceptionsAllowedToRetry) {
 FetchOptions fetchOptions = FetchOptions.Builder.withDeadline(10);
 HTTPRequest req = null;
 try {
  req = new HTTPRequest(new URL(hostName + url), HTTPMethod.POST, fetchOptions);
  req.setHeader(new HTTPHeader("Content-Type", "application/json; charset=utf-8"));
  req.setPayload(payload.getBytes(UTF_8));
 } catch (MalformedURLException e) {
  LOG.error("Request: {}{}", hostName, url, e);
  throw (new RuntimeException(e));
 }
 return new GaePendingResult<>(
   req, client, clazz, fieldNamingPolicy, errorTimeout, maxRetries, exceptionsAllowedToRetry);
}

代码示例来源:origin: org.apache.camel/camel-gae

/**
 * Reads data from <code>exchange</code> and writes it to a newly created
 * {@link HTTPRequest} instance. The <code>request</code> parameter is
 * ignored.
 *
 * @return a newly created {@link HTTPRequest} instance containing data from
 *         <code>exchange</code>.
 */
public HTTPRequest writeRequest(GHttpEndpoint endpoint, Exchange exchange, HTTPRequest request) throws Exception {
  HTTPRequest answer = new HTTPRequest(
      getRequestUrl(endpoint, exchange), 
      getRequestMethod(endpoint, exchange));
  writeRequestHeaders(endpoint, exchange, answer);
  writeRequestBody(endpoint, exchange, answer);
  return answer;
}

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

@Test
public void testFollowRedirectsExternal() throws Exception {
  final URL redirectUrl = new URL("http://google.com/");
  final String expectedDestinationURLPrefix = "http://www.google.";
  FetchOptions options = FetchOptions.Builder.followRedirects();
  HTTPRequest request = new HTTPRequest(redirectUrl, HTTPMethod.GET, options);
  URLFetchService service = URLFetchServiceFactory.getURLFetchService();
  HTTPResponse response = service.fetch(request);
  String destinationUrl = response.getFinalUrl().toString();
  assertTrue("Did not get redirected.", destinationUrl.startsWith(expectedDestinationURLPrefix));
}

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

protected void testOptions(URL url, HTTPMethod method, FetchOptions options, ResponseHandler handler) throws Exception {
  HTTPRequest request = new HTTPRequest(url, method, options);
  URLFetchService service = URLFetchServiceFactory.getURLFetchService();
  HTTPResponse response = service.fetch(request);
  handler.handle(response);
}

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

static HTTPRequest copyRequest(HTTPRequest in) {
  HTTPRequest out = new HTTPRequest(in.getURL(), in.getMethod(), in.getFetchOptions());
  for (HTTPHeader h : in.getHeaders()) {
   out.addHeader(h);
  }
  out.setPayload(in.getPayload());
  return out;
 }
}

代码示例来源:origin: com.squareup.retrofit/retrofit

static HTTPRequest createRequest(Request request) throws IOException {
 HTTPMethod httpMethod = getHttpMethod(request.getMethod());
 URL url = new URL(request.getUrl());
 HTTPRequest fetchRequest = new HTTPRequest(url, httpMethod);
 for (Header header : request.getHeaders()) {
  fetchRequest.addHeader(new HTTPHeader(header.getName(), header.getValue()));
 }
 TypedOutput body = request.getBody();
 if (body != null) {
  String mimeType = body.mimeType();
  if (mimeType != null) {
   fetchRequest.addHeader(new HTTPHeader("Content-Type", mimeType));
  }
  ByteArrayOutputStream baos = new ByteArrayOutputStream();
  body.writeTo(baos);
  fetchRequest.setPayload(baos.toByteArray());
 }
 return fetchRequest;
}

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

protected HttpResponseImpl postOrPut(HttpRequestImpl request, HTTPMethod postOrPut) {
  FetchOptions fetchOptions = createFetchOptions(request);
  URL requestUrl = buildPostRequestUrl(request);
  HTTPRequest fetchRequest = new HTTPRequest(requestUrl, postOrPut, fetchOptions);
  setContentTypeIfNotPresent(request, fetchRequest, ContentType.ApplicationFormUrlEncoded);
  addAuthorization(request, fetchRequest);
  addHeaders(request, fetchRequest);
  addCookies(request, fetchRequest);
  addBody(request, fetchRequest, true);
  return fetch(fetchRequest, postOrPut);
}

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

protected HttpResponseImpl headGetDelete(HttpRequestImpl request, HTTPMethod headGetDelete) {
  FetchOptions fetchOptions = createFetchOptions(request);
  URL requestUrl = buildGetRequestUrl(request);
  HTTPRequest fetchRequest = new HTTPRequest(requestUrl, headGetDelete, fetchOptions);
  setContentTypeIfNotPresent(request, fetchRequest, ContentType.TextPlain);
  addAuthorization(request, fetchRequest);
  addHeaders(request, fetchRequest);
  addCookies(request, fetchRequest);
  addBody(request, fetchRequest, false);
  return fetch(fetchRequest, headGetDelete);
}

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

@Test
public void testAsyncOps() throws Exception {
  URLFetchService service = URLFetchServiceFactory.getURLFetchService();
  URL adminConsole = findAvailableUrl(URLS);
  Future<HTTPResponse> response = service.fetchAsync(adminConsole);
  printResponse(response.get(5, TimeUnit.SECONDS));
  response = service.fetchAsync(new HTTPRequest(adminConsole));
  printResponse(response.get(5, TimeUnit.SECONDS));
  URL jbossOrg = new URL("http://www.jboss.org");
  if (available(jbossOrg)) {
    response = service.fetchAsync(jbossOrg);
    printResponse(response.get(30, TimeUnit.SECONDS));
  }
  sync(5000L); // wait a bit for async to finish
}

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

@Test
public void testPayload() throws Exception {
  URLFetchService service = URLFetchServiceFactory.getURLFetchService();
  URL url = getFetchUrl();
  HTTPRequest req = new HTTPRequest(url, HTTPMethod.POST);
  req.setHeader(new HTTPHeader("Content-Type", "application/octet-stream"));
  req.setPayload("Tralala".getBytes(UTF_8));
  HTTPResponse response = service.fetch(req);
  String content = new String(response.getContent());
  Assert.assertEquals("Hopsasa", content);
}

代码示例来源: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());
}

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

@Test
public void testGetters() throws Exception {
  HTTPRequest request = new HTTPRequest(getFetchUrl(), HTTPMethod.PATCH, FetchOptions.Builder.withDefaults());
  request.addHeader(new HTTPHeader("foo", "bar"));
  request.setPayload("qwerty".getBytes());
  Assert.assertEquals(getFetchUrl(), request.getURL());
  Assert.assertEquals(HTTPMethod.PATCH, request.getMethod());
  Assert.assertNotNull(request.getFetchOptions());
  Assert.assertNotNull(request.getHeaders());
  Assert.assertEquals(1, request.getHeaders().size());
  assertEquals(new HTTPHeader("foo", "bar"), request.getHeaders().get(0));
  Assert.assertArrayEquals("qwerty".getBytes(), request.getPayload());
}

相关文章