Example usage for org.apache.http.client.utils URIBuilder addParameter

List of usage examples for org.apache.http.client.utils URIBuilder addParameter

Introduction

In this page you can find the example usage for org.apache.http.client.utils URIBuilder addParameter.

Prototype

public URIBuilder addParameter(final String param, final String value) 

Source Link

Document

Adds parameter to URI query.

Usage

From source file:org.wso2.identity.scenarios.commons.util.IdentityScenarioUtil.java

/**
 * Send GET request for a given URL with the request query parameters.
 *
 * @param client  HttpClient to be used for request sending.
 * @param url     Request URL./* w w w  .  j  av a  2s .  co m*/
 * @param params  Request query parameters.
 * @param headers Request headers.
 * @return HttpResponse containing the response.
 * @throws IOException        If error occurs while sending the request.
 * @throws URISyntaxException If error occurs while constructing the request URL.
 */
public static HttpResponse sendGetRequest(HttpClient client, String url, Map<String, String> params,
        Header[] headers) throws IOException, URISyntaxException {

    URIBuilder uriBuilder = new URIBuilder(url);
    if (params != null && !params.isEmpty()) {
        for (Map.Entry<String, String> entry : params.entrySet()) {
            uriBuilder.addParameter(entry.getKey(), entry.getValue());
        }
    }

    URI uri = uriBuilder.build();

    HttpGet getRequest = new HttpGet(uri);
    if (headers != null) {
        getRequest.setHeaders(headers);
    }

    return client.execute(getRequest);
}

From source file:synapticloop.b2.request.BaseB2Request.java

/**
 * Return the URI for this request, which adds any parameters found in the
 * 'parameters' data structure/*from  w w w  .j a v  a2 s.  c  o  m*/
 *
 * @return The URI for this request, with properly encoded parameters
 *
 * @throws IOException If there was an error building the URI
 */
protected URI buildUri() throws IOException {
    try {
        URIBuilder uriBuilder = new URIBuilder(url);

        for (final String key : requestParameters.keySet()) {
            uriBuilder.addParameter(key, requestParameters.get(key));
        }

        return uriBuilder.build();
    } catch (URISyntaxException e) {
        throw new IOException(e);
    }
}