Example usage for org.apache.http.client.utils URLEncodedUtils format

List of usage examples for org.apache.http.client.utils URLEncodedUtils format

Introduction

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

Prototype

public static String format(final Iterable<? extends NameValuePair> parameters, final Charset charset) 

Source Link

Document

Returns a String that is suitable for use as an application/x-www-form-urlencoded list of parameters in an HTTP PUT or HTTP POST.

Usage

From source file:org.kitodo.sruimport.SRUImport.java

private String createQueryParameterString(LinkedHashMap<String, String> searchFields) {
    List<BasicNameValuePair> nameValuePairList = searchFields.entrySet().stream()
            .map(entry -> new BasicNameValuePair(entry.getKey(), entry.getValue()))
            .collect(Collectors.toList());
    return URLEncodedUtils.format(nameValuePairList, StandardCharsets.UTF_8);
}

From source file:io.coala.capability.online.FluentHCOnlineCapability.java

public static HttpEntity toFormEntity(final List<NameValuePair> paramList) {
    final ContentType contentType = ContentType.create(URLEncodedUtils.CONTENT_TYPE, Consts.ISO_8859_1);
    final Charset charset = contentType != null ? contentType.getCharset() : null;
    final String s = URLEncodedUtils.format(paramList, charset != null ? charset.name() : null);
    byte[] raw;//from   w  w  w  . j  a va 2 s  . c  o  m
    try {
        raw = charset != null ? s.getBytes(charset.name()) : s.getBytes();
    } catch (UnsupportedEncodingException ex) {
        raw = s.getBytes();
    }
    return new ApacheInternalByteArrayEntity(raw, contentType);
}

From source file:io.gs2.stamina.Gs2StaminaClient.java

/**
 * ?????<br>//from   w  w  w. j a  va  2  s  . c o  m
 * <br>
 *
 * @param request 
        
 * @return ?
        
 */

public DescribeStaminaPoolResult describeStaminaPool(DescribeStaminaPoolRequest request) {

    String url = Gs2Constant.ENDPOINT_HOST + "/staminaPool";

    List<NameValuePair> queryString = new ArrayList<>();
    if (request.getPageToken() != null)
        queryString.add(new BasicNameValuePair("pageToken", String.valueOf(request.getPageToken())));
    if (request.getLimit() != null)
        queryString.add(new BasicNameValuePair("limit", String.valueOf(request.getLimit())));

    if (queryString.size() > 0) {
        url += "?" + URLEncodedUtils.format(queryString, "UTF-8");
    }
    HttpGet get = createHttpGet(url, credential, ENDPOINT, DescribeStaminaPoolRequest.Constant.MODULE,
            DescribeStaminaPoolRequest.Constant.FUNCTION);
    if (request.getRequestId() != null) {
        get.setHeader("X-GS2-REQUEST-ID", request.getRequestId());
    }

    return doRequest(get, DescribeStaminaPoolResult.class);

}

From source file:com.opendoorlogistics.studio.components.geocoder.SearchResultsPanel.java

private String getQueryString() {
    ArrayList<BasicNameValuePair> params = new ArrayList<>();
    params.add(new BasicNameValuePair("addressdetails", "1"));
    params.add(new BasicNameValuePair("limit", Integer.toString(NominatimConstants.RESULTS_LIMIT)));
    params.add(new BasicNameValuePair("format", "json"));
    params.add(new BasicNameValuePair("bounded", "0"));
    params.add(new BasicNameValuePair("q", model.getAddress()));

    // validate email...
    boolean okEmail = config.getEmail() != null;
    if (okEmail) {
        String email = Strings.std(config.getEmail());
        if (Strings.isEmailAddress(email)) {
            params.add(new BasicNameValuePair("email", config.getEmail()));
        } else {//from   ww w . j  a v  a2  s  .  com
            okEmail = false;
        }
    }

    if (!okEmail) {
        throw new RuntimeException("Invalid email address entered: " + config.getEmail());
    }

    Country country = (Country) countryCode.getSelectedItem();
    if (country != null && country != Controls.ALL_COUNTRIES) {
        params.add(new BasicNameValuePair("countrycodes", country.getTwoDigitCode()));
    }

    String formatted = URLEncodedUtils.format(params, (String) null);

    String server = (String) serverBox.getEditor().getItem();
    String uri = server + "?" + formatted;
    return uri;
}

From source file:org.wso2.carbon.appfactory.apiManager.integration.utils.Utils.java

public static HttpPost createHttpPostRequest(URL url, List<NameValuePair> params, String path)
        throws AppFactoryException {

    URI uri;//w w  w  .  j a va2s  . c o m
    try {
        uri = URIUtils.createURI(url.getProtocol(), url.getHost(), url.getPort(), path,
                URLEncodedUtils.format(params, "UTF-8"), null);
    } catch (URISyntaxException e) {
        String msg = "Invalid URL syntax";
        log.error(msg, e);
        throw new AppFactoryException(msg, e);
    }

    return new HttpPost(uri);
}

From source file:org.cogsurv.cogsurver.http.AbstractHttpApi.java

public HttpGet createHttpGet(String url, NameValuePair... nameValuePairs) {
    if (DEBUG)//from w ww. ja va  2  s  .  c  o  m
        LOG.log(Level.FINE, "creating HttpGet for: " + url);
    String query = URLEncodedUtils.format(stripNulls(nameValuePairs), HTTP.UTF_8);
    HttpGet httpGet = new HttpGet(url + "?" + query);
    httpGet.addHeader(CLIENT_VERSION_HEADER, mClientVersion);
    if (DEBUG)
        LOG.log(Level.FINE, "Created: " + httpGet.getURI());
    return httpGet;
}

From source file:com.data2semantics.yasgui.server.servlets.SparqlServlet.java

private HttpResponse executeGet(String endpoint, String accept, HttpClient client,
        List<NameValuePair> nameValuePairs) throws ClientProtocolException, IOException {
    if (!endpoint.endsWith("?")) {
        endpoint += "?";
    }/*from www.j  a v a  2s .c  om*/
    endpoint += URLEncodedUtils.format(nameValuePairs, "utf-8");
    HttpGet get = new HttpGet(endpoint);
    get.setHeader("Accept", accept);
    get.setHeader("Content-Type", "application/x-www-form-urlencoded");
    return client.execute(get);
}