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;
}
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();
}
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;
}
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;
}
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;
}
Aggregations