Java Code Examples for org.apache.commons.httpclient.methods.GetMethod#getStatusText()

The following examples show how to use org.apache.commons.httpclient.methods.GetMethod#getStatusText() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: WebAPI.java    From h2o-2 with Apache License 2.0 6 votes vote down vote up
/**
 * Exports a model to a JSON file.
 */
static void exportModel() throws Exception {
  HttpClient client = new HttpClient();
  GetMethod get = new GetMethod(URL + "/2/ExportModel.json?model=MyInitialNeuralNet");
  int status = client.executeMethod(get);
  if( status != 200 )
    throw new Exception(get.getStatusText());
  JsonObject response = (JsonObject) new JsonParser().parse(new InputStreamReader(get.getResponseBodyAsStream()));
  JsonElement model = response.get("model");
  JsonWriter writer = new JsonWriter(new FileWriter(JSON_FILE));
  writer.setLenient(true);
  writer.setIndent("  ");
  Streams.write(model, writer);
  writer.close();
  get.releaseConnection();
}
 
Example 2
Source File: WebAPI.java    From h2o-2 with Apache License 2.0 5 votes vote down vote up
/**
 * 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();
}