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

/**
 * IP Login(03): IP/*from   ww w  . j  a v  a 2 s  . c  o m*/
 */
public ApiInvoker<IPLoginRet> IPLogin(String ip) {
    String[] paramNames = new String[] { "ip" };
    String[] paramValues = new String[] { "" + ip };
    String url = apiUrl.getIPLoginUrl();
    ApiDataParseHandler<IPLoginRet> handler = ApiDataParseHandler.IP_LOGIN_RET_PARSE_HANDLER;
    List<NameValuePair> nvps = createRequestParams(paramNames, paramValues, false);
    if (Logger.DEBUG) {
        L.d(url + "?" + URLEncodedUtils.format(nvps, "UTF-8"));
    }
    return new ApiInvoker<IPLoginRet>(this.config, handler, url, nvps);
}

From source file:com.hollowsoft.library.utility.request.HttpRequest.java

/**
 *
 * @param url/*from w  w  w. j av a  2  s. c o m*/
 * @param nameValuePairList
 * @param headerArray
 * @return
 * @throws RequestException
 */
public JsonNode doDelete(final String url, final List<NameValuePair> nameValuePairList,
        final Header... headerArray) throws RequestException {

    if (url == null || url.isEmpty()) {
        throw new IllegalArgumentException("The url cannot be null or empty.");
    }

    final String parameterString = URLEncodedUtils.format(nameValuePairList, Constants.DEFAULT_CHARSET.name());

    try {

        final HttpDelete httpDelete = new HttpDelete(url + "?" + parameterString);
        httpDelete.setHeaders(headerArray);

        final HttpEntity httpEntity = httpClient.execute(httpDelete).getEntity();

        return new ObjectMapper().reader().readTree(httpEntity.getContent());

    } catch (final ClientProtocolException e) {
        throw new RequestException(e);

    } catch (final JsonProcessingException e) {
        throw new RequestException(e);

    } catch (final IllegalStateException e) {
        throw new RequestException(e);

    } catch (final IOException e) {
        throw new RequestException(e);
    }
}

From source file:com.ab.http.RequestParams.java

/**
 * Gets the param string.
 *
 * @return the param string
 */
protected String getParamString() {
    return URLEncodedUtils.format(getParamsList(), HTTP.UTF_8);
}

From source file:org.opencastproject.series.remote.SeriesServiceRemoteImpl.java

/**
 * Builds the a series URL./*www .  j  a v  a  2 s. com*/
 * 
 * @param q
 *          the series query
 * @param admin
 *          whether this is for an administrative read
 * @return the series URL
 */
private String getSeriesUrl(SeriesQuery q) {
    StringBuilder url = new StringBuilder();
    url.append("/series.xml?");

    List<NameValuePair> queryStringParams = new ArrayList<NameValuePair>();
    if (q.getText() != null)
        queryStringParams.add(new BasicNameValuePair("q", q.getText()));
    if (q.getSeriesId() != null)
        queryStringParams.add(new BasicNameValuePair("seriesId", q.getSeriesId()));
    queryStringParams.add(new BasicNameValuePair("edit", Boolean.toString(q.isEdit())));
    if (q.getSeriesTitle() != null)
        queryStringParams.add(new BasicNameValuePair("seriesTitle", q.getSeriesTitle()));
    if (q.getCreator() != null)
        queryStringParams.add(new BasicNameValuePair("creator", q.getCreator()));
    if (q.getContributor() != null)
        queryStringParams.add(new BasicNameValuePair("contributor", q.getContributor()));
    if (q.getPublisher() != null)
        queryStringParams.add(new BasicNameValuePair("publisher", q.getPublisher()));
    if (q.getRightsHolder() != null)
        queryStringParams.add(new BasicNameValuePair("rightsholder", q.getRightsHolder()));
    if (q.getCreatedFrom() != null)
        queryStringParams
                .add(new BasicNameValuePair("createdfrom", SolrUtils.serializeDate(q.getCreatedFrom())));
    if (q.getCreatedTo() != null)
        queryStringParams.add(new BasicNameValuePair("createdto", SolrUtils.serializeDate(q.getCreatedTo())));
    if (q.getLanguage() != null)
        queryStringParams.add(new BasicNameValuePair("language", q.getLanguage()));
    if (q.getLicense() != null)
        queryStringParams.add(new BasicNameValuePair("license", q.getLicense()));
    if (q.getSubject() != null)
        queryStringParams.add(new BasicNameValuePair("subject", q.getSubject()));
    if (q.getAbstract() != null)
        queryStringParams.add(new BasicNameValuePair("abstract", q.getAbstract()));
    if (q.getDescription() != null)
        queryStringParams.add(new BasicNameValuePair("description", q.getDescription()));
    if (q.getSort() != null) {
        String sortString = q.getSort().toString();
        if (!q.isSortAscending())
            sortString = sortString.concat("_DESC");
        queryStringParams.add(new BasicNameValuePair("sort", sortString));
    }
    queryStringParams.add(new BasicNameValuePair("startPage", Long.toString(q.getStartPage())));
    queryStringParams.add(new BasicNameValuePair("count", Long.toString(q.getCount())));

    url.append(URLEncodedUtils.format(queryStringParams, "UTF-8"));
    return url.toString();
}

From source file:io.gs2.identifier.Gs2IdentifierClient.java

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

public DescribeUserResult describeUser(DescribeUserRequest request) {

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

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

    return doRequest(get, DescribeUserResult.class);

}

From source file:org.apache.hadoop.yarn.webapp.util.WebAppUtils.java

private static String getURLEncodedQueryString(HttpServletRequest request) {
    String queryString = request.getQueryString();
    if (queryString != null && !queryString.isEmpty()) {
        String reqEncoding = request.getCharacterEncoding();
        if (reqEncoding == null || reqEncoding.isEmpty()) {
            reqEncoding = "ISO-8859-1";
        }/*from ww  w.  ja  v  a2s  .c  om*/
        Charset encoding = Charset.forName(reqEncoding);
        List<NameValuePair> params = URLEncodedUtils.parse(queryString, encoding);
        return URLEncodedUtils.format(params, encoding);
    }
    return null;
}

From source file:org.ambraproject.wombat.service.remote.SolrSearchApiImpl.java

private URI getSolrUri(List<NameValuePair> params, Site site) throws SolrUndefinedException {
    SolrUndefinedException solrUndefinedException = new SolrUndefinedException(
            "Solr server URI must be defined in wombat.yaml in order to use solr features such "
                    + "as search, RSS, or listing recent articles on the homepage.");
    if (!runtimeConfiguration.getSolrConfiguration().isPresent()) {
        throw solrUndefinedException;
    }/*from  w  w w . j a  va  2 s  .c  o m*/
    try {
        URL solrServer = runtimeConfiguration.getSolrConfiguration().get().getUrl(site)
                .orElseThrow(() -> solrUndefinedException);
        return new URL(solrServer, "?" + URLEncodedUtils.format(params, "UTF-8")).toURI();
    } catch (MalformedURLException | URISyntaxException e) {
        //Solr server has already been validated - any exception here must be invalid values in params
        throw new IllegalArgumentException(e);
    }
}

From source file:org.opencastproject.workflow.remote.WorkflowServiceRemoteImpl.java

/**
 * {@inheritDoc}/*from ww w .  jav  a2 s  .  co  m*/
 * 
 * @see org.opencastproject.workflow.api.WorkflowService#countWorkflowInstances(org.opencastproject.workflow.api.WorkflowInstance.WorkflowState,
 *      java.lang.String)
 */
@Override
public long countWorkflowInstances(WorkflowState state, String operation) throws WorkflowDatabaseException {
    List<NameValuePair> queryStringParams = new ArrayList<NameValuePair>();
    if (state != null)
        queryStringParams.add(new BasicNameValuePair("state", state.toString()));
    if (operation != null)
        queryStringParams.add(new BasicNameValuePair("operation", operation));

    StringBuilder url = new StringBuilder("/count");
    if (queryStringParams.size() > 0) {
        url.append("?");
        url.append(URLEncodedUtils.format(queryStringParams, "UTF-8"));
    }

    HttpGet get = new HttpGet(url.toString());
    HttpResponse response = getResponse(get);
    try {
        if (response != null) {
            String body = null;
            try {
                body = EntityUtils.toString(response.getEntity());
                return Long.parseLong(body);
            } catch (NumberFormatException e) {
                throw new WorkflowDatabaseException("Unable to parse the response body as a long: " + body);
            }
        }
    } catch (ParseException e) {
        throw new WorkflowDatabaseException("Unable to parse the response body");
    } catch (IOException e) {
        throw new WorkflowDatabaseException("Unable to parse the response body");
    } finally {
        closeConnection(response);
    }

    throw new WorkflowDatabaseException("Unable to count workflow instances");
}

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

/**
 * Feature Applications(04): Feature Applications
 *///from ww w  .  jav a  2 s .c o  m
public ApiInvoker<AppsRet> featureApps(Integer appfilter) {
    String url = apiUrl.getFeatureAppsUrl();
    ApiDataParseHandler<AppsRet> handler = ApiDataParseHandler.APPS_RET_PARSE_HANDLER;
    List<NameValuePair> nvps = createRequestParams(null, null, true, appfilter);
    if (Logger.DEBUG) {
        L.d(url + "?" + URLEncodedUtils.format(nvps, "UTF-8"));
    }
    return new ApiInvoker<AppsRet>(this.config, handler, url, nvps);
}