use of org.apache.commons.httpclient.methods.GetMethod in project spatial-portal by AtlasOfLivingAustralia.
the class RemoteLogger method getLogItem.
public JSONObject getLogItem(String logId) {
init();
try {
if (Util.isLoggedIn()) {
String url = loggerService + "/app/view/" + logId + ".json" + "?appid=" + URLEncoder.encode(appid, StringConstants.UTF_8) + "&api_key=" + URLEncoder.encode(CommonData.getSettings().getProperty("api_key"), StringConstants.UTF_8);
HttpClient client = new HttpClient();
GetMethod get = new GetMethod(url);
get.addRequestHeader(StringConstants.ACCEPT, StringConstants.APPLICATION_JSON);
client.executeMethod(get);
LOGGER.debug("get: " + url + ", response: " + get.getResponseBodyAsString());
JSONParser jp = new JSONParser();
return (JSONObject) jp.parse(get.getResponseBodyAsString());
}
} catch (Exception e) {
LOGGER.error("Error getting logging information from server:", e);
}
return null;
}
use of org.apache.commons.httpclient.methods.GetMethod in project spatial-portal by AtlasOfLivingAustralia.
the class Sampling method getDownloadUrl.
static String getDownloadUrl(String statusUrl) {
String downloadUrl = null;
try {
HttpClient client = new HttpClient();
GetMethod get = new GetMethod(statusUrl);
get.addRequestHeader(StringConstants.CONTENT_TYPE, StringConstants.APPLICATION_JSON);
client.executeMethod(get);
JSONParser jp = new JSONParser();
JSONObject jo = (JSONObject) jp.parse(get.getResponseBodyAsString());
if ("finished".equals(jo.get(StringConstants.STATUS))) {
downloadUrl = jo.get("downloadUrl").toString();
} else if ("cancelled".equals(jo.get(StringConstants.STATUS)) || "error".equals(jo.get(StringConstants.STATUS))) {
downloadUrl = null;
} else {
downloadUrl = "";
}
} catch (Exception e) {
LOGGER.error("error getting response from : " + statusUrl, e);
}
return downloadUrl;
}
use of org.apache.commons.httpclient.methods.GetMethod in project spatial-portal by AtlasOfLivingAustralia.
the class Sampling method getDownloadData.
static List<String[]> getDownloadData(String downloadUrl, int numberOfPoints) {
List<String[]> output = new ArrayList<String[]>();
try {
HttpClient client = new HttpClient();
GetMethod get = new GetMethod(downloadUrl);
get.addRequestHeader(StringConstants.CONTENT_TYPE, "application/zip");
client.executeMethod(get);
try {
ZipInputStream zip = new ZipInputStream(get.getResponseBodyAsStream());
zip.getNextEntry();
CSVReader csv = new CSVReader(new InputStreamReader(zip));
//read first line
String[] line = csv.readNext();
//setup
for (int i = 2; i < line.length; i++) {
output.add(new String[numberOfPoints]);
}
int row = 0;
while ((line = csv.readNext()) != null && row < numberOfPoints) {
for (int i = 2; i - 2 < output.size() && i < line.length; i++) {
output.get(i - 2)[row] = line[i];
}
row = row + 1;
}
zip.close();
} catch (Exception e) {
LOGGER.error("failed to read zipped stream from: " + downloadUrl, e);
}
} catch (Exception e) {
LOGGER.error("error getting response from url: " + downloadUrl, e);
}
return output;
}
use of org.apache.commons.httpclient.methods.GetMethod in project spatial-portal by AtlasOfLivingAustralia.
the class SpeciesAutoComplete method getResults.
private JSONArray getResults(String nsurl) throws Exception {
HttpClient client = new HttpClient();
GetMethod get = new GetMethod(nsurl);
get.addRequestHeader(StringConstants.CONTENT_TYPE, StringConstants.TEXT_PLAIN);
client.executeMethod(get);
String rawJSON = get.getResponseBodyAsString();
//parse
JSONParser jp = new JSONParser();
JSONObject jo = (JSONObject) jp.parse(rawJSON);
//support search and auto bie webservices
if (jo.containsKey("searchResults")) {
return (JSONArray) ((JSONObject) jo.get("searchResults")).get("results");
} else {
return (JSONArray) jo.get("autoCompleteList");
}
}
use of org.apache.commons.httpclient.methods.GetMethod in project spatial-portal by AtlasOfLivingAustralia.
the class ProgressController method onClick$btnCancel.
public void onClick$btnCancel(Event e) {
try {
HttpClient client = new HttpClient();
GetMethod get = new GetMethod((CommonData.getSatServer() + "/ws/jobs/cancel?pid=") + pid);
get.addRequestHeader(StringConstants.ACCEPT, StringConstants.TEXT_PLAIN);
client.getHttpConnectionManager().getParams().setSoTimeout(timer.getDelay());
client.executeMethod(get);
} catch (Exception ex) {
LOGGER.error("error getting updated job info pid=" + pid, ex);
}
this.detach();
}
Aggregations