Search in sources :

Example 61 with NameValuePair

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);
}
Also used : NameValuePair(org.apache.hc.core5.http.NameValuePair) BasicNameValuePair(org.apache.hc.core5.http.message.BasicNameValuePair) URI(java.net.URI) Test(org.junit.jupiter.api.Test)

Example 62 with NameValuePair

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;
}
Also used : HttpPost(org.apache.hc.client5.http.classic.methods.HttpPost) NameValuePair(org.apache.hc.core5.http.NameValuePair) BasicNameValuePair(org.apache.hc.core5.http.message.BasicNameValuePair) BasicNameValuePair(org.apache.hc.core5.http.message.BasicNameValuePair) ArrayList(java.util.ArrayList) UrlEncodedFormEntity(org.apache.hc.client5.http.entity.UrlEncodedFormEntity)

Example 63 with NameValuePair

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);
}
Also used : NameValuePair(org.apache.hc.core5.http.NameValuePair) ToString(lombok.ToString) URI(java.net.URI) HashMap(java.util.HashMap) Map(java.util.Map)

Example 64 with NameValuePair

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;
}
Also used : BasicNameValuePair(org.apache.hc.core5.http.message.BasicNameValuePair) NameValuePair(org.apache.hc.core5.http.NameValuePair) BasicNameValuePair(org.apache.hc.core5.http.message.BasicNameValuePair) ArrayList(java.util.ArrayList) Collection(java.util.Collection) Map(java.util.Map)

Aggregations

NameValuePair (org.apache.hc.core5.http.NameValuePair)56 Test (org.junit.jupiter.api.Test)26 BasicNameValuePair (org.apache.hc.core5.http.message.BasicNameValuePair)25 ArrayList (java.util.ArrayList)15 URI (java.net.URI)13 UrlEncodedFormEntity (org.apache.hc.client5.http.entity.UrlEncodedFormEntity)12 HttpPost (org.apache.hc.client5.http.classic.methods.HttpPost)11 Map (java.util.Map)10 CharArrayBuffer (org.apache.hc.core5.util.CharArrayBuffer)9 IOException (java.io.IOException)7 CloseableHttpResponse (org.apache.hc.client5.http.impl.classic.CloseableHttpResponse)7 URIBuilder (org.apache.hc.core5.net.URIBuilder)7 URISyntaxException (java.net.URISyntaxException)6 HashMap (java.util.HashMap)5 HeaderElement (org.apache.hc.core5.http.HeaderElement)5 HttpGet (org.apache.hc.client5.http.classic.methods.HttpGet)4 BasicHeader (org.apache.hc.core5.http.message.BasicHeader)4 List (java.util.List)3 CloseableHttpClient (org.apache.hc.client5.http.impl.classic.CloseableHttpClient)3 HttpEntity (org.apache.hc.core5.http.HttpEntity)3