Example usage for org.apache.commons.httpclient.methods PostMethod setParameter

List of usage examples for org.apache.commons.httpclient.methods PostMethod setParameter

Introduction

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

Prototype

public void setParameter(String paramString1, String paramString2) 

Source Link

Usage

From source file:org.vamdc.taverna.vamdc_taverna_suite.common.UWSCaller.java

/**
 * //ww  w. j av  a 2  s  .c o  m
 * @param strURL
 * @param append
 * @throws Exception
*/
private static void executeJob(String strURL, String append) throws Exception {
    if (append != null && !append.trim().equals("")) {
        strURL = strURL + "/" + append;
    }
    PostMethod post = new PostMethod(strURL);
    post.setFollowRedirects(false);
    post.setParameter("phase", "RUN");
    //
    HttpClient httpclient = new HttpClient();
    int result = httpclient.executeMethod(post);
    int statuscode = post.getStatusCode();
    System.out.println(post.getResponseBodyAsString());
}

From source file:org.wso2.carbon.esb.proxyservice.test.proxyservices.UrlEncordedFormPostViaProxyTestCase.java

@SetEnvironment(executionEnvironments = { ExecutionEnvironment.STANDALONE })
@Test(groups = {//  ww  w  .j  a va 2 s  . c o m
        "wso2.esb" }, description = "Patch : ESBJAVA-1696 : Encoded Special characters in the URL is decoded at the Gateway and not re-encoded", enabled = true)
public void testEncodingSpecialCharacterViaHttpProxy() throws IOException {
    HttpClient client = new HttpClient();
    client.getParams().setParameter(HttpMethodParams.RETRY_HANDLER,
            new DefaultHttpMethodRetryHandler(0, false));
    client.getParams().setSoTimeout(5000);
    client.getParams().setConnectionManagerTimeout(5000);

    // Create POST method
    String url = getProxyServiceURLHttp("MyProxy");
    PostMethod method = new PostMethod(url);
    // Set parameters on POST
    String value1 = "Hello World";
    String value2 = "This is a Form Submission containing %";
    String value3 = URLEncoder.encode("This is an encoded value containing %");
    method.setParameter("test1", value1);
    method.addParameter("test2", value2);
    method.addParameter("test3", value3);

    // Execute and print response
    try {
        client.executeMethod(method);
    } catch (Exception e) {

    } finally {
        method.releaseConnection();
    }
    String response = wireMonitorServer.getCapturedMessage();
    String[] responseArray = response.split("test");

    if (responseArray.length < 3) {
        Assert.fail("All attributes are not sent");
    }
    for (String res : responseArray) {
        if (res.startsWith("1")) {
            Assert.assertTrue(res.startsWith("1=" + URLEncoder.encode(value1).replace("+", "%20")));
        } else if (res.startsWith("2")) {
            Assert.assertTrue(res.startsWith("2=" + URLEncoder.encode(value2).replace("+", "%20")));
        } else if (res.startsWith("3")) {
            Assert.assertTrue(res.startsWith("3=" + URLEncoder.encode(value3)));
        }
    }

}

From source file:pukiwikiCommunicator.connector.SaveButtonDebugFrame.java

private void replaceTextWith(String x) {
    // System.out.println("updateButton.actionPerformed, event="+evt);
    //TODO add your code for updateButton.actionPerformed

    /* make the body (fig) */
    /*/* ww w.  ja v  a2s.co m*/
    try{
       fig=new String(fig.getBytes("UTF-8"),  "UTF-8");
    }
    catch(Exception e){
       return;
    }
    */
    if (this.updateText == null)
        this.updateText = "";
    this.updateText = this.updateText + "\n " + insertSpaceAfterNewLine(x);

    this.urlField.setText(this.actionUrl);
    String url = this.urlField.getText();
    this.println("url=" + url);
    //      this.messageTextArea.append(this.updateText);
    BufferedReader br = null;
    //      System.out.println("updateText="+this.updateText);
    this.println("editWriteValue=" + this.editWriteValue);
    this.println("editCmd=" + this.editCmd);
    this.println("editPage=" + this.editPage);
    this.println("digest=" + this.editDigest);
    try {
        PostMethod method = new PostMethod(url);
        if (this.client == null)
            return;
        method.getParams().setContentCharset(this.pageCharSet);
        method.setParameter("msg", this.updateText);
        //          method.setParameter("encode_hint",this.editEncodeHint);
        method.addParameter("write", this.editWriteValue);
        method.addParameter("cmd", this.editCmd);
        method.addParameter("page", this.editPage);
        method.addParameter("digest", this.editDigest);
        int status = client.executeMethod(method);
        if (status != HttpStatus.SC_OK) {
            this.println("Method failed: " + method.getStatusLine());
            method.getResponseBodyAsString();
        } else {
            br = new BufferedReader(new InputStreamReader(method.getResponseBodyAsStream()));
            String readLine;
            while (((readLine = br.readLine()) != null)) {
                this.println(readLine);
            }
        }
        method.releaseConnection();
    } catch (Exception e) {
        //         this.messageTextArea.append(e.toString()+"\n");
        System.out.println("" + e);
        e.printStackTrace();
    }

}

From source file:st.happy_camper.flume.twitter.TwitterStreamingConnection.java

/**
 * @return//  w ww .  ja v a2 s . c o m
 */
private void doOpen() {
    int backoff = 10000;

    while (true) {
        PostMethod method = new PostMethod(URL);

        LOG.info("post: " + this.postContent);
        method.setParameter("track", this.postContent);
        try {
            int statusCode = httpClient.executeMethod(method);
            switch (statusCode) {
            case 200: {
                LOG.info("Connected.");
                this.method = method;
                this.reader = new BufferedReader(
                        new InputStreamReader(method.getResponseBodyAsStream(), "utf8"));
                return;
            }
            case 401:
            case 403:
            case 406:
            case 413:
            case 416: {
                String message = String.format("%d %s.", statusCode, HttpStatus.getStatusText(statusCode));
                LOG.warn(message);
                LOG.warn(method.getResponseBodyAsString());
                method.releaseConnection();

                throw new IllegalStateException(message);
            }
            case 420: {
                LOG.warn("420 Rate Limited.");
                method.releaseConnection();
                break;
            }
            case 500: {
                LOG.warn("500 Server Internal Error.");
                method.releaseConnection();
                break;
            }
            case 503: {
                LOG.warn("503 Service Overloaded.");
                method.releaseConnection();
                break;
            }
            default: {
                String message = "Unknown status code: " + statusCode;
                LOG.warn(message);
                method.releaseConnection();
            }
            }
        } catch (IllegalStateException e) {
            throw e;
        } catch (Exception e) {
            LOG.error(e.getMessage(), e);
            method.releaseConnection();
        }

        int wait = rnd.nextInt(backoff) + 1;
        LOG.info(String.format("Retry after %d milliseconds.", wait));
        try {
            Thread.sleep(wait);
        } catch (InterruptedException e) {
            LOG.error(e.getMessage(), e);
        }
        if (backoff < 240000) {
            backoff *= 2;
            if (backoff >= 240000) {
                backoff = 240000;
            }
        }
    }
}

From source file:xbl.http.CookieForm.java

public void setPostParameters(PostMethod post) {
    Nodes inputs = query(this.element, "//*:input");
    for (int i = 0; i < inputs.size(); i++) {
        Element input = (Element) inputs.get(i);
        post.setParameter(input.getAttributeValue("name"), input.getAttributeValue("value"));
    }/*from   www.  jav a 2 s  .  com*/
}

From source file:xbl.http.SignInForm.java

public void setPostParameters(PostMethod post) {
    Nodes inputs = this.query(this.element, "//*:input");
    for (int i = 0; i < inputs.size(); i++) {
        Element input = (Element) inputs.get(i);
        String name = input.getAttributeValue("name");
        String value = input.getAttributeValue("value");
        post.setParameter(name, value);
    }/*from  w w w . j  a v  a2s  .c o  m*/
    post.setParameter("LoginOptions", "2");
    post.setParameter("passwd", this.passwd);
    post.setParameter("login", this.login);
}