public static String get()

in util/src/main/java/com/google/cloud/healthcare/imaging/dicomadapter/GcpMetadataUtil.java [40:63]


  public static String get(HttpRequestFactory requestFactory, String path) {
    try {
      HttpRequest httpRequest =
          requestFactory.buildGetRequest(new GenericUrl(baseUrl + path));
      httpRequest.getHeaders().put("Metadata-Flavor", "Google");
      HttpResponse httpResponse = httpRequest.execute();

      if (!httpResponse.isSuccessStatusCode()
          || httpResponse.getStatusCode() == HttpStatusCodes.STATUS_CODE_NO_CONTENT) {
        log.warn("Failed to get metadata for {} with response {}:{}",
            path, httpResponse.getStatusCode(), httpResponse.getStatusMessage());
        return null;
      }

      return CharStreams.toString(new InputStreamReader(
          httpResponse.getContent(), StandardCharsets.UTF_8));
    } catch (UnknownHostException e) {
      log.trace("Not GCP environment, failed to get metadata for {} with exception {}", path, e);
      return null;
    } catch (IOException | IllegalArgumentException e) {
      log.warn("Failed to get metadata for {} with exception {}", path, e);
      return null;
    }
  }