All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.ocadotechnology.newrelic.apiclient.internal.ApiBase Maven / Gradle / Ivy

Go to download

NewRelic Alerts Configurator can be used to configure NewRelic alerts for your application. Instead of defining alerts through UI you can define them in code. It allows you to automatize alerts configuration, easily recover them in case of wipe out and have full history of changes in your version control system.

There is a newer version: 5.0.1
Show newest version
package com.ocadotechnology.newrelic.apiclient.internal;

import com.ocadotechnology.newrelic.apiclient.internal.client.NewRelicClient;
import com.ocadotechnology.newrelic.apiclient.internal.model.ObjectList;

import javax.ws.rs.client.Invocation.Builder;
import javax.ws.rs.core.Link;
import javax.ws.rs.core.Response;

import static javax.ws.rs.core.MediaType.APPLICATION_JSON_TYPE;

abstract class ApiBase {

    protected final NewRelicClient client;

    ApiBase(NewRelicClient client) {
        this.client = client;
    }

    > LT getPageable(Builder request, Class responseType) {
        Response response = request.get();
        LT responseBody = response.readEntity(responseType);
        Link next = response.getLink("next");
        return followPageable(next, responseBody, responseType);
    }

    private > LT followPageable(Link next, LT responseBody, Class responseType) {
        while (next != null) {
            Response nextResponse = client.target(next).request(APPLICATION_JSON_TYPE).get();
            LT nextResponseBody = nextResponse.readEntity(responseType);
            responseBody = responseBody.merge(nextResponseBody);
            next = nextResponse.getLink("next");
        }
        return responseBody;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy