use of org.apache.commons.httpclient.HttpClient in project spatial-portal by AtlasOfLivingAustralia.
the class ProgressController method get.
JSONObject get() {
try {
StringBuilder sbProcessUrl = new StringBuilder();
sbProcessUrl.append(CommonData.getSatServer()).append("/ws/job?pid=").append(pid);
LOGGER.debug("checking status every '" + timer.getDelay() + "' sec: " + sbProcessUrl.toString());
HttpClient client = new HttpClient();
GetMethod get = new GetMethod(sbProcessUrl.toString());
get.addRequestHeader(StringConstants.ACCEPT, StringConstants.APPLICATION_JSON);
client.getHttpConnectionManager().getParams().setSoTimeout(timer.getDelay());
int result = client.executeMethod(get);
if (result == 200) {
JSONParser jp = new JSONParser();
return (JSONObject) jp.parse(get.getResponseBodyAsString());
}
} catch (SocketTimeoutException e) {
LOGGER.debug("progress timeout exception, will be trying again.");
} catch (Exception e) {
LOGGER.error("error getting updated job info pid=" + pid, e);
}
return null;
}
use of org.apache.commons.httpclient.HttpClient in project spatial-portal by AtlasOfLivingAustralia.
the class AreaReportController method getGazPoints.
public static JSONArray getGazPoints(String wkt) {
try {
int limit = Integer.MAX_VALUE;
String url = CommonData.getLayersServer() + "/objects/inarea/" + CommonData.getSettings().get("area_report_gaz_field") + "?limit=" + limit;
HttpClient client = new HttpClient();
PostMethod post = new PostMethod(url);
LOGGER.debug(url);
if (wkt != null) {
post.addParameter(StringConstants.WKT, wkt);
}
post.addRequestHeader(StringConstants.ACCEPT, StringConstants.JSON_JAVASCRIPT_ALL);
int result = client.executeMethod(post);
if (result == 200) {
String txt = post.getResponseBodyAsString();
JSONParser jp = new JSONParser();
return (JSONArray) jp.parse(txt);
} else {
LOGGER.debug(result + ", " + post.getResponseBodyAsString());
}
} catch (Exception e) {
LOGGER.error("error getting number of gaz points in an area: " + wkt, e);
}
return null;
}
use of org.apache.commons.httpclient.HttpClient in project spatial-portal by AtlasOfLivingAustralia.
the class MapComposer method loadDistributionMap.
private void loadDistributionMap(String lsids, String wkt) {
String newWkt = wkt;
if (CommonData.WORLD_WKT.equals(newWkt)) {
newWkt = null;
}
//test for a valid lsid match
String[] wmsNames = CommonData.getSpeciesDistributionWMS(lsids);
String[] spcode = CommonData.getSpeciesDistributionSpcode(lsids);
MapLayer ml;
JSONParser jp = new JSONParser();
if (wmsNames.length > 0 && (newWkt == null || newWkt.equals(CommonData.WORLD_WKT))) {
//add all
for (int i = 0; i < wmsNames.length; i++) {
if (getMapLayerWMS(wmsNames[i]) == null) {
//map this layer with its recorded scientific name
try {
JSONObject jo = ((JSONObject) jp.parse(Util.readUrl(CommonData.getLayersServer() + "/distribution/" + spcode[i] + "?nowkt=true")));
String scientific = jo.get(StringConstants.SCIENTIFIC).toString();
String distributionAreaName = jo.get("area_name").toString();
String layerName = getNextAreaLayerName(scientific);
String html = Util.getMetadataHtmlForDistributionOrChecklist(spcode[i], null, layerName);
ml = addWMSLayer(layerName, getNextAreaLayerName(distributionAreaName), wmsNames[i], 0.35f, html, null, LayerUtilitiesImpl.WKT, null, null);
ml.setSPCode(spcode[i]);
setupMapLayerAsDistributionArea(ml);
} catch (Exception e) {
LOGGER.error("failed to parse for distribution: " + spcode[i]);
}
}
}
} else if (wmsNames.length > 0 && newWkt != null && !newWkt.equals(CommonData.WORLD_WKT)) {
String url = CommonData.getLayersServer() + "/distributions";
try {
HttpClient client = new HttpClient();
PostMethod post = new PostMethod(url);
post.addParameter(StringConstants.WKT, newWkt);
post.addParameter(StringConstants.LSIDS, lsids);
post.addRequestHeader(StringConstants.ACCEPT, StringConstants.JSON_JAVASCRIPT_ALL);
int result = client.executeMethod(post);
if (result == 200) {
String txt = post.getResponseBodyAsString();
JSONArray ja = (JSONArray) jp.parse(txt);
List<String> found = new ArrayList();
for (int i = 0; i < ja.size(); i++) {
JSONObject jo = (JSONObject) ja.get(i);
if (jo.containsKey(StringConstants.WMSURL)) {
found.add(jo.get(StringConstants.WMSURL).toString());
}
}
for (int i = 0; i < wmsNames.length; i++) {
if (getMapLayerWMS(wmsNames[i]) == null) {
String scientific = ((JSONObject) jp.parse(Util.readUrl(CommonData.getLayersServer() + "/distribution/" + spcode[i] + "?nowkt=true"))).get(StringConstants.SCIENTIFIC).toString();
String layerName = getNextAreaLayerName(scientific + " area " + (i + 1));
String html = Util.getMetadataHtmlForDistributionOrChecklist(spcode[i], null, layerName);
ml = addWMSLayer(layerName, getNextAreaLayerName("Expert distribution: " + scientific), found.get(i), 0.35f, html, null, LayerUtilitiesImpl.WKT, null, null);
ml.setSPCode(spcode[i]);
setupMapLayerAsDistributionArea(ml);
}
}
}
} catch (Exception e) {
LOGGER.error("error posting distributions: " + url);
}
}
openChecklistSpecies(lsids, newWkt, true);
}
use of org.apache.commons.httpclient.HttpClient in project spatial-portal by AtlasOfLivingAustralia.
the class SpeciesListUtil method getLists.
private static JSONObject getLists(String user, Integer offset, Integer max, String sort, String order, String searchTerm) {
StringBuilder sb = new StringBuilder(CommonData.getSpeciesListServer());
sb.append("/ws/speciesList");
sb.append("?user=");
if (user != null && !"guest@ala.org.au".equals(user)) {
sb.append(user);
}
if (offset != null) {
sb.append("&offset=").append(offset.toString());
}
if (max != null) {
sb.append("&max=").append(max);
}
if (sort != null) {
sb.append("&sort=").append(sort);
}
if (order != null) {
sb.append("&order=").append(order);
}
if (searchTerm != null) {
//sb.append("&listName=ilike:%25" + searchTerm + "%25");
try {
sb.append("&q=" + URLEncoder.encode(searchTerm, "UTF-8"));
} catch (Exception e) {
}
}
HttpClient client = new HttpClient();
GetMethod get = new GetMethod(sb.toString());
try {
//permission to get private lists
if (user != null) {
get.addRequestHeader(StringConstants.COOKIE, "ALA-Auth=" + java.net.URLEncoder.encode(user, StringConstants.UTF_8));
}
get.addRequestHeader(StringConstants.CONTENT_TYPE, StringConstants.TEXT_PLAIN);
int result = client.executeMethod(get);
if (result == 200) {
String rawJSON = get.getResponseBodyAsString();
JSONParser jp = new JSONParser();
return (JSONObject) jp.parse(rawJSON);
} else {
LOGGER.error("Unable to retrieve species list. " + result + " > " + get.getResponseBodyAsString());
}
} catch (Exception e) {
LOGGER.error("Error retrieving public species list.", e);
} finally {
get.releaseConnection();
}
return null;
}
use of org.apache.commons.httpclient.HttpClient in project spatial-portal by AtlasOfLivingAustralia.
the class LsidCountsDynamic method count.
private static int count(String lsid) {
HttpClient client = new HttpClient();
String url = null;
try {
url = CommonData.getBiocacheServer() + "/occurrences/search?facet=off&pageSize=0&fq=" + URLEncoder.encode("geospatial_kosher:*", StringConstants.UTF_8) + "&q=" + URLEncoder.encode("lsid:" + lsid, StringConstants.UTF_8) + CommonData.getBiocacheQc();
LOGGER.debug(url);
GetMethod get = new GetMethod(url);
client.getHttpConnectionManager().getParams().setSoTimeout(30000);
client.executeMethod(get);
JSONParser jp = new JSONParser();
JSONObject jo = (JSONObject) jp.parse(get.getResponseBodyAsString());
return ((Long) jo.get("totalRecords")).intValue();
} catch (Exception e) {
LOGGER.error("error getting LSID count for : " + url, e);
}
return -1;
}
Aggregations