Example usage for org.apache.commons.httpclient NameValuePair setName

List of usage examples for org.apache.commons.httpclient NameValuePair setName

Introduction

In this page you can find the example usage for org.apache.commons.httpclient NameValuePair setName.

Prototype

public void setName(String name) 

Source Link

Document

Set the name.

Usage

From source file:mesquite.tol.lib.BaseHttpRequestMaker.java

public static boolean postToServer(String s, String URI, StringBuffer response) {
    HttpClient client = new HttpClient();
    PostMethod method = new PostMethod(URI);
    method.addParameter("OS", StringEscapeUtils
            .escapeHtml(System.getProperty("os.name") + "\t" + System.getProperty("os.version")));
    method.addParameter("JVM", StringEscapeUtils
            .escapeHtml(System.getProperty("java.version") + "\t" + System.getProperty("java.vendor")));
    NameValuePair post = new NameValuePair();
    post.setName("post");
    post.setValue(StringEscapeUtils.escapeHtml(s));
    method.addParameter(post);/*from   w  ww .jav a2 s  .co m*/

    method.getParams().setParameter(HttpMethodParams.RETRY_HANDLER,
            new DefaultHttpMethodRetryHandler(3, false));

    return executeMethod(client, method, response);
}

From source file:net.sourceforge.jwbf.actions.mw.old.PostDelete.java

/**
 * /*w ww. j a v a2  s .co m*/
 * @param label of the article
 * @param tab with contains environment variable "wpEditToken"
 * @deprecated
 */
public PostDelete(final String label, Hashtable<String, String> tab) {

    NameValuePair action = new NameValuePair("wpConfirmB", "Delete Page");
    // this value is preseted
    NameValuePair wpReason = new NameValuePair("wpReason", "hier der Grund");
    wpReason.setName("backdraft");

    NameValuePair wpEditToken = new NameValuePair("wpEditToken", tab.get("wpEditToken"));

    PostMethod pm = new PostMethod("/index.php?title=" + label + "&action=delete");

    pm.setRequestBody(new NameValuePair[] { action, wpReason, wpEditToken });
    pm.getParams().setContentCharset(MediaWikiBot.CHARSET);
    msgs.add(pm);

}

From source file:com.griddynamics.jagger.coordinator.http.client.ExchangeClient.java

private String exchangeData(String url, Serializable obj) throws IOException {
    PostMethod method = new PostMethod(urlBase + url);
    NameValuePair pair = new NameValuePair();
    pair.setName(MESSAGE);
    pair.setValue(SerializationUtils.toString(obj));

    method.setQueryString(new NameValuePair[] { pair });
    try {//from  w  w  w  .j  a v  a2  s. c  om
        int returnCode = httpClient.executeMethod(method);
        log.debug("Exchange response code {}", returnCode);
        return method.getResponseBodyAsString();
    } finally {
        try {
            method.releaseConnection();
        } catch (Throwable e) {
            log.error("Cannot release connection", e);
        }
    }
}

From source file:net.sourceforge.jwbf.actions.mw.util.PostModifyContent.java

/**
 * /*  w w w .j a  v  a 2  s  .  c  o m*/
 * @param a the
 * @param tab internal value set
 * @param login a 
 */
public PostModifyContent(final ContentAccessable a, final Hashtable<String, String> tab, LoginData login) {

    String uS = "";
    try {
        uS = "/index.php?title=" + URLEncoder.encode(a.getLabel(), MediaWikiBot.CHARSET) + "&action=submit";
    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
    }

    NameValuePair action = new NameValuePair("wpSave", "Save");
    NameValuePair wpStarttime = new NameValuePair("wpStarttime", tab.get("wpStarttime"));
    NameValuePair wpEditToken = new NameValuePair("wpEditToken", tab.get("wpEditToken"));
    NameValuePair wpEdittime = new NameValuePair("wpEdittime", tab.get("wpEdittime"));

    NameValuePair wpTextbox = new NameValuePair("wpTextbox1", a.getText());

    String editSummaryText = a.getEditSummary();
    if (editSummaryText != null && editSummaryText.length() > 200) {
        editSummaryText = editSummaryText.substring(0, 200);
    }

    NameValuePair wpSummary = new NameValuePair("wpSummary", editSummaryText);

    NameValuePair wpMinoredit = new NameValuePair();

    if (a.isMinorEdit()) {
        wpMinoredit.setValue("1");
        wpMinoredit.setName("wpMinoredit");
    }

    LOG.info("WRITE: " + a.getLabel());
    PostMethod pm = new PostMethod(uS);
    pm.getParams().setContentCharset(MediaWikiBot.CHARSET);

    pm.setRequestBody(new NameValuePair[] { action, wpStarttime, wpEditToken, wpEdittime, wpTextbox, wpSummary,
            wpMinoredit });
    msgs.add(pm);
}

From source file:com.funambol.json.dao.JsonDAOImpl.java

public JsonResponse removeAllItems(String token, long since) throws HttpException, IOException {

    String request = Utility.getUrl(jsonServerUrl, resourceType, REMOVE_ITEM_URL);

    if (log.isTraceEnabled()) {
        log.trace("JsonDAOImpl: start removeAllItems");
    }/*from  www .  j  a  va  2s . co  m*/

    DeleteMethod remove = new DeleteMethod(request);

    if (since != 0) {
        NameValuePair nvp_since = new NameValuePair();
        nvp_since.setName("since");
        nvp_since.setValue("" + since);
        NameValuePair[] nvp = { nvp_since };
        remove.setQueryString(nvp);
    }

    if (log.isTraceEnabled()) {
        log.trace("JsonDAOImpl: removeAllItem request:" + request);
    }
    remove.setRequestHeader(Utility.TOKEN_HEADER_NAME, token);

    int statusCode = 0;
    String responseBody = null;
    try {
        statusCode = httpClient.executeMethod(remove);
        responseBody = remove.getResponseBodyAsString();
    } finally {
        remove.releaseConnection();
    }

    if (log.isTraceEnabled()) {
        log.trace("JsonDAOImpl: deleteAllItem response " + responseBody);
    }

    JsonResponse response = new JsonResponse(statusCode, responseBody);

    return response;
}

From source file:com.funambol.json.dao.JsonDAOImpl.java

public JsonResponse removeItem(String token, String id, long since) throws HttpException, IOException {

    String request = Utility.getUrl(jsonServerUrl, resourceType, REMOVE_ITEM_URL) + Utility.URL_SEP + id;

    if (log.isTraceEnabled()) {
        log.trace("JsonDAOImpl: start removeItem with id:" + id + "and since=" + since);
    }//  w w w .  ja  v  a 2 s . co  m

    DeleteMethod remove = new DeleteMethod(request);

    if (since != 0) {
        NameValuePair nvp_since = new NameValuePair();
        nvp_since.setName("since");
        nvp_since.setValue("" + since);
        NameValuePair[] nvp = { nvp_since };
        remove.setQueryString(nvp);
    }

    if (log.isTraceEnabled()) {
        log.trace("JsonDAOImpl: removeItem request:" + request);
    }
    remove.setRequestHeader(Utility.TOKEN_HEADER_NAME, token);

    int statusCode = 0;
    String responseBody = null;
    try {
        statusCode = httpClient.executeMethod(remove);
        responseBody = remove.getResponseBodyAsString();
    } finally {
        remove.releaseConnection();
    }

    if (log.isTraceEnabled()) {
        log.trace("JsonDAOImpl: deleteItem response " + responseBody);
        log.trace("JsonDAOImpl: item with id:" + id + " removed");
    }

    JsonResponse response = new JsonResponse(statusCode, responseBody);

    return response;
}

From source file:com.funambol.json.dao.JsonDAOImpl.java

public JsonResponse addItem(String token, String jsonObject, long since) throws HttpException, IOException {

    String request = Utility.getUrl(jsonServerUrl, resourceType, ADD_ITEM_URL);

    if (log.isTraceEnabled()) {
        log.trace("JsonDAOImpl: start addItem; since=" + since);
    }//from  w  w  w  . j  a  v a2s .c  o m

    PostMethod post = new PostMethod(request);
    post.setRequestHeader(Utility.TOKEN_HEADER_NAME, token);
    post.setRequestEntity(new StringRequestEntity(jsonObject));

    if (since != 0) {
        NameValuePair nvp_since = new NameValuePair();
        nvp_since.setName("since");
        nvp_since.setValue("" + since);
        NameValuePair[] nvp = { nvp_since };
        post.setQueryString(nvp);
    }

    if (log.isTraceEnabled()) {
        log.trace("addItem Request: " + request);
    }
    if (Configuration.getConfiguration().isDebugMode()) {
        if (log.isTraceEnabled()) {
            log.trace("JSON to add " + jsonObject);
        }
    }

    int statusCode = 0;
    String responseBody = null;

    try {
        statusCode = httpClient.executeMethod(post);
        responseBody = post.getResponseBodyAsString();
    } finally {
        post.releaseConnection();
    }

    if (log.isTraceEnabled()) {
        log.trace("JsonDAOImpl: statusCode " + statusCode + "; added item" + responseBody);
        log.trace("JsonDAOImpl: item added");
    }

    JsonResponse response = new JsonResponse(statusCode, responseBody);

    return response;
}

From source file:com.funambol.json.dao.JsonDAOImpl.java

public JsonResponse updateItem(String token, String id, String jsonObject, long since)
        throws HttpException, IOException {

    String request = Utility.getUrl(jsonServerUrl, resourceType, UPDATE_ITEM_URL) + Utility.URL_SEP + id;

    if (log.isTraceEnabled()) {
        log.trace(//from www  .j  ava 2s.c om
                "JsonDAOImpl: start updateItem with id:" + id + " and since=" + since + " sessionid:" + token);
    }

    PutMethod put = new PutMethod(request);
    put.setRequestHeader(Utility.TOKEN_HEADER_NAME, token);
    put.setRequestEntity(new StringRequestEntity(jsonObject));

    if (since != 0) {
        NameValuePair nvp_since = new NameValuePair();
        nvp_since.setName("since");
        nvp_since.setValue("" + since);
        NameValuePair[] nvp = { nvp_since };
        put.setQueryString(nvp);
    }

    if (log.isTraceEnabled()) {
        log.trace("updateItem Request: " + request);
    }
    if (Configuration.getConfiguration().isDebugMode()) {
        if (log.isTraceEnabled()) {
            log.trace("JSON to update " + jsonObject);
        }
    }

    int statusCode = 0;
    String responseBody = null;
    try {
        statusCode = httpClient.executeMethod(put);
        responseBody = put.getResponseBodyAsString();
    } finally {
        put.releaseConnection();
    }

    if (log.isTraceEnabled()) {
        log.trace("JsonDAOImpl: item with id:" + id + " updated; response " + responseBody);
    }

    JsonResponse response = new JsonResponse(statusCode, responseBody);

    return response;

}

From source file:com.funambol.json.api.dao.FunambolJSONApiDAO.java

/**
 *
 *//*from w  w  w .ja  v a2s.c o  m*/
protected String sendGetRequest(String REQUEST, long since, long until) throws IOOperationException {

    String response = null;
    GetMethod method = null;
    try {
        if (log.isTraceEnabled()) {
            log.trace("\nREQUEST:" + REQUEST);
        }
        method = new GetMethod(REQUEST);
        HttpClient httpClient = new HttpClient();
        if (since != 0 && until != 0) {
            NameValuePair nvp_since = new NameValuePair();
            nvp_since.setName("since");
            nvp_since.setValue("" + since);
            NameValuePair nvp_until = new NameValuePair();
            nvp_until.setName("until");
            nvp_until.setValue("" + until);
            NameValuePair[] nvp = { nvp_since, nvp_until };
            method.setQueryString(nvp);
        }

        if (this.sessionid != null) {
            method.setRequestHeader("Authorization", this.sessionid);
        }

        printMethodParams(method);
        printHeaderFields(method.getRequestHeaders(), "REQUEST");

        int code = httpClient.executeMethod(method);

        response = method.getResponseBodyAsString();

        if (log.isTraceEnabled()) {
            log.trace("RESPONSE code: " + code);
        }
        printHeaderFields(method.getResponseHeaders(), "RESPONSE");

    } catch (Exception e) {
        throw new IOOperationException("Error GET Request ", e);
    } finally {
        if (method != null) {
            method.releaseConnection();
        }
    }

    return response;
}

From source file:org.apache.wookie.proxy.ProxyClient.java

/**
 * Processes the parameters passed through to the request,
 * removing the parameters used by the proxy itself
 * @return//from  w  w w.ja va2  s  .c  om
 */
private void filterParameters(Map<Object, Object> umap) {
    Map<Object, Object> map = new HashMap<Object, Object>(umap);
    map.remove("instanceid_key");
    map.remove("url");
    ArrayList<NameValuePair> params = new ArrayList<NameValuePair>();
    for (Object key : map.keySet().toArray()) {
        for (String value : (String[]) map.get(key)) {
            NameValuePair param = new NameValuePair();
            param.setName((String) key);
            param.setValue(value);
            params.add(param);
        }
    }
    parameters = params.toArray(new NameValuePair[params.size()]);
}