Search in sources :

Example 26 with NameValuePair

use of org.apache.hc.core5.http.copied.NameValuePair in project httpcomponents-core by apache.

the class BasicHeaderValueParser method parseParameters.

@Override
public NameValuePair[] parseParameters(final CharSequence buffer, final ParserCursor cursor) {
    Args.notNull(buffer, "Char sequence");
    Args.notNull(cursor, "Parser cursor");
    tokenizer.skipWhiteSpace(buffer, cursor);
    final List<NameValuePair> params = new ArrayList<>();
    while (!cursor.atEnd()) {
        final NameValuePair param = parseNameValuePair(buffer, cursor);
        params.add(param);
        final char ch = buffer.charAt(cursor.getPos() - 1);
        if (ch == ELEM_DELIMITER) {
            break;
        }
    }
    return params.toArray(EMPTY_NAME_VALUE_ARRAY);
}
Also used : NameValuePair(org.apache.hc.core5.http.NameValuePair) ArrayList(java.util.ArrayList)

Example 27 with NameValuePair

use of org.apache.hc.core5.http.copied.NameValuePair in project httpcomponents-core by apache.

the class BasicHeaderValueParser method parseHeaderElement.

@Override
public HeaderElement parseHeaderElement(final CharSequence buffer, final ParserCursor cursor) {
    Args.notNull(buffer, "Char sequence");
    Args.notNull(cursor, "Parser cursor");
    final NameValuePair nvp = parseNameValuePair(buffer, cursor);
    NameValuePair[] params = null;
    if (!cursor.atEnd()) {
        final char ch = buffer.charAt(cursor.getPos() - 1);
        if (ch != ELEM_DELIMITER) {
            params = parseParameters(buffer, cursor);
        }
    }
    return new BasicHeaderElement(nvp.getName(), nvp.getValue(), params);
}
Also used : NameValuePair(org.apache.hc.core5.http.NameValuePair)

Example 28 with NameValuePair

use of org.apache.hc.core5.http.copied.NameValuePair in project geo-platform by geosdi.

the class CatalogContextTest method setUp.

@Before
public void setUp() throws Exception {
    try {
        CloseableHttpClient client = HttpClients.createDefault();
        List<NameValuePair> qparams = new ArrayList<NameValuePair>();
        qparams.add(new BasicNameValuePair("SERVICE", "CSW"));
        qparams.add(new BasicNameValuePair("REQUEST", "GetCapabilities"));
        URI uri = new URIBuilder().setScheme("http").setHost(CSW_HOST).setPath(CSW_PATH).addParameters(qparams).build();
        HttpGet get = new HttpGet(uri);
        CloseableHttpResponse response = client.execute(get);
        this.entity = response.getEntity();
    } catch (URISyntaxException ex) {
        logger.error("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ " + ex.getMessage());
    } catch (ClientProtocolException ex) {
        logger.error("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ " + ex.getMessage());
    } catch (IOException ex) {
        logger.error("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ " + ex.getMessage());
    }
}
Also used : CloseableHttpClient(org.apache.hc.client5.http.impl.classic.CloseableHttpClient) BasicNameValuePair(org.apache.hc.core5.http.message.BasicNameValuePair) NameValuePair(org.apache.hc.core5.http.NameValuePair) BasicNameValuePair(org.apache.hc.core5.http.message.BasicNameValuePair) HttpGet(org.apache.hc.client5.http.classic.methods.HttpGet) ArrayList(java.util.ArrayList) CloseableHttpResponse(org.apache.hc.client5.http.impl.classic.CloseableHttpResponse) URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException) URI(java.net.URI) URIBuilder(org.apache.hc.core5.net.URIBuilder) ClientProtocolException(org.apache.hc.client5.http.ClientProtocolException) Before(org.junit.Before)

Example 29 with NameValuePair

use of org.apache.hc.core5.http.copied.NameValuePair in project spotify-web-api-java by spotify-web-api-java.

the class AbstractRequest method bodyParametersToJson.

public String bodyParametersToJson(List<NameValuePair> bodyParameters) {
    JsonObject jsonObject = new JsonObject();
    JsonElement jsonElement;
    for (NameValuePair nameValuePair : bodyParameters) {
        try {
            jsonElement = JsonParser.parseString(nameValuePair.getValue());
        } catch (JsonSyntaxException e) {
            jsonElement = new JsonPrimitive(nameValuePair.getValue());
        }
        jsonObject.add(nameValuePair.getName(), jsonElement);
    }
    return jsonObject.toString();
}
Also used : BasicNameValuePair(org.apache.hc.core5.http.message.BasicNameValuePair)

Example 30 with NameValuePair

use of org.apache.hc.core5.http.copied.NameValuePair in project spotify-web-api-java by spotify-web-api-java.

the class Assertions method assertHasBodyParameter.

public static <RT, T> void assertHasBodyParameter(IRequest<RT> request, String name, T value) {
    List<NameValuePair> bodyParameters = request.getBodyParameters();
    for (NameValuePair bodyParameter : bodyParameters) {
        if (bodyParameter.getName().equals(name) && bodyParameter.getValue().equals(String.valueOf(value))) {
            return;
        }
    }
    fail(String.format("Request \"%s\" does not contain form parameter \"%s\" with value \"%s\"", request.getClass().getSimpleName(), name, value));
}
Also used : NameValuePair(org.apache.hc.core5.http.NameValuePair)

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