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:lynxtools.async_download.RequestParams.java

protected String getParamString() {
    if (jsonObjectParam != null) {
        return "";//"?" + jsonObjectParam.toString(); gotta figure how to do this, if its possible
    } else {/* w w  w.  j a v  a 2 s  . com*/
        return "?" + URLEncodedUtils.format(getParamsList(), ENCODING);
    }
}

From source file:io.stallion.plugins.flatBlog.comments.Comment.java

public String permalinkWithParams(Map<String, String> params) {
    List<BasicNameValuePair> pairs = list();
    for (Map.Entry<String, String> entry : params.entrySet()) {
        pairs.add(new BasicNameValuePair(entry.getKey(), entry.getValue()));
    }//from   w  w  w. ja  v  a  2  s.  c  o  m
    return permalinkWithQuery(URLEncodedUtils.format(pairs, "UTF-8"));
}

From source file:com.github.feribg.audiogetter.helpers.Utils.java

/**
 * Prepare a valid Youtube API request URI
 * @param query/*from  w  ww.j  av  a2  s  . c om*/
 * @param pageToken
 * @return
 * @throws URISyntaxException
 */
public static URI getYoutubeSearchURI(String query, String pageToken) throws URISyntaxException {
    List<NameValuePair> qparams = new ArrayList<NameValuePair>();
    qparams.add(new BasicNameValuePair("q", query));
    //if there is a specific page to load
    if (pageToken != null && pageToken.length() > 0) {
        qparams.add(new BasicNameValuePair("pageToken", pageToken));
    }
    qparams.add(new BasicNameValuePair("part", "snippet,id"));
    qparams.add(new BasicNameValuePair("maxResults", String.valueOf(Constants.Youtube.PER_PAGE)));
    qparams.add(new BasicNameValuePair("safeSearch", Constants.Youtube.SAFE_SEARCH));
    qparams.add(new BasicNameValuePair("type", Constants.Youtube.TYPE));
    qparams.add(new BasicNameValuePair("key", Constants.Youtube.API_TOKEN));
    return URIUtils.createURI(Constants.Youtube.API_SCHEME, Constants.Youtube.API_HOST, -1,
            Constants.Youtube.API_SEARCH, URLEncodedUtils.format(qparams, "UTF-8"), null);
}

From source file:org.carrot2.workbench.vis.FlashViewPage.java

/**
 * Construct a HTTP GET. /*from   w ww .  jav a2s . c  o  m*/
 */
private String createGetURI(String uriString, Map<String, Object> customParams) {
    try {
        List<NameValuePair> pairs = Lists.newArrayList();
        for (Map.Entry<String, Object> e : customParams.entrySet()) {
            pairs.add(new BasicNameValuePair(e.getKey(), e.getValue().toString()));
        }

        URI uri = new URI(uriString);
        uri = URIUtils.createURI(uri.getScheme(), uri.getHost(), uri.getPort(), uri.getPath(),
                URLEncodedUtils.format(pairs, "UTF-8"), null);

        return uri.toString();
    } catch (URISyntaxException e) {
        throw new RuntimeException(e);
    }
}

From source file:com.suning.mobile.ebuy.lottery.network.util.Caller.java

/**
 * /*from   www  .ja va2  s  .com*/
 * @Description:get
 * @Author 12120153
 * @Date 2013-1-3
 */
public String getEbuy(String url, List<NameValuePair> list, String action) {
    LogUtil.e("url:" + url + action + "?" + URLEncodedUtils.format(list, LotteryApiConfig.ENCODE));
    HttpGet request = new HttpGet(url + action + "?" + URLEncodedUtils.format(list, LotteryApiConfig.ENCODE));
    request.addHeader("Accept-Encoding", "gzip");
    request.addHeader("User-Agent", "Mozilla/5.0 (iPhone; U; CPU iPhone OS 3_0 like Mac OS X; en-us) "
            + "AppleWebKit/528.18 (KHTML, like Gecko) Version/4.0 Mobile/7A341 Safari/528.16");

    String result = "";
    try {
        result = mClient.execute(request, responseHandler);
    } catch (NullPointerException e) {
        LogUtil.logException(e);
        result = "";
    } catch (ClientProtocolException e) {
        LogUtil.logException(e);
        result = "";
    } catch (IOException e) {
        LogUtil.logException(e);
        result = "";
    } catch (Exception e) {
        LogUtil.logException(e);
        result = "";
    }
    if (null == result) {
        result = "";
    }
    return result;
}

From source file:de.geeksfactory.opacclient.apis.Zones.java

@Override
public SearchRequestResult searchGetPage(int page) throws IOException, OpacErrorException {
    List<NameValuePair> params = new ArrayList<>();

    params.add(new BasicNameValuePair("Style", version18 ? "Portal2" : "Portal3"));
    params.add(new BasicNameValuePair("SubStyle", ""));
    params.add(new BasicNameValuePair("Lang", "GER"));
    params.add(new BasicNameValuePair("ResponseEncoding", "utf-8"));
    if (page > this.page) {
        params.add(new BasicNameValuePair("Method", version18 ? "FetchIncrementalBrowseDown" : "PageDown"));
    } else {//from   ww w .  ja v  a  2  s.c o m
        params.add(new BasicNameValuePair("Method", version18 ? "FetchIncrementalBrowseUp" : "PageUp"));
    }
    params.add(new BasicNameValuePair("PageSize", "10"));

    String html = httpGet(opac_url + "/" + searchobj + "?" + URLEncodedUtils.format(params, "UTF-8"),
            getDefaultEncoding());
    this.page = page;

    return parse_search(html, page);
}

From source file:iristk.speech.nuancecloud.NuanceCloudRecognizerListener.java

private void initRequest() {
    try {//from  w ww.  ja va2 s.c  om
        speechQueue.reset();

        InputStream inputStream;
        String codec;

        if (!(audioFormat.getSampleRate() == 8000 || audioFormat.getSampleRate() == 16000)) {
            System.err.println("Error: NuanceCloudRecognizer must get 8 or 16 Khz audio, not "
                    + audioFormat.getSampleRate());
        }

        if (useSpeex) {
            encodedQueue.reset();
            JSpeexEnc encoder = new JSpeexEnc((int) audioFormat.getSampleRate());
            encoder.startEncoding(speechQueue, encodedQueue);
            inputStream = encodedQueue.getInputStream();
            codec = "audio/x-speex;rate=" + (int) audioFormat.getSampleRate();
        } else {
            inputStream = speechQueue.getInputStream();
            codec = "audio/x-wav;codec=pcm;bit=16;rate=" + (int) audioFormat.getSampleRate();
        }

        List<NameValuePair> qparams = new ArrayList<NameValuePair>();
        qparams.add(new BasicNameValuePair("appId", license.getAppId()));
        qparams.add(new BasicNameValuePair("appKey", license.getAppKey()));
        qparams.add(new BasicNameValuePair("id", DEVICE_ID));
        URI uri = URIUtils.createURI("https", HOSTNAME, 443, SERVLET, URLEncodedUtils.format(qparams, "UTF-8"),
                null);
        final HttpPost httppost = new HttpPost(uri);
        httppost.addHeader("Content-Type", codec);
        httppost.addHeader("Content-Language", language);
        httppost.addHeader("Accept-Language", language);
        httppost.addHeader("Accept", RESULTS_FORMAT);
        httppost.addHeader("Accept-Topic", LM);
        if (nuanceAudioSource != null) {
            httppost.addHeader("X-Dictation-AudioSource", nuanceAudioSource.name());
        }
        if (cookie != null)
            httppost.addHeader("Cookie", cookie);

        InputStreamEntity reqEntity = new InputStreamEntity(inputStream, -1);
        reqEntity.setContentType(codec);

        httppost.setEntity(reqEntity);

        postThread = new PostThread(httppost);

    } catch (URISyntaxException e) {
        e.printStackTrace();
    }
}

From source file:org.maikelwever.droidpile.backend.ApiConnecter.java

public ApiSearchResponse search(int start, int end, String query) throws IOException, JSONException {
    ArrayList<MailpileMessage> list = new ArrayList<MailpileMessage>();
    int totalItemCount = 0;
    ArrayList<NameValuePair> args = new ArrayList<NameValuePair>();
    args.add(new BasicNameValuePair("q", query));
    args.add(new BasicNameValuePair("start", Integer.toString(start)));
    args.add(new BasicNameValuePair("end", Integer.toString(end)));

    String data = this.getData("search", "?" + URLEncodedUtils.format(args, ENCODING));
    JSONObject result = new JSONObject(data).getJSONObject("result");
    JSONArray threadIds = result.getJSONArray("thread_ids");
    JSONObject metadata = result.getJSONObject("data").getJSONObject("metadata");

    totalItemCount = result.getJSONObject("stats").getInt("total");

    for (int i = 0; i < threadIds.length(); i++) {
        String threadid = threadIds.getString(i);
        JSONObject message = metadata.getJSONObject(threadid);
        if (message != null) {
            list.add(parseJsonIntoMessage(message, threadid));
        }/*from ww w  .ja va2  s.  co  m*/
    }

    return new ApiSearchResponse(list, totalItemCount);
}

From source file:io.gs2.ranking.Gs2RankingClient.java

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

public DescribeRankingTableResult describeRankingTable(DescribeRankingTableRequest request) {

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

    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, DescribeRankingTableRequest.Constant.MODULE,
            DescribeRankingTableRequest.Constant.FUNCTION);
    if (request.getRequestId() != null) {
        get.setHeader("X-GS2-REQUEST-ID", request.getRequestId());
    }

    return doRequest(get, DescribeRankingTableResult.class);

}

From source file:com.jzboy.couchdb.Database.java

/**
 * Returns a list of changes made to documents in the database.
 * This method doesn't support the 'continuous' option and throws an exception if it is
 * present in the params map.//  w  w w. j av  a2  s.c om
 * @param params   parameters for the Changes API call. Keys are parameter names, mapped
 * to the string representation of the value, which is copied as-is to the JSON sent to
 * CouchDB. It is OK to pass either null or an empty map.
 * @return   the list of changes, where each change is a JSON
  * @throws IOException         if the HttpClient throws an IOException
 * @throws URISyntaxException   if there was a problem constructing a URI for this database
 * @throws CouchDBException      if CouchDB returns an error - response code >= 300. The response
 * details are encapsulated in the exception.
 * @see <a href="http://wiki.apache.org/couchdb/HTTP_database_API#Changes">
 * CouchDB Wiki for a description of the possible parameters</a>
 */
public ArrayList<JsonNode> changes(List<NameValuePair> params)
        throws IOException, URISyntaxException, CouchDBException {
    if (params.contains(new BasicNameValuePair("continuous", "true")))
        throw new CouchDBException("'continuous' feeds are not supported by this method");

    JsonNode res = server.getHttpClient()
            .get(URITemplates.dbChanges(this, URLEncodedUtils.format(params, "utf-8")));
    ArrayList<JsonNode> results = new ArrayList<JsonNode>();
    for (JsonNode row : res.get("results"))
        results.add(row);
    return results;
}