Example usage for org.apache.commons.httpclient.methods MultipartPostMethod addParameter

List of usage examples for org.apache.commons.httpclient.methods MultipartPostMethod addParameter

Introduction

In this page you can find the example usage for org.apache.commons.httpclient.methods MultipartPostMethod addParameter.

Prototype

public void addParameter(String paramString1, String paramString2) 

Source Link

Usage

From source file:org.openmicroscopy.is.HttpImageServer.java

public long convertPlaneFromTIFF(final long pixelsID, final int theZ, final int theC, final int theT,
        final long fileID) throws ImageServerException {
    MultipartPostMethod post = startCall();
    try {/*from   ww w.  ja v  a  2s  .  c  o m*/
        post.addParameter("Method", "ConvertTIFF");
        post.addParameter("PixelsID", Long.toString(pixelsID));
        post.addParameter("theZ", Integer.toString(theZ));
        post.addParameter("theC", Integer.toString(theC));
        post.addParameter("theT", Integer.toString(theT));
        post.addParameter("FileID", Long.toString(fileID));
        executeCall(post);

        return Long.parseLong(post.getResponseBodyAsString().trim());
    } finally {
        finishCall(post);
    }
}

From source file:org.openmicroscopy.is.HttpImageServer.java

public long convertPlaneFromTIFF(final long pixelsID, final int theZ, final int theC, final int theT,
        final long fileID, final int directory) throws ImageServerException {
    MultipartPostMethod post = startCall();
    try {/*from  w w  w  .j a  v a  2 s . c  om*/
        post.addParameter("Method", "ConvertTIFF");
        post.addParameter("PixelsID", Long.toString(pixelsID));
        post.addParameter("theZ", Integer.toString(theZ));
        post.addParameter("theC", Integer.toString(theC));
        post.addParameter("theT", Integer.toString(theT));
        post.addParameter("FileID", Long.toString(fileID));
        post.addParameter("TIFFDirIndex", Integer.toString(directory));
        executeCall(post);

        return Long.parseLong(post.getResponseBodyAsString().trim());
    } finally {
        finishCall(post);
    }
}

From source file:org.openmicroscopy.is.HttpImageServer.java

public long convertRows(final long pixelsID, final int theY, final int numRows, final int theZ, final int theC,
        final int theT, final long fileID, final long offset, final boolean bigEndian)
        throws ImageServerException {
    MultipartPostMethod post = startCall();
    try {/*from  ww  w  . j a  v a 2s.  c o m*/
        post.addParameter("Method", "ConvertRows");
        post.addParameter("PixelsID", Long.toString(pixelsID));
        post.addParameter("theY", Integer.toString(theY));
        post.addParameter("nRows", Integer.toString(numRows));
        post.addParameter("theZ", Integer.toString(theZ));
        post.addParameter("theC", Integer.toString(theC));
        post.addParameter("theT", Integer.toString(theT));
        post.addParameter("FileID", Long.toString(fileID));
        post.addParameter("Offset", Long.toString(offset));
        post.addParameter("BigEndian", bigEndian ? "1" : "0");
        executeCall(post);

        return Long.parseLong(post.getResponseBodyAsString().trim());
    } finally {
        finishCall(post);
    }
}

From source file:org.openmicroscopy.is.HttpImageServer.java

public PlaneStatistics getPlaneStatistics(long pixelsID) throws ImageServerException {
    PixelsFileFormat pff = getPixelsInfo(pixelsID);
    int sizeZ = pff.getSizeZ();
    int sizeC = pff.getSizeC();
    int sizeT = pff.getSizeT();

    MultipartPostMethod post = startCall();
    try {//from  ww  w. j  a v a  2  s.  c o m
        post.addParameter("Method", "GetPlaneStats");
        post.addParameter("PixelsID", Long.toString(pixelsID));
        executeCall(post);

        double[][][] minimum = new double[sizeZ][sizeC][sizeT], maximum = new double[sizeZ][sizeC][sizeT],
                mean = new double[sizeZ][sizeC][sizeT], sigma = new double[sizeZ][sizeC][sizeT],
                geomean = new double[sizeZ][sizeC][sizeT], geosigma = new double[sizeZ][sizeC][sizeT],
                centroidX = new double[sizeZ][sizeC][sizeT], centroidY = new double[sizeZ][sizeC][sizeT],
                sumI = new double[sizeZ][sizeC][sizeT], sumI2 = new double[sizeZ][sizeC][sizeT],
                sumLogI = new double[sizeZ][sizeC][sizeT], sumXI = new double[sizeZ][sizeC][sizeT],
                sumYI = new double[sizeZ][sizeC][sizeT], sumZI = new double[sizeZ][sizeC][sizeT];

        String result = post.getResponseBodyAsString();
        StringTokenizer rtoken = new StringTokenizer(result, "\r\n");

        while (rtoken.hasMoreTokens()) {
            String line = rtoken.nextToken();
            StringTokenizer ltoken = new StringTokenizer(line, "\t");

            int theC = getIntToken(ltoken);
            int theT = getIntToken(ltoken);
            int theZ = getIntToken(ltoken);
            minimum[theZ][theC][theT] = getDoubleToken(ltoken);
            maximum[theZ][theC][theT] = getDoubleToken(ltoken);
            mean[theZ][theC][theT] = getDoubleToken(ltoken);
            geomean[theZ][theC][theT] = getDoubleToken(ltoken);
            geosigma[theZ][theC][theT] = getDoubleToken(ltoken);
            centroidX[theZ][theC][theT] = getDoubleToken(ltoken);
            centroidY[theZ][theC][theT] = getDoubleToken(ltoken);
            sumI[theZ][theC][theT] = getDoubleToken(ltoken);
            sumI2[theZ][theC][theT] = getDoubleToken(ltoken);
            sumLogI[theZ][theC][theT] = getDoubleToken(ltoken);
            sumXI[theZ][theC][theT] = getDoubleToken(ltoken);
            sumYI[theZ][theC][theT] = getDoubleToken(ltoken);
            sumZI[theZ][theC][theT] = getDoubleToken(ltoken);
        }

        return new PlaneStatistics(minimum, maximum, mean, sigma, geomean, geosigma, centroidX, centroidY, sumI,
                sumI2, sumLogI, sumXI, sumYI, sumZI);
    } finally {
        finishCall(post);
    }
}

From source file:org.openmicroscopy.is.HttpImageServer.java

public StackStatistics getStackStatistics(long pixelsID) throws ImageServerException {
    PixelsFileFormat pff = getPixelsInfo(pixelsID);
    int sizeC = pff.getSizeC();
    int sizeT = pff.getSizeT();

    MultipartPostMethod post = startCall();
    try {/*  w  w  w. j  a v a 2s  .  c o  m*/
        post.addParameter("Method", "GetStackStats");
        post.addParameter("PixelsID", Long.toString(pixelsID));
        executeCall(post);

        double[][] minimum = new double[sizeC][sizeT], maximum = new double[sizeC][sizeT],
                mean = new double[sizeC][sizeT], sigma = new double[sizeC][sizeT],
                geomean = new double[sizeC][sizeT], geosigma = new double[sizeC][sizeT],
                centroidX = new double[sizeC][sizeT], centroidY = new double[sizeC][sizeT],
                centroidZ = new double[sizeC][sizeT], sumI = new double[sizeC][sizeT],
                sumI2 = new double[sizeC][sizeT], sumLogI = new double[sizeC][sizeT],
                sumXI = new double[sizeC][sizeT], sumYI = new double[sizeC][sizeT],
                sumZI = new double[sizeC][sizeT];

        String result = post.getResponseBodyAsString();
        StringTokenizer rtoken = new StringTokenizer(result, "\r\n");

        while (rtoken.hasMoreTokens()) {
            String line = rtoken.nextToken();
            StringTokenizer ltoken = new StringTokenizer(line, "\t");

            int theC = getIntToken(ltoken);
            int theT = getIntToken(ltoken);
            minimum[theC][theT] = getDoubleToken(ltoken);
            maximum[theC][theT] = getDoubleToken(ltoken);
            mean[theC][theT] = getDoubleToken(ltoken);
            geomean[theC][theT] = getDoubleToken(ltoken);
            geosigma[theC][theT] = getDoubleToken(ltoken);
            centroidX[theC][theT] = getDoubleToken(ltoken);
            centroidY[theC][theT] = getDoubleToken(ltoken);
            centroidZ[theC][theT] = getDoubleToken(ltoken);
            sumI[theC][theT] = getDoubleToken(ltoken);
            sumI2[theC][theT] = getDoubleToken(ltoken);
            sumLogI[theC][theT] = getDoubleToken(ltoken);
            sumXI[theC][theT] = getDoubleToken(ltoken);
            sumYI[theC][theT] = getDoubleToken(ltoken);
            sumZI[theC][theT] = getDoubleToken(ltoken);
        }

        return new StackStatistics(minimum, maximum, mean, sigma, geomean, geosigma, centroidX, centroidY,
                centroidZ, sumI, sumI2, sumLogI, sumXI, sumYI, sumZI);
    } finally {
        finishCall(post);
    }
}

From source file:oscar.eform.actions.ManageEFormAction.java

public ActionForward exportEFormSend(ActionMapping mapping, ActionForm form, HttpServletRequest request,
        HttpServletResponse response) throws Exception {

    String username = request.getParameter("username");
    String password = request.getParameter("password");

    String fid = request.getParameter("fid");
    MiscUtils.getLogger().debug("fid: " + fid);
    EForm eForm = new EForm(fid, "1");
    //===================
    HttpClient client = new HttpClient();
    client.getParams().setCookiePolicy(CookiePolicy.RFC_2109);

    PostMethod method = new PostMethod("http://mydrugref.org/sessions");

    method.addParameter("session[email]", username);
    method.addParameter("session[password]", password);

    int statusCode = client.executeMethod(method);

    //need to check if login worked

    byte[] responseBody = method.getResponseBody();

    MiscUtils.getLogger().debug(new String(responseBody));

    MiscUtils.getLogger()//from   ww w. ja v  a2  s  .  c  om
            .debug("--------------------------------------------------------------------------------------");
    MultipartPostMethod eformPost = new MultipartPostMethod("http://mydrugref.org/e_forms/");

    String documentDir = OscarProperties.getInstance().getProperty("DOCUMENT_DIR");
    File docDir = new File(documentDir);
    String exportFilename = "eformExport" + System.currentTimeMillis() + "" + (Math.random() * 100);
    MiscUtils.getLogger().debug("Exported file name " + exportFilename);
    File exportFile = new File(documentDir, exportFilename);

    FileOutputStream fos = new FileOutputStream(exportFile);

    EFormExportZip eFormExportZip = new EFormExportZip();
    List<EForm> eForms = new ArrayList<EForm>();
    eForms.add(eForm);
    eFormExportZip.exportForms(eForms, fos);
    fos.close();

    eformPost.addParameter("e_form[name]", eForm.getFormName());
    eformPost.addParameter("e_form[category]", request.getParameter("category"));
    eformPost.addParameter("e_form[uploaded_data]", exportFile.getName(), exportFile);

    int statusCode2 = client.executeMethod(eformPost);

    byte[] responseBody2 = eformPost.getResponseBody();

    MiscUtils.getLogger().debug("ST " + statusCode2);
    MiscUtils.getLogger().debug(new String(responseBody2));
    //TODO:Need to handle errors

    return mapping.findForward("success");
}