use of org.apache.hc.core5.http.copied.NameValuePair in project httpcomponents-core by apache.
the class TestURIBuilder method testSetParametersWithNullList.
@Test
public void testSetParametersWithNullList() throws Exception {
final URI uri = new URI("http", null, "localhost", 80, "/test", "param=test", null);
final URIBuilder uribuilder = new URIBuilder(uri).setParameters((List<NameValuePair>) null);
final URI result = uribuilder.build();
Assertions.assertEquals(new URI("http://localhost:80/test"), result);
}
use of org.apache.hc.core5.http.copied.NameValuePair in project vassal by vassalengine.
the class HttpRequestWrapper method buildPost.
private HttpPost buildPost(String path, Properties props) throws IOException {
final HttpPost httpPost = new HttpPost(baseURL + path);
final List<NameValuePair> params = new ArrayList<>();
for (final Enumeration<?> e = props.keys(); e.hasMoreElements(); ) {
final String key = (String) e.nextElement();
final String value = props.getProperty(key);
params.add(new BasicNameValuePair(key, value));
}
httpPost.setEntity(new UrlEncodedFormEntity(params));
return httpPost;
}
use of org.apache.hc.core5.http.copied.NameValuePair in project OpenLineage by OpenLineage.
the class ArgumentParser method parse.
public static ArgumentParser parse(String clientUrl) {
URI uri = URI.create(clientUrl);
String host = uri.getScheme() + "://" + uri.getAuthority();
String path = uri.getPath();
String[] elements = path.split("/");
String version = get(elements, "api", 1, DEFAULTS.getVersion());
String namespace = get(elements, "namespaces", 3, DEFAULTS.getNamespace());
String jobName = get(elements, "jobs", 5, DEFAULTS.getJobName());
String runId = get(elements, "runs", 7, DEFAULTS.getParentRunId());
List<NameValuePair> nameValuePairList = URLEncodedUtils.parse(uri, StandardCharsets.UTF_8);
Optional<String> apiKey = getApiKey(nameValuePairList);
Optional<Map<String, String>> urlParams = getUrlParams(nameValuePairList);
log.info(String.format("%s/api/%s/namespaces/%s/jobs/%s/runs/%s", host, version, namespace, jobName, runId));
return new ArgumentParser(host, version, namespace, jobName, runId, apiKey, urlParams);
}
use of org.apache.hc.core5.http.copied.NameValuePair in project datagear by datageartech.
the class HttpDataSet method toNameValuePairs.
/**
* 将指定JSON字符串转换为名/值列表。
*
* @param nameValueObjJsonArray
* 允许为{@code null}、{@code ""}
* @return 空列表表示无名/值,返回{@code #NOT_NAME_VALUE_PAIR_OBJ_ARRAY_JSON}表示{@code nameValueObjJsonArray}格式不合法
* @throws Throwable
*/
@SuppressWarnings("unchecked")
protected List<NameValuePair> toNameValuePairs(String nameValueObjJsonArray) throws Throwable {
if (StringUtil.isEmpty(nameValueObjJsonArray))
return Collections.EMPTY_LIST;
Object jsonObj = getObjectMapperNonStardand().readValue(nameValueObjJsonArray, Object.class);
if (jsonObj == null)
return Collections.EMPTY_LIST;
if (!(jsonObj instanceof Collection<?>))
return NOT_NAME_VALUE_PAIR_OBJ_ARRAY_JSON;
Collection<?> collection = (Collection<?>) jsonObj;
List<NameValuePair> nameValuePairs = new ArrayList<>(collection.size());
for (Object ele : collection) {
String name = null;
String value = null;
if (ele instanceof Map<?, ?>) {
Map<String, ?> eleMap = (Map<String, ?>) ele;
Object nameVal = eleMap.get("name");
Object valueVal = eleMap.get("value");
if (nameVal instanceof String) {
name = (String) nameVal;
if (valueVal != null)
value = (valueVal instanceof String ? (String) valueVal : valueVal.toString());
}
}
if (name == null)
return NOT_NAME_VALUE_PAIR_OBJ_ARRAY_JSON;
nameValuePairs.add(new BasicNameValuePair(name, value));
}
return nameValuePairs;
}
Aggregations