Search in sources :

Example 1 with Gson

use of dontweave.gson.Gson in project h2o-2 by h2oai.

the class WebAPI method listJobs.

/**
   * Lists jobs currently running.
   */
static void listJobs() throws Exception {
    HttpClient client = new HttpClient();
    GetMethod get = new GetMethod(URL + "/Jobs.json");
    int status = client.executeMethod(get);
    if (status != 200)
        throw new Exception(get.getStatusText());
    Gson gson = new Gson();
    JobsRes res = gson.fromJson(new InputStreamReader(get.getResponseBodyAsStream()), JobsRes.class);
    System.out.println("Running jobs:");
    for (Job job : res.jobs) System.out.println(job.description + " " + job.destination_key);
    get.releaseConnection();
}
Also used : InputStreamReader(java.io.InputStreamReader) HttpClient(org.apache.commons.httpclient.HttpClient) GetMethod(org.apache.commons.httpclient.methods.GetMethod) Gson(dontweave.gson.Gson)

Example 2 with Gson

use of dontweave.gson.Gson in project h2o-2 by h2oai.

the class HttpTest method get.

public Get get(String uri, Class c) {
    GetMethod get = new GetMethod("http://127.0.0.1:54321/" + uri);
    Get res = new Get();
    try {
        res._status = _client.executeMethod(get);
        if (res._status == 200) {
            Gson gson = new Gson();
            res._res = gson.fromJson(new InputStreamReader(get.getResponseBodyAsStream()), c);
        }
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
    get.releaseConnection();
    return res;
}
Also used : InputStreamReader(java.io.InputStreamReader) GetMethod(org.apache.commons.httpclient.methods.GetMethod) Gson(dontweave.gson.Gson)

Aggregations

Gson (dontweave.gson.Gson)2 InputStreamReader (java.io.InputStreamReader)2 GetMethod (org.apache.commons.httpclient.methods.GetMethod)2 HttpClient (org.apache.commons.httpclient.HttpClient)1