Search in sources :

Example 96 with NameValuePair

use of org.apache.commons.httpclient.NameValuePair in project ecf by eclipse.

the class SimpleResponse method getCharset.

public String getCharset() {
    String charset = DEFAULT_CONTENT_CHARSET;
    Header contenttype = this.headers.getFirstHeader("Content-Type");
    if (contenttype != null) {
        HeaderElement[] values = contenttype.getElements();
        if (values.length == 1) {
            NameValuePair param = values[0].getParameterByName("charset");
            if (param != null) {
                charset = param.getValue();
            }
        }
    }
    return charset;
}
Also used : NameValuePair(org.apache.commons.httpclient.NameValuePair) Header(org.apache.commons.httpclient.Header) HeaderElement(org.apache.commons.httpclient.HeaderElement)

Example 97 with NameValuePair

use of org.apache.commons.httpclient.NameValuePair in project pinpoint by naver.

the class HttpClientIT method test.

@Test
public void test() {
    HttpClient client = new HttpClient();
    client.getParams().setConnectionManagerTimeout(CONNECTION_TIMEOUT);
    client.getParams().setSoTimeout(SO_TIMEOUT);
    GetMethod method = new GetMethod(getCallUrl());
    // Provide custom retry handler is necessary
    method.getParams().setParameter(HttpMethodParams.RETRY_HANDLER, new DefaultHttpMethodRetryHandler(3, false));
    method.setQueryString(new NameValuePair[] { new NameValuePair("key2", "value2") });
    try {
        // Execute the method.
        client.executeMethod(method);
    } catch (Exception ignored) {
    } finally {
        method.releaseConnection();
    }
    PluginTestVerifier verifier = PluginTestVerifierHolder.getInstance();
    verifier.printCache();
}
Also used : NameValuePair(org.apache.commons.httpclient.NameValuePair) HttpClient(org.apache.commons.httpclient.HttpClient) GetMethod(org.apache.commons.httpclient.methods.GetMethod) DefaultHttpMethodRetryHandler(org.apache.commons.httpclient.DefaultHttpMethodRetryHandler) PluginTestVerifier(com.navercorp.pinpoint.bootstrap.plugin.test.PluginTestVerifier) Test(org.junit.Test)

Example 98 with NameValuePair

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

the class GenericMethod method removeParameter.

/**
 * Removes all parameters with the given paramName. If there is more than
 * one parameter with the given paramName, all of them are removed.  If
 * there is just one, it is removed.  If there are none, then the request
 * is ignored.
 *
 * @param paramName The parameter name to remove.
 *
 * @return true if at least one parameter was removed
 *
 * @throws IllegalArgumentException When the parameter name passed is null
 *
 * @since 2.0
 */
public boolean removeParameter(String paramName) throws IllegalArgumentException {
    log.trace("enter PostMethod.removeParameter(String)");
    if (paramName == null) {
        throw new IllegalArgumentException("Argument passed to removeParameter(String) cannot be null");
    }
    boolean removed = false;
    Iterator<NameValuePair> iter = this.params.iterator();
    while (iter.hasNext()) {
        NameValuePair pair = iter.next();
        if (paramName.equals(pair.getName())) {
            iter.remove();
            removed = true;
        }
    }
    return removed;
}
Also used : NameValuePair(org.apache.commons.httpclient.NameValuePair)

Example 99 with NameValuePair

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

the class GenericMethod method getParameter.

/**
 * Gets the parameter of the specified name. If there exists more than one
 * parameter with the name paramName, then only the first one is returned.
 *
 * @param paramName name of the parameter
 *
 * @return If a parameter exists with the name argument, the corresponding
 *         NameValuePair is returned.  Otherwise null.
 *
 * @since 2.0
 */
public NameValuePair getParameter(String paramName) {
    log.trace("enter PostMethod.getParameter(String)");
    if (paramName == null) {
        return null;
    }
    Iterator<NameValuePair> iter = this.params.iterator();
    while (iter.hasNext()) {
        NameValuePair parameter = iter.next();
        if (paramName.equals(parameter.getName())) {
            return parameter;
        }
    }
    return null;
}
Also used : NameValuePair(org.apache.commons.httpclient.NameValuePair)

Example 100 with NameValuePair

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

the class BigSwitchBcfApi method executeRetrieveObject.

@SuppressWarnings("unchecked")
protected <T> T executeRetrieveObject(final Type returnObjectType, final String uri, final Map<String, String> parameters) throws BigSwitchBcfApiException {
    checkInvariants();
    GetMethod gm = (GetMethod) createMethod("get", uri, _port);
    setHttpHeader(gm);
    if (parameters != null && !parameters.isEmpty()) {
        List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(parameters.size());
        for (Entry<String, String> e : parameters.entrySet()) {
            nameValuePairs.add(new NameValuePair(e.getKey(), e.getValue()));
        }
        gm.setQueryString(nameValuePairs.toArray(new NameValuePair[0]));
    }
    executeMethod(gm);
    String hash = checkResponse(gm, "BigSwitch HTTP get failed: ");
    T returnValue;
    try {
        // CAUTIOUS: Safety margin of 2048 characters - extend if needed.
        returnValue = (T) gson.fromJson(gm.getResponseBodyAsString(2048), returnObjectType);
    } catch (IOException e) {
        S_LOGGER.error("IOException while retrieving response body", e);
        throw new BigSwitchBcfApiException(e);
    } finally {
        gm.releaseConnection();
    }
    if (returnValue instanceof ControlClusterStatus) {
        if (HASH_CONFLICT.equals(hash)) {
            isPrimary = true;
            ((ControlClusterStatus) returnValue).setTopologySyncRequested(true);
        } else if (!HASH_IGNORE.equals(hash) && !isPrimary) {
            isPrimary = true;
            ((ControlClusterStatus) returnValue).setTopologySyncRequested(true);
        }
    }
    return returnValue;
}
Also used : NameValuePair(org.apache.commons.httpclient.NameValuePair) GetMethod(org.apache.commons.httpclient.methods.GetMethod) ArrayList(java.util.ArrayList) IOException(java.io.IOException)

Aggregations

NameValuePair (org.apache.commons.httpclient.NameValuePair)217 ArrayList (java.util.ArrayList)114 Credentials (org.apache.commons.httpclient.Credentials)64 UsernamePasswordCredentials (org.apache.commons.httpclient.UsernamePasswordCredentials)64 Test (org.junit.Test)61 HttpTest (org.apache.sling.commons.testing.integration.HttpTest)49 JsonObject (javax.json.JsonObject)43 PostMethod (org.apache.commons.httpclient.methods.PostMethod)41 HashMap (java.util.HashMap)28 IOException (java.io.IOException)23 Header (org.apache.commons.httpclient.Header)21 JsonArray (javax.json.JsonArray)20 HttpClient (org.apache.commons.httpclient.HttpClient)19 HashSet (java.util.HashSet)17 HttpMethod (org.apache.commons.httpclient.HttpMethod)16 GetMethod (org.apache.commons.httpclient.methods.GetMethod)16 Cookie (org.apache.commons.httpclient.Cookie)13 GetRequest (org.eclipse.ecf.internal.bulletinboard.commons.webapp.GetRequest)10 LinkedList (java.util.LinkedList)8 Map (java.util.Map)8