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:com.blackey.quickvolley.Request.JsonNetworkRequest.java

private static String urlBuilder(String url, List<NameValuePair> params) {
    return url + "?" + URLEncodedUtils.format(params, "UTF-8");
}

From source file:org.craftercms.social.util.UGCHttpClient.java

private HttpPost manageAttachments(String[] attachments, String ticket, String target, String textContent)
        throws UnsupportedEncodingException, URISyntaxException {
    List<NameValuePair> qparams = new ArrayList<NameValuePair>();
    qparams.add(new BasicNameValuePair("ticket", ticket));
    URI uri = URIUtils.createURI(scheme, host, port, appPath + "/api/2/ugc/" + "create.json",
            URLEncodedUtils.format(qparams, HTTP.UTF_8), null);
    HttpPost httppost = new HttpPost(uri);

    if (attachments.length > 0) {

        MultipartEntity me = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE);
        File file;//from   w  w w  .  j  a v  a2 s  .co m
        FileBody fileBody;
        for (String f : attachments) {
            file = new File(f);
            fileBody = new FileBody(file, "application/octect-stream");
            me.addPart("attachments", fileBody);
        }
        //File file = new File(attachments[0]);
        //FileBody fileBody = new FileBody(file, "application/octect-stream") ;
        //me.addPart("attachments", fileBody) ;
        me.addPart("target", new StringBody(target));
        me.addPart("textContent", new StringBody(textContent));

        httppost.setEntity(me);
    }
    return httppost;
}

From source file:org.apache.sling.hapi.client.forms.internal.FormValues.java

public String toString() {
    return URLEncodedUtils.format(list.flatten(), "UTF-8");
}

From source file:com.aselalee.trainschedule.GetResultsFromSiteV2.java

private void GetPriceViaJSON(String station_from, String station_to) {
    /**/*  w  ww.j  a  va  2 s . c o  m*/
     * Create name value pairs to be sent.
     */
    List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(3);
    nameValuePairs.add(new BasicNameValuePair("lang", "en"));
    nameValuePairs.add(new BasicNameValuePair("startStationID", station_from));
    nameValuePairs.add(new BasicNameValuePair("endStationID", station_to));
    String strParams = URLEncodedUtils.format(nameValuePairs, "utf-8");
    strParams = Constants.JSONURL_GETPRICE_V2 + "?" + strParams;
    String JSONStr = doJSONRequest(strParams);
    if (JSONStr == null) {
        prices = null;
        return;
    }
    if (JSONToPriceList(JSONStr) == false) {
        prices = null;
        return;
    }
}

From source file:org.wildfly.test.integration.elytron.rolemappers.AbstractRoleMapperTest.java

private URL prepareRolesPrintingURL(URL webAppURL) throws MalformedURLException {
    final List<NameValuePair> qparams = new ArrayList<NameValuePair>();
    for (final String role : allTestedRoles()) {
        qparams.add(new BasicNameValuePair(RolePrintingServlet.PARAM_ROLE_NAME, role));
    }//www  . j av a 2 s .  c  o  m
    String queryRoles = URLEncodedUtils.format(qparams, "UTF-8");
    return new URL(
            webAppURL.toExternalForm() + RolePrintingServlet.SERVLET_PATH.substring(1) + "?" + queryRoles);
}

From source file:com.bazaarvoice.seo.sdk.util.BVUtilty.java

public static String removeBVQuery(String queryUrl) {

    final URI uri;
    try {// ww  w  . jav a  2s  .  c  o  m
        uri = new URI(queryUrl);
    } catch (URISyntaxException e) {
        return queryUrl;
    }

    try {
        String newQuery = null;
        if (uri.getQuery() != null && uri.getQuery().length() > 0) {
            List<NameValuePair> newParameters = new ArrayList<NameValuePair>();
            List<NameValuePair> parameters = URLEncodedUtils.parse(uri.getQuery(), Charset.forName("UTF-8"));
            List<String> bvParameters = Arrays.asList("bvrrp", "bvsyp", "bvqap", "bvpage");
            for (NameValuePair parameter : parameters) {
                if (!bvParameters.contains(parameter.getName())) {
                    newParameters.add(parameter);
                }
            }
            newQuery = newParameters.size() > 0
                    ? URLEncodedUtils.format(newParameters, Charset.forName("UTF-8"))
                    : null;

        }
        return new URI(uri.getScheme(), uri.getAuthority(), uri.getPath(), newQuery, null).toString();
    } catch (URISyntaxException e) {
        return queryUrl;
    }
}

From source file:net.reichholf.dreamdroid.helpers.SimpleHttpClient.java

/**
 * @param uri/*  www. ja v a 2s .  com*/
 * @param parameters
 * @return
 */
public String buildFileStreamUrl(String uri, List<NameValuePair> parameters) {
    String parms = URLEncodedUtils.format(parameters, HTTP.UTF_8).replace("+", "%20");
    String fileAuthString = "";
    if (mProfile.isFileLogin())
        fileAuthString = mProfile.getUser() + ":" + mProfile.getPass() + "@";

    String url = mFilePrefix + fileAuthString + mProfile.getStreamHost() + ":" + mProfile.getFilePortString()
            + uri + parms;
    return url;
}

From source file:com.nexmo.sdk.core.client.Client.java

/**
 * Construct a Nexmo Url instance./*from   ww  w  .  j  a va  2  s  .  c om*/
 *
 * @param requestParams The necessary http params.
 * @param methodName The method name inside the API call.
 *
 * @throws MalformedURLException if an error occurs while opening the connection.
 */
private static URL constructUrlGetConnection(Map<String, String> requestParams, final String methodName,
        final String host) throws MalformedURLException {
    List<NameValuePair> getParams = new ArrayList<>();
    for (Map.Entry<String, String> entry : requestParams.entrySet()) {
        getParams.add(new BasicNameValuePair(entry.getKey(), entry.getValue()));
    }

    String paramString = URLEncodedUtils.format(getParams, HTTP.UTF_8);
    return new URL(host + methodName + paramString);
}

From source file:com.example.android.wearablemessageapiexample.MobileActivity.java

private MessageApi.MessageListener messageListenerFactory() {
    return new MessageApi.MessageListener() {
        @Override// www. ja v  a  2 s .c  o  m
        public void onMessageReceived(MessageEvent messageEvent) {
            if (messageEvent.getPath().equals(COMMAND_PATH)) {

                RobotCommand robotCommand = new RobotCommand(new String(messageEvent.getData()));
                command = robotCommand.getCommand();

                if (!command.isEmpty()) {
                    StringBuilder requestUrl = new StringBuilder(BASE_URL);
                    List<NameValuePair> params = new ArrayList<NameValuePair>();
                    params.add(new BasicNameValuePair("name", command));
                    params.add(new BasicNameValuePair("queue", "1"));
                    String queryString = URLEncodedUtils.format(params, "utf-8");
                    requestUrl.append("?");
                    requestUrl.append(queryString);
                    HttpClient httpclient = new DefaultHttpClient();
                    try {
                        httpclient.execute(new HttpGet(requestUrl.toString()));
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                } else {
                    //TODO: NO DETECTED COMMAND
                }
            }
        }
    };
}

From source file:io.servicecomb.core.transport.AbstractTransport.java

private String genAddressWithoutSchema(String addressWithoutSchema, Map<String, String> pairs) {
    if (addressWithoutSchema == null || pairs == null || pairs.isEmpty()) {
        return addressWithoutSchema;
    }/*  w  w  w.j  a va 2  s.  c  om*/

    int idx = addressWithoutSchema.indexOf('?');
    if (idx == -1) {
        addressWithoutSchema += "?";
    } else {
        addressWithoutSchema += "&";
    }

    String encodedQuery = URLEncodedUtils.format(pairs.entrySet().stream().map(entry -> {
        return new BasicNameValuePair(entry.getKey(), entry.getValue());
    }).collect(Collectors.toList()), StandardCharsets.UTF_8.name());

    if (!RegistryUtils.getServiceRegistry().getFeatures().isCanEncodeEndpoint()) {
        addressWithoutSchema = genAddressWithoutSchemaForOldSC(addressWithoutSchema, encodedQuery);
    } else {
        addressWithoutSchema += encodedQuery;
    }

    return addressWithoutSchema;
}