Search in sources :

Example 6 with NameValuePair

use of org.apache.commons.httpclient.NameValuePair in project tdi-studio-se by Talend.

the class ExchangeUtils method sendPostRequest.

public static String sendPostRequest(String urlAddress, Map<String, String> parameters) throws Exception {
    HttpClient httpclient = new HttpClient();
    PostMethod postMethod = new PostMethod(urlAddress);
    if (parameters != null) {
        NameValuePair[] postData = new NameValuePair[parameters.size()];
        int i = 0;
        for (String key : parameters.keySet()) {
            String value = parameters.get(key);
            postData[i++] = new NameValuePair(key, value);
        }
        postMethod.addParameters(postData);
    }
    httpclient.executeMethod(postMethod);
    String response = postMethod.getResponseBodyAsString();
    postMethod.releaseConnection();
    return response;
}
Also used : NameValuePair(org.apache.commons.httpclient.NameValuePair) PostMethod(org.apache.commons.httpclient.methods.PostMethod) HttpClient(org.apache.commons.httpclient.HttpClient)

Example 7 with NameValuePair

use of org.apache.commons.httpclient.NameValuePair in project intellij-community by JetBrains.

the class JiraLegacyApi method findTasks.

@NotNull
@Override
public List<Task> findTasks(@NotNull String query, int max) throws Exception {
    // Unfortunately, both SOAP and XML-RPC interfaces of JIRA don't allow fetching *all* tasks from server, but
    // only filtered by some search term (see http://stackoverflow.com/questions/764282/how-can-jira-soap-api-not-have-this-method).
    // JQL was added in SOAP only since JIRA 4.0 (see method JiraSoapService#getIssuesFromJqlSearch() at
    // https://docs.atlassian.com/software/jira/docs/api/rpc-jira-plugin/latest/index.html?com/atlassian/jira/rpc/soap/JiraSoapService.html)
    // So due to this limitation and the need to support these old versions of bug tracker (3.0, 4.2) we need the following ugly and hacky
    // solution with extracting issues from RSS feed.
    GetMethod method = new GetMethod(myRepository.getUrl() + RSS_SEARCH_PATH);
    method.setQueryString(new NameValuePair[] { new NameValuePair("tempMax", String.valueOf(max)), new NameValuePair("assignee", TaskUtil.encodeUrl(myRepository.getUsername())), new NameValuePair("reset", "true"), new NameValuePair("sorter/field", "updated"), new NameValuePair("sorter/order", "DESC"), new NameValuePair("pager/start", "0") });
    return processRSS(method);
}
Also used : NameValuePair(org.apache.commons.httpclient.NameValuePair) GetMethod(org.apache.commons.httpclient.methods.GetMethod) NotNull(org.jetbrains.annotations.NotNull)

Example 8 with NameValuePair

use of org.apache.commons.httpclient.NameValuePair in project zaproxy by zaproxy.

the class GenericMethod method removeParameter.

/**
     * Removes all parameter with the given paramName and paramValue. If there
     * is more than one parameter with the given paramName, only one is
     * removed.  If there are none, then the request is ignored.
     *
     * @param paramName The parameter name to remove.
     * @param paramValue The parameter value to remove.
     *
     * @return true if a parameter was removed.
     *
     * @throws IllegalArgumentException when param name or value are null
     *
     * @since 2.0
     */
public boolean removeParameter(String paramName, String paramValue) throws IllegalArgumentException {
    log.trace("enter PostMethod.removeParameter(String, String)");
    if (paramName == null) {
        throw new IllegalArgumentException("Parameter name may not be null");
    }
    if (paramValue == null) {
        throw new IllegalArgumentException("Parameter value may not be null");
    }
    Iterator<NameValuePair> iter = this.params.iterator();
    while (iter.hasNext()) {
        NameValuePair pair = iter.next();
        if (paramName.equals(pair.getName()) && paramValue.equals(pair.getValue())) {
            iter.remove();
            return true;
        }
    }
    return false;
}
Also used : NameValuePair(org.apache.commons.httpclient.NameValuePair)

Example 9 with NameValuePair

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

the class PhylogeneticDiversityListResults method evalArea.

private void evalArea(SelectedArea sa) {
    try {
        Query sq = QueryUtil.queryFromSelectedArea(selectedQuery, sa, null, false, null);
        CSVReader r = new CSVReader(new StringReader(sq.speciesList()));
        JSONArray ja = new JSONArray();
        for (String[] s : r.readAll()) {
            ja.add(s[1]);
        }
        //call pd with specieslist=ja.toString()
        String url = CommonData.getSettings().getProperty(CommonData.PHYLOLIST_URL) + "/phylo/getPD";
        NameValuePair[] params = new NameValuePair[2];
        params[0] = new NameValuePair("noTreeText", StringConstants.TRUE);
        params[1] = new NameValuePair("speciesList", ja.toString());
        JSONParser jp = new JSONParser();
        JSONArray pds = (JSONArray) jp.parse(Util.readUrlPost(url, params));
        Map<String, String> pdrow = new HashMap<String, String>();
        Map<String, JSONArray> speciesRow = new HashMap<String, JSONArray>();
        for (int j = 0; j < pds.size(); j++) {
            String tree = "" + ((JSONObject) pds.get(j)).get(StringConstants.STUDY_ID);
            pdrow.put(tree, ((JSONObject) pds.get(j)).get("pd").toString());
            speciesRow.put(tree, (JSONArray) ((JSONObject) pds.get(j)).get("taxaRecognised"));
            //maxPD retrieval
            String maxPd = ((JSONObject) pds.get(j)).get("maxPd").toString();
            for (int k = 0; k < selectedTrees.size(); k++) {
                if (((Map<String, String>) selectedTrees.get(k)).get(StringConstants.STUDY_ID).equals(tree)) {
                    ((Map<String, String>) selectedTrees.get(k)).put("maxPd", maxPd);
                }
            }
        }
        areaPds.add(pdrow);
        areaSpeciesMatches.add(speciesRow);
    } catch (Exception e) {
        LOGGER.error("failed processing a pd for a selected area.", e);
    }
}
Also used : NameValuePair(org.apache.commons.httpclient.NameValuePair) Query(au.org.ala.spatial.util.Query) CSVReader(au.com.bytecode.opencsv.CSVReader) JSONArray(org.json.simple.JSONArray) JSONObject(org.json.simple.JSONObject) StringReader(java.io.StringReader) JSONParser(org.json.simple.parser.JSONParser)

Example 10 with NameValuePair

use of org.apache.commons.httpclient.NameValuePair in project zm-mailbox by Zimbra.

the class RawAuth method authenticate.

private void authenticate(String token) throws AuthenticationException, IOException {
    Response res = doGet(GET_AUTH, new NameValuePair(APPID, appId), new NameValuePair(TOKEN, token));
    cookie = res.getRequiredField(COOKIE);
    wssId = res.getRequiredField(WSSID);
    String s = res.getRequiredField(EXPIRATION);
    try {
        expiration = System.currentTimeMillis() + Long.parseLong(s) * Constants.MILLIS_PER_SECOND;
    } catch (NumberFormatException e) {
        throw new IOException("Invalid integer value for field '" + EXPIRATION + "': " + s);
    }
}
Also used : NameValuePair(org.apache.commons.httpclient.NameValuePair) IOException(java.io.IOException)

Aggregations

NameValuePair (org.apache.commons.httpclient.NameValuePair)162 ArrayList (java.util.ArrayList)109 Credentials (org.apache.commons.httpclient.Credentials)64 UsernamePasswordCredentials (org.apache.commons.httpclient.UsernamePasswordCredentials)64 Test (org.junit.Test)55 HttpTest (org.apache.sling.commons.testing.integration.HttpTest)49 JsonObject (javax.json.JsonObject)43 HashMap (java.util.HashMap)24 PostMethod (org.apache.commons.httpclient.methods.PostMethod)24 JsonArray (javax.json.JsonArray)20 Header (org.apache.commons.httpclient.Header)16 HashSet (java.util.HashSet)14 HttpClient (org.apache.commons.httpclient.HttpClient)13 HttpMethod (org.apache.commons.httpclient.HttpMethod)13 GetMethod (org.apache.commons.httpclient.methods.GetMethod)12 IOException (java.io.IOException)8 LinkedList (java.util.LinkedList)8 InputStream (java.io.InputStream)7 URL (java.net.URL)6 DefaultHttpMethodRetryHandler (org.apache.commons.httpclient.DefaultHttpMethodRetryHandler)5