private String doReadResource()

in src/main/java/software/amazon/cloudwatchlogs/emf/environment/ResourceFetcher.java [66:94]


    private String doReadResource(URI endpoint, String method, List<Pair<String, String>> headers) {
        InputStream inputStream = null;
        try {
            HttpURLConnection connection = connectToEndpoint(endpoint, method, headers);

            int statusCode = connection.getResponseCode();

            if (statusCode == HttpURLConnection.HTTP_OK) {
                inputStream = connection.getInputStream();
                return IOUtils.toString(inputStream);
            } else if (statusCode == HttpURLConnection.HTTP_NOT_FOUND) {
                throw new EMFClientException(
                        "The requested metadata is not found at " + connection.getURL());
            } else {
                inputStream = connection.getErrorStream();
                handleErrorResponse(inputStream, connection.getResponseMessage());
            }
        } catch (IOException ioException) {
            log.debug(
                    "An IOException occurred when connecting to service endpoint: "
                            + endpoint
                            + "\n Retrying to connect "
                            + "again.");
            throw new EMFClientException("Failed to connect to service endpoint: ", ioException);
        } finally {
            IOUtils.closeQuietly(inputStream, log);
        }
        return "";
    }