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:tw.com.sti.store.api.android.AndroidApiService.java

/**
 * Applications of Category(06): ??/*ww  w.j  a v a2 s . c  o  m*/
 */
public ApiInvoker<CategoryAppsRet> categoryApps(String categoryId, AppsType appsType, Integer appfilter,
        int page, Integer pSize) {
    String url = apiUrl.getCategoryAppsUrl(categoryId, appsType, page);
    ApiDataParseHandler<CategoryAppsRet> handler = ApiDataParseHandler.CATEGORY_APPS_RET_PARSE_HANDLER;
    String[] paramNames = null;
    String[] paramValues = null;
    if (pSize != null) {
        paramNames = new String[] { "psize" };
        paramValues = new String[] { pSize.toString() };
    }
    List<NameValuePair> nvps = createRequestParams(paramNames, paramValues, true, appfilter);
    if (Logger.DEBUG) {
        L.d(url + "?" + URLEncodedUtils.format(nvps, "UTF-8"));
    }
    return new ApiInvoker<CategoryAppsRet>(this.config, handler, url, nvps);
}

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

/**
 * ????<br>//w  w  w  .  j  a  v  a2s .  com
 * <br>
 *
 * @param request 
        
 * @return ?
        
 */

public GetRankingResult getRanking(GetRankingRequest request) {

    String url = Gs2Constant.ENDPOINT_HOST + "/ranking/"
            + (request.getRankingTableName() == null || request.getRankingTableName().equals("") ? "null"
                    : request.getRankingTableName())
            + "/mode/" + (request.getGameMode() == null || request.getGameMode().equals("") ? "null"
                    : request.getGameMode())
            + "/ranking";

    List<NameValuePair> queryString = new ArrayList<>();
    if (request.getOffset() != null)
        queryString.add(new BasicNameValuePair("offset", String.valueOf(request.getOffset())));
    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, GetRankingRequest.Constant.MODULE,
            GetRankingRequest.Constant.FUNCTION);
    if (request.getRequestId() != null) {
        get.setHeader("X-GS2-REQUEST-ID", request.getRequestId());
    }

    return doRequest(get, GetRankingResult.class);

}

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

/**
 * Retrieve a collection of documents, given their ids.
 * @param ids      ids of the documents/*from  www .  j  a v  a2 s.c o m*/
 * @param params   view API params
 * @return if params contain include_docs:true, a list of the full documents; otherwise each Document in the result
 * list contains an id and rev only. Ids that weren't found are ignored, so the result's size may be smaller than
 * the input ids'.
 * @see <a href="http://wiki.apache.org/couchdb/HTTP_Bulk_Document_API#Fetch_Multiple_Documents_With_a_Single_Request">
 * CouchDB Wiki for more information on valid parameters</a>
  * @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.
 */
public ArrayList<Document> getDocuments(Collection<String> ids, List<NameValuePair> params)
        throws IOException, URISyntaxException, CouchDBException {
    // build a json document with the requested document ids
    ObjectNode root = JsonNodeFactory.instance.objectNode();
    ArrayNode keys = root.putArray("keys");
    for (String id : ids)
        keys.add(id);
    String data = JsonUtils.serializeJson(root);
    String query = (params == null) ? null : URLEncodedUtils.format(params, "utf-8");
    JsonNode json = server.getHttpClient().post(URITemplates.allDocs(this, query), data);
    return parseDocuments(json);
}

From source file:com.ibm.ws.lars.rest.RepositoryContext.java

protected Attachment doPostAttachmentNoContent(String assetId, String name, Attachment attachment)
        throws ClientProtocolException, IOException, InvalidJsonAssetException {
    List<NameValuePair> qparams = new ArrayList<>();
    qparams.add(new BasicNameValuePair("name", name));
    String url = "/assets/" + assetId + "/attachments?" + URLEncodedUtils.format(qparams, "UTF-8");

    String response = doPost(url, attachment.toJson(), 200);

    Attachment createdAttachment = Attachment.jsonToAttachment(response);

    return createdAttachment;
}

From source file:org.craftercms.social.UCGRestServicesTest.java

public static void main(String[] args) throws Exception {

    ProfileClient profileRestClient = new ProfileRestClientImpl();

    String token = profileRestClient.getAppToken("craftersocial", "craftersocial");
    Tenant tenant = profileRestClient.getTenantByName(token, "testing");
    String ticket = profileRestClient.getTicket(token, "admin", "admin", tenant.getId());
    List<NameValuePair> qparams = new ArrayList<NameValuePair>();
    qparams.add(new BasicNameValuePair("ticket", ticket));
    qparams.add(new BasicNameValuePair("target", "testing"));

    qparams.add(new BasicNameValuePair("textContent", "Content"));

    URI uri = URIUtils.createURI("http", "localhost", 8080, "crafter-social/api/1/ugc/" + "create.json",
            URLEncodedUtils.format(qparams, HTTP.UTF_8), null);

    HttpClient httpclient = new DefaultHttpClient();
    HttpPost httppost = new HttpPost(uri);
    File file = new File(
            "/Users/alvarogonzalez/development/projects/crafter-social/rest/src/test/resources/test.txt");
    MultipartEntity me = new MultipartEntity();

    //The usual form parameters can be added this way
    //me.addPart("fileDescription", new StringBody(fileDescription != null ? fileDescription : "")) ;
    //multiPartEntity.addPart("fileName", new StringBody(fileName != null ? fileName : file.getName())) ;

    /*Need to construct a FileBody with the file that needs to be attached and specify the mime type of the file. Add the fileBody to the request as an another part.
    This part will be considered as file part and the rest of them as usual form-data parts*/
    FileBody fileBody = new FileBody(file, "application/octect-stream");
    //me.addPart("ticket", new StringBody(token)) ;
    //me.addPart("target", new StringBody("my-test")) ;
    me.addPart("attachments", fileBody);

    httppost.setEntity(me);//from  w  w  w .java 2s.co  m
    httpclient.execute(httppost);

}

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

@Override
public DetailledItem getResultById(String id, String homebranch) throws IOException {

    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"));
    params.add(new BasicNameValuePair("no", id));

    String html = httpGet(opac_url + "/APS_PRESENT_BIB?" + URLEncodedUtils.format(params, "UTF-8"),
            getDefaultEncoding());//from   w  w  w  . j  a  v a  2 s. c o  m

    return parse_result(id, html);
}

From source file:com.mobeelizer.java.connection.MobeelizerConnectionServiceImpl.java

private String createQuery(final String[] params) {
    if (params.length > 0) {
        List<NameValuePair> qparams = new ArrayList<NameValuePair>();
        for (int i = 0; i < params.length; i += 2) {
            qparams.add(new BasicNameValuePair(params[i], params[i + 1]));
        }/*from  w ww  .  ja  v  a 2  s  .  c  o m*/
        return "?" + URLEncodedUtils.format(qparams, "UTF-8");
    } else {
        return "";
    }
}

From source file:tw.com.sti.store.api.android.AndroidApiService.java

/**
 * Application Detail(07): ?//from   ww w. j av  a2s  .  c o  m
 */
public ApiInvoker<ApplicationRet> application(String packageName) {
    String url = apiUrl.getApplicationDetailUrl(packageName);
    ApiDataParseHandler<ApplicationRet> handler = ApiDataParseHandler.APPLICATION_PARSE_HANDLER;
    List<NameValuePair> nvps = createRequestParams();
    if (Logger.DEBUG) {
        L.d(url + "?" + URLEncodedUtils.format(nvps, "UTF-8"));
    }
    return new ApiInvoker<ApplicationRet>(this.config, handler, url, nvps);
}

From source file:com.gs.tools.doc.extractor.core.util.HttpUtility.java

public static byte[] readFileFromPOST(String sourceUrl, Map<String, String> reqParams) throws IOException {
    HttpClient httpClient = null;/*from   w ww  . j  a va  2  s .  c o m*/
    try {
        httpClient = getDefaultHttpClient();
        HttpPost httpRequest = new HttpPost(sourceUrl);
        if (null != reqParams && reqParams.size() > 0) {
            List<NameValuePair> paramList = new ArrayList<NameValuePair>();
            for (String param : reqParams.keySet()) {
                paramList.add(new BasicNameValuePair(param, reqParams.get(param)));
            }
            StringEntity reqEntity = new StringEntity(URLEncodedUtils.format(paramList, "UTF-8"), "UTF-8");
            httpRequest.setEntity(reqEntity);
        }

        HttpResponse response = httpClient.execute(httpRequest);

        return readResponseContent(response);
    } finally {
        if (null != httpClient)
            httpClient.getConnectionManager().shutdown();
    }
}