Search in sources :

Example 76 with HttpClient

use of org.apache.commons.httpclient.HttpClient in project spatial-portal by AtlasOfLivingAustralia.

the class GDMComposer method rungdm.

public boolean rungdm() {
    try {
        StringBuilder sbProcessUrl = new StringBuilder();
        sbProcessUrl.append(CommonData.getSatServer()).append("/ws/gdm/step2?");
        sbProcessUrl.append("&pid=").append(pid);
        sbProcessUrl.append("&cutpoint=").append(cutpoint.getSelectedItem().getValue());
        sbProcessUrl.append("&useDistance=").append(rgdistance.getSelectedItem().getValue());
        sbProcessUrl.append("&weighting=").append(weighting.getSelectedItem().getValue());
        sbProcessUrl.append("&useSubSample=").append(useSubSample.isChecked() ? "1" : "0");
        sbProcessUrl.append("&sitePairsSize=").append(sitePairsSize.getValue());
        sbProcessUrl.append("&name=").append(query.getName());
        HttpClient client = new HttpClient();
        PostMethod get = new PostMethod(sbProcessUrl.toString());
        get.addRequestHeader(StringConstants.ACCEPT, StringConstants.TEXT_PLAIN);
        LOGGER.debug("calling gdm ws: " + sbProcessUrl.toString());
        client.executeMethod(get);
        step2Id = get.getResponseBodyAsString();
        getFellow("runningMsg2").setVisible(true);
        statusMsg = ((Label) getFellow("runningMsg2")).getValue();
        startTime = System.currentTimeMillis();
        Events.echoEvent("step2Status", this, null);
        return false;
    } catch (Exception e) {
        LOGGER.error("error finalizing GDM", e);
    }
    return false;
}
Also used : PostMethod(org.apache.commons.httpclient.methods.PostMethod) HttpClient(org.apache.commons.httpclient.HttpClient)

Example 77 with HttpClient

use of org.apache.commons.httpclient.HttpClient in project spatial-portal by AtlasOfLivingAustralia.

the class GDMComposer method runGDMStep1.

public boolean runGDMStep1() {
    try {
        SelectedArea sa = getSelectedArea();
        query = QueryUtil.queryFromSelectedArea(getSelectedSpecies(), sa, false, getGeospatialKosher());
        query = query.newFacet(new Facet("occurrence_status_s", "absent", false), false);
        sbenvsel = getSelectedLayersWithDisplayNames();
        if (query.getSpeciesCount() < 2) {
            getMapComposer().showMessage("An list of species with multiple occurrences for each species is required by GDM.", this);
            return false;
        }
        HttpClient client = new HttpClient();
        PostMethod get = new PostMethod(CommonData.getSatServer() + "/ws/gdm/step1?" + "envlist=" + URLEncoder.encode(sbenvsel, StringConstants.UTF_8) + "&taxacount=" + query.getSpeciesCount() + "&speciesq=" + URLEncoder.encode(QueryUtil.queryFromSelectedArea(query, sa, false, getGeospatialKosher()).getQ(), StringConstants.UTF_8) + "&bs=" + URLEncoder.encode(query.getBS(), StringConstants.UTF_8));
        if (sa.getMapLayer() != null && sa.getMapLayer().getEnvelope() != null) {
            area = StringConstants.ENVELOPE + "(" + sa.getMapLayer().getEnvelope() + ")";
        } else {
            area = sa.getWkt();
        }
        if (getSelectedArea() != null) {
            get.addParameter(StringConstants.AREA, area);
        }
        get.addRequestHeader(StringConstants.ACCEPT, StringConstants.TEXT_PLAIN);
        LOGGER.debug("calling gdm ws step 1");
        client.executeMethod(get);
        step1Id = get.getResponseBodyAsString();
        //wait for step 1
        LOGGER.debug(step1Id);
        getFellow("runningMsg1").setVisible(true);
        statusMsg = ((Label) getFellow("runningMsg1")).getValue();
        startTime = System.currentTimeMillis();
        Events.echoEvent("step1Status", this, null);
        btnOk.setDisabled(true);
        return true;
    } catch (Exception e) {
        LOGGER.error("GDM error: ", e);
        getMapComposer().showMessage("Unknown error.", this);
    }
    return false;
}
Also used : PostMethod(org.apache.commons.httpclient.methods.PostMethod) SelectedArea(au.org.emii.portal.menu.SelectedArea) HttpClient(org.apache.commons.httpclient.HttpClient) Facet(au.org.ala.legend.Facet)

Example 78 with HttpClient

use of org.apache.commons.httpclient.HttpClient in project spatial-portal by AtlasOfLivingAustralia.

the class ALOCComposer method getJob.

String getJob() {
    try {
        StringBuilder sbProcessUrl = new StringBuilder();
        sbProcessUrl.append(CommonData.getSatServer()).append("/ws/jobs/").append("inputs").append("?pid=").append(pid);
        LOGGER.debug(sbProcessUrl.toString());
        HttpClient client = new HttpClient();
        GetMethod get = new GetMethod(sbProcessUrl.toString());
        get.addRequestHeader(StringConstants.ACCEPT, StringConstants.TEXT_PLAIN);
        client.executeMethod(get);
        String slist = get.getResponseBodyAsString();
        LOGGER.debug(slist);
        return slist;
    } catch (Exception e) {
        LOGGER.error("error getting gob info pid=" + pid, e);
    }
    return "";
}
Also used : HttpClient(org.apache.commons.httpclient.HttpClient) GetMethod(org.apache.commons.httpclient.methods.GetMethod)

Example 79 with HttpClient

use of org.apache.commons.httpclient.HttpClient in project spatial-portal by AtlasOfLivingAustralia.

the class ALOCComposer method getEstimate.

@Override
public long getEstimate() {
    try {
        String sbenvsel = getSelectedLayers();
        if (sbenvsel.split(":").length > 50) {
            getMapComposer().showMessage(sbenvsel.split(":").length + " layers selected.  Please select fewer than 50 environmental layers in step 1.");
            return -1;
        }
        if (groupCount.getValue() <= 1 || groupCount.getValue() > 200) {
            getMapComposer().showMessage("Please enter the number of groups to generate (2 to 200) in step 2.");
            //highlight step 2
            return -1;
        }
        SelectedArea sa = getSelectedArea();
        //estimate analysis size in bytes
        double[][] bbox = null;
        List<Double> bb;
        if (sa.getMapLayer() != null) {
            bb = sa.getMapLayer().getMapLayerMetadata().getBbox();
        } else {
            bb = Util.getBoundingBox(sa.getWkt());
        }
        bbox = new double[][] { { bb.get(0), bb.get(1) }, { bb.get(2), bb.get(3) } };
        long cellsInBBox = (long) ((bbox[1][0] - bbox[0][0]) / 0.01 * (bbox[1][1] - bbox[0][1]) / 0.01);
        long size = (groupCount.getValue() + sbenvsel.split(":").length + 2) * cellsInBBox * 4;
        LOGGER.debug("ALOC estimate size in MB, cells=" + cellsInBBox + ", bbox=" + bbox[0][0] + "," + bbox[0][1] + "," + bbox[1][0] + "," + bbox[1][1] + ", groups=" + groupCount.getValue() + ", layers=" + sbenvsel.split(":").length + ", size=" + size / 1024 / 1024 + ", max size=" + CommonData.getSettings().getProperty("aloc_size_limit_in_mb"));
        if (size / 1024 / 1024 > Integer.parseInt(CommonData.getSettings().getProperty("aloc_size_limit_in_mb"))) {
            getMapComposer().showMessage("Analysis is too large.  Reduce the number of groups, number of layers or area.", this);
            return -1;
        }
        HttpClient client = new HttpClient();
        PostMethod get = new PostMethod((CommonData.getSatServer() + "/ws/aloc/estimate?") + "gc=" + URLEncoder.encode(String.valueOf(groupCount.getValue()), StringConstants.UTF_8) + "&envlist=" + URLEncoder.encode(sbenvsel, StringConstants.UTF_8));
        String area;
        if (sa.getMapLayer() != null && sa.getMapLayer().getEnvelope() != null) {
            area = StringConstants.ENVELOPE + "(" + sa.getMapLayer().getEnvelope() + ")";
        } else {
            area = sa.getWkt();
        }
        get.addParameter(StringConstants.AREA, area);
        get.addRequestHeader(StringConstants.ACCEPT, StringConstants.TEXT_PLAIN);
        client.executeMethod(get);
        String estimate = get.getResponseBodyAsString();
        return Long.valueOf(estimate);
    } catch (Exception e) {
        LOGGER.error("Unable to get estimates", e);
    }
    return -1;
}
Also used : PostMethod(org.apache.commons.httpclient.methods.PostMethod) SelectedArea(au.org.emii.portal.menu.SelectedArea) HttpClient(org.apache.commons.httpclient.HttpClient)

Example 80 with HttpClient

use of org.apache.commons.httpclient.HttpClient in project spatial-portal by AtlasOfLivingAustralia.

the class LayerLegendScatterplotController method onSelect$cbHighlightArea.

public void onSelect$cbHighlightArea(Event event) {
    if (cbHighlightArea.getSelectedItem() != null) {
        if (cbHighlightArea.getSelectedItem().getValue() instanceof MapLayer) {
            MapLayer ml = cbHighlightArea.getSelectedItem().getValue();
            SelectedArea sa = new SelectedArea(ml, ml.getFacets() == null ? ml.getWKT() : null);
            data.setHighlightSa(sa);
        } else {
            String wkt = cbHighlightArea.getSelectedItem().getValue();
            SelectedArea sa = new SelectedArea(null, wkt);
            data.setHighlightSa(sa);
        }
    } else {
        data.setHighlightSa(null);
    }
    try {
        HttpClient client = new HttpClient();
        PostMethod post = new PostMethod(CommonData.getSatServer() + "/ws/scatterplot/style/" + data.getId());
        //add style parameters (highlight area)
        if (data.getHighlightSa() != null) {
            post.addParameter(StringConstants.HIGHLIGHT_WKT, data.getHighlightSa().getWkt());
        } else {
            post.addParameter(StringConstants.HIGHLIGHT_WKT, "");
        }
        post.addRequestHeader(StringConstants.ACCEPT, StringConstants.APPLICATION_JSON);
        client.executeMethod(post);
    } catch (Exception e) {
        LOGGER.error("error getting a new scatterplot id", e);
    }
    data.setImagePath(null);
    redraw();
}
Also used : PostMethod(org.apache.commons.httpclient.methods.PostMethod) HasMapLayer(au.org.emii.portal.menu.HasMapLayer) MapLayer(au.org.emii.portal.menu.MapLayer) SelectedArea(au.org.emii.portal.menu.SelectedArea) HttpClient(org.apache.commons.httpclient.HttpClient)

Aggregations

HttpClient (org.apache.commons.httpclient.HttpClient)399 GetMethod (org.apache.commons.httpclient.methods.GetMethod)221 PostMethod (org.apache.commons.httpclient.methods.PostMethod)120 HttpMethod (org.apache.commons.httpclient.HttpMethod)98 Test (org.junit.Test)87 IOException (java.io.IOException)82 InputStream (java.io.InputStream)70 HttpException (org.apache.commons.httpclient.HttpException)44 JSONParser (org.json.simple.parser.JSONParser)44 JSONObject (org.json.simple.JSONObject)40 Map (java.util.Map)35 ArrayList (java.util.ArrayList)27 HashMap (java.util.HashMap)25 HttpState (org.apache.commons.httpclient.HttpState)25 ZMailbox (com.zimbra.client.ZMailbox)23 Account (com.zimbra.cs.account.Account)22 StringRequestEntity (org.apache.commons.httpclient.methods.StringRequestEntity)22 ServiceException (com.zimbra.common.service.ServiceException)21 JSONArray (org.json.simple.JSONArray)21 ByteArrayRequestEntity (org.apache.commons.httpclient.methods.ByteArrayRequestEntity)20