com.google.api.client.http.HttpRequest.getUrl()方法的使用及代码示例

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

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

HttpRequest.getUrl介绍

暂无

代码示例

代码示例来源:origin: GoogleContainerTools/jib

/** @return the original request URL */
 public GenericUrl getRequestUrl() {
  return httpResponse.getRequest().getUrl();
 }
}

代码示例来源: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: googleapis/google-cloud-java

try {
 Insert req = storage.objects().insert(object.getBucket(), object);
 GenericUrl url = req.buildHttpRequest().getUrl();
 String scheme = url.getScheme();
 String host = url.getHost();

代码示例来源:origin: GoogleCloudPlatform/java-docs-samples

public boolean handleResponse(
   final HttpRequest request, final HttpResponse response, final boolean supportsRetry)
   throws IOException {
  if (wrappedCredential.handleResponse(request, response, supportsRetry)) {
   // If credential decides it can handle it, the return code or message indicated
   // something specific to authentication, and no backoff is desired.
   return true;
  } else if (backoffHandler.handleResponse(request, response, supportsRetry)) {
   // Otherwise, we defer to the judgement of our internal backoff handler.
   LOG.info("Retrying " + request.getUrl().toString());
   return true;
  } else {
   return false;
  }
 }
});

代码示例来源:origin: GoogleCloudPlatform/java-docs-samples

.buildRequest(request.getRequestMethod(), request.getUrl(), request.getContent())
.setHeaders(httpHeaders);

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

try {
  HttpRequestFactory httpRequestFactory = createRequestFactory(HTTP_TRANSPORT);
  HttpRequest request = httpRequestFactory
      .buildGetRequest(new GenericUrl(PLACES_SEARCH_URL));
  request.getUrl().put("key", API_KEY);
  request.getUrl().put("location", _latitude + "," + _longitude);
  request.getUrl().put("radius", _radius); // in meters
  request.getUrl().put("sensor", "false");

  if(types != null)
    request.getUrl().put("types", types);

  PlacesList list = request.execute().parseAs(PlacesList.class);
  // Check log cat for places response status
  Log.d("Places Status", "" + list.status);
  return list;

} catch (HttpResponseException e) {
  Log.e("Error:", e.getMessage());
  return null;
}

代码示例来源:origin: gradle.plugin.com.google.cloud.tools/jib-gradle-plugin

/** @return the original request URL */
 public GenericUrl getRequestUrl() {
  return httpResponse.getRequest().getUrl();
 }
}

代码示例来源:origin: com.google.cloud.tools/jib-maven-plugin

/** @return the original request URL */
 public GenericUrl getRequestUrl() {
  return httpResponse.getRequest().getUrl();
 }
}

代码示例来源:origin: com.google.enterprise.cloudsearch/google-cloudsearch-connector-sdk

@Override
 public boolean handleIOException(HttpRequest request, boolean supportsRetry)
   throws IOException {
  String event =
    logger.isLoggable(INFO)
      ? String.format("IOException for %s", request.getUrl().buildRelativeUrl())
      : null;
  if (supportsRetry) {
   logger.log(FINE, "Handling {0}", event);
   boolean retry = delegate.handleIOException(request, supportsRetry);
   logger.log(retry ? INFO : WARNING, retry ? "Retrying {0}" : "Not retrying {0}", event);
   return retry;
  } else {
   logger.log(WARNING, "Unable to retry {0}", event);
   return false;
  }
 }
}

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

private boolean overrideThisMethod(HttpRequest request) throws IOException {
 String requestMethod = request.getRequestMethod();
 if (requestMethod.equals(HttpMethods.POST)) {
  return false;
 }
 if (requestMethod.equals(HttpMethods.GET)
   ? request.getUrl().build().length() > MAX_URL_LENGTH : overrideAllMethods) {
  return true;
 }
 return !request.getTransport().supportsMethod(requestMethod);
}

代码示例来源:origin: com.google.cloud.bigdataoss/util

@Override
 public boolean handleIOException(HttpRequest httpRequest, boolean supportsRetry)
   throws IOException {
  // We sadly don't get anything helpful to see if this is something we want to log. As a result
  // we'll turn down the logging level to debug.
  logger.atFine().log("Encountered an IOException when accessing URL %s", httpRequest.getUrl());
  return delegateIOExceptionHandler.handleIOException(httpRequest, supportsRetry);
 }
}

代码示例来源:origin: GoogleCloudPlatform/bigdata-interop

@Override
 public boolean handleIOException(HttpRequest httpRequest, boolean supportsRetry)
   throws IOException {
  // We sadly don't get anything helpful to see if this is something we want to log. As a result
  // we'll turn down the logging level to debug.
  logger.atFine().log("Encountered an IOException when accessing URL %s", httpRequest.getUrl());
  return delegateIOExceptionHandler.handleIOException(httpRequest, supportsRetry);
 }
}

代码示例来源:origin: GoogleCloudPlatform/bigdata-interop

@Override
public boolean handleResponse(
  HttpRequest httpRequest, HttpResponse httpResponse, boolean supportsRetry)
  throws IOException {
 if (responseCodesToLog.contains(httpResponse.getStatusCode())) {
  logger.atInfo().log(
    "Encountered status code %s when accessing URL %s. "
      + "Delegating to response handler for possible retry.",
    httpResponse.getStatusCode(), httpRequest.getUrl());
 }
 return delegateResponseHandler.handleResponse(httpRequest, httpResponse, supportsRetry);
}

代码示例来源:origin: com.google.cloud.bigdataoss/util

@Override
public boolean handleResponse(
  HttpRequest httpRequest, HttpResponse httpResponse, boolean supportsRetry)
  throws IOException {
 if (responseCodesToLog.contains(httpResponse.getStatusCode())) {
  logger.atInfo().log(
    "Encountered status code %s when accessing URL %s. "
      + "Delegating to response handler for possible retry.",
    httpResponse.getStatusCode(), httpRequest.getUrl());
 }
 return delegateResponseHandler.handleResponse(httpRequest, httpResponse, supportsRetry);
}

代码示例来源:origin: XeroAPI/Xero-Java

public void intercept(HttpRequest request) throws IOException 
{
  computeNonce();
  computeTimestamp();
  try {
    computeSignature(request.getRequestMethod(), request.getUrl());
  } catch (GeneralSecurityException e) {
    logger.error(e);
    IOException io = new IOException();
    io.initCause(e);
    throw io;
  }
  request.getHeaders().setAuthorization(getAuthorizationHeader());
}

代码示例来源:origin: codice/ddf

@Override
public void onSuccess(HttpResponse httpResponse) {
 if (httpResponse != null
   && httpResponse.getStatusCode() == HttpStatusCodes.STATUS_CODE_OK) {
  try {
   String parsedResponse = httpResponse.parseAsString();
   buildEntityDescriptor(parsedResponse);
   service.shutdown();
  } catch (IOException e) {
   LOGGER.info(
     "Unable to parse metadata from: {}",
     httpResponse.getRequest().getUrl().toString(),
     e);
  }
 } else {
  LOGGER.warn("No/bad response; re-submitting request");
 }
}

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

HTTPRequestInfo(HttpRequest req) {
 method = req.getRequestMethod();
 url = req.getUrl().toURL();
 long myLength;
 HttpContent content = req.getContent();
 try {
  myLength = content == null ? -1 : content.getLength();
 } catch (IOException e) {
  myLength = -1;
 }
 length = myLength;
 h1 = req.getHeaders();
 h2 = null;
}

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

public void intercept(HttpRequest request) throws IOException {
 if (overrideThisMethod(request)) {
  String requestMethod = request.getRequestMethod();
  request.setRequestMethod(HttpMethods.POST);
  request.getHeaders().set(HEADER, requestMethod);
  if (requestMethod.equals(HttpMethods.GET)) {
   // take the URI query part and put it into the HTTP body
   request.setContent(new UrlEncodedContent(request.getUrl().clone()));
   // remove query parameters from URI
   request.getUrl().clear();
  } else if (request.getContent() == null) {
   // Google servers will fail to process a POST unless the Content-Length header is specified
   request.setContent(new EmptyContent());
  }
 }
}

代码示例来源:origin: googleapis/gax-java

@Test
public void testRequestUrl() throws IOException {
 HttpRequest httpRequest = httpRequestRunnable.createHttpRequest();
 String expectedUrl = ENDPOINT + "name/feline" + "?food=bird&food=mouse&size=small";
 Truth.assertThat(httpRequest.getUrl().toString()).isEqualTo(expectedUrl);
}

代码示例来源:origin: googleads/googleads-java-lib

@VisibleForTesting
RequestInfo buildRequestInfo(HttpRequest request) {
 RequestInfo.Builder requestBuilder = new RequestInfo.Builder();
 if (request != null) {
  requestBuilder.withServiceName("reportdownload").withMethodName(request.getRequestMethod());
  try {
   requestBuilder.withUrl(request.getUrl().toURL().toString());
  } catch (IllegalArgumentException e) {
   requestBuilder.withUrl("Malformed URL: " + request.getUrl());
  }
  if (request.getHeaders() != null) {
   String clientCustomerId =
     request.getHeaders().getFirstHeaderStringValue(CLIENT_CUSTOMER_ID);
   requestBuilder.withContext(CLIENT_CUSTOMER_ID, clientCustomerId);
  }
  // Get the payload from the request.
  requestBuilder.withPayload(extractPayload(request.getHeaders(), request.getContent()));
 }
 return requestBuilder.build();
}

相关文章