Example usage for org.apache.http.client.utils URIBuilder addParameter

List of usage examples for org.apache.http.client.utils URIBuilder addParameter

Introduction

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

Prototype

public URIBuilder addParameter(final String param, final String value) 

Source Link

Document

Adds parameter to URI query.

Usage

From source file:com.kookoo.outbound.OutboundTest.java

public static void main(String a[]) {
    try {/*from  w ww.  j  a  v  a  2  s  .  co m*/
        String server_ip = "http://XXXX:8080"; /*change to your web server*/
        String phone_no1 = "09985XXXXX";/*change number to your numbers*/
        String phone_no2 = "09985XXXXX";/*change number to your numbers*/
        String api_key = "KKXXXXX";/*kookoo api key*/
        String kookoo_number = "91xxxxx";/*kookoo assigned number*/

        Date d = new Date();
        String trackId = "" + d.getTime();
        String url = "http://kookoo.in/outbound/outbound.php";
        URIBuilder uribuilder = new URIBuilder(url);
        uribuilder.addParameter("api_key", api_key);
        uribuilder.addParameter("phone_no", phone_no1);
        uribuilder.addParameter("caller_id", kookoo_number);
        /*assigned kookoo number*/
        uribuilder.addParameter("url",
                server_ip + "/kookoocall/outboundcall?number2=" + phone_no2 + "&trackId=" + trackId);
        uribuilder.addParameter("callback_url",
                server_ip + "/kookoocall/outbound_callstatus?number2=" + phone_no2 + "&trackId=" + trackId);

        URI uri = uribuilder.build();
        System.out.println("Final Outboud API url " + uri);
        HttpGet request = new HttpGet(uri);
        HttpClient client = HttpClientBuilder.create().build();
        HttpResponse response = client.execute(request);

        String responseString = new BasicResponseHandler().handleResponse(response);
        System.out.println(responseString);

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

}

From source file:com.vmware.identity.openidconnect.common.CommonUtils.java

public static String appendQueryParameter(URI uri, String parameterName, String parameterValue) {
    Validate.notNull(uri, "uri");
    Validate.notEmpty(parameterName, "parameterName");
    Validate.notEmpty(parameterValue, "parameterValue");

    String result;/*from  w  ww  .  ja v  a2s.co  m*/
    URIBuilder uriBuilder = new URIBuilder(uri);
    uriBuilder.addParameter(parameterName, parameterValue);
    try {
        result = uriBuilder.build().toString();
    } catch (URISyntaxException e) {
        String error = String.format("failed to add parameter [%s]=[%s] to uri [%s]", parameterName,
                parameterValue, uri);
        throw new IllegalArgumentException(error, e);
    }
    return result;
}

From source file:org.apache.sling.distribution.util.RequestUtils.java

public static URI appendDistributionRequest(URI uri, DistributionRequest distributionRequest)
        throws URISyntaxException {
    URIBuilder uriBuilder = new URIBuilder(uri);
    uriBuilder.addParameter(DistributionParameter.ACTION.toString(),
            distributionRequest.getRequestType().name());

    String[] paths = distributionRequest.getPaths();

    if (paths != null) {
        for (String path : paths) {
            uriBuilder.addParameter(DistributionParameter.PATH.toString(), path);
        }/*ww  w. j ava 2s.  c o m*/
    }

    return uriBuilder.build();
}

From source file:com.thoughtworks.go.util.UrlUtil.java

public static String urlWithQuery(String oldUrl, String paramName, String paramValue)
        throws URISyntaxException {
    URIBuilder uriBuilder = new URIBuilder(oldUrl);
    uriBuilder.addParameter(paramName, paramValue);
    return uriBuilder.toString();
}

From source file:org.fao.geonet.harvester.wfsfeatures.worker.OwsUtils.java

public static String getGetCapabilitiesUrl(final String wfsUrl, final String version) throws Exception {
    URIBuilder builder = new URIBuilder(wfsUrl);
    builder.addParameter("request", "GetCapabilities");
    builder.addParameter("service", "WFS");
    builder.addParameter("version", version);

    String url = builder.build().toURL().toString();
    return url;/*from  ww w.  ja v  a2  s  .com*/
}

From source file:com.appdirect.sdk.support.HttpClientHelper.java

public static HttpGet get(String endpoint, String... params) throws URISyntaxException {
    if (params.length % 2 != 0) {
        throw new IllegalArgumentException("pass params in name=value form");
    }/*w w  w .  j a v a2s. co m*/

    URIBuilder builder = new URIBuilder(endpoint);
    for (int i = 0; i < params.length; i = i + 2) {
        builder.addParameter(params[i], params[i + 1]).build();
    }
    return new HttpGet(builder.build());
}

From source file:com.infullmobile.jenkins.plugin.restrictedregister.util.AppUrls.java

@Nonnull
public static String buildActivationUrl(String code, String secret) throws InvalidUriException {
    String ret = null;//from  w w w .ja  v a  2  s . c  om
    final String path = String.format(Locale.US, FORMAT_REGISTER_PATH,
            PluginModule.getDefault().getPluginDescriptor().getRootActionURL());
    try {
        final URIBuilder builder = new URIBuilder(getRootURL());
        builder.setPath(path);
        builder.addParameter(BaseFormField.SECRET.getFieldName(), secret);
        builder.addParameter(BaseFormField.ACTIVATION_CODE.getFieldName(), code);
        final URI uri = builder.build();
        ret = uri.toURL().toExternalForm();
    } catch (URISyntaxException | MalformedURLException e) {
        onError(e.getLocalizedMessage());
    }
    return ret;
}

From source file:com.gsma.mobileconnect.utils.HttpUtils.java

/**
 * Add a boolean parameter to the URI.//from ww w  . ja v  a 2 s .  c o  m
 * <p>
 * Adds the string value of the boolean value to the URI.
 *
 * @param uri The URI to add the parameter to.
 * @param parameterName The name of the parameter to add.
 * @param value The value of the parameter to add.
 */
public static void addParameter(URIBuilder uri, String parameterName, boolean value) {
    uri.addParameter(parameterName, String.valueOf(value));
}

From source file:com.gsma.mobileconnect.utils.HttpUtils.java

/**
 * Add the string value of the value as a parameter to the URI.
 * <p>/*from w  w  w.  ja va 2  s.c om*/
 * If the value is null then no parameter is added.
 *
 * @param uri The URI to add the parameter to.
 * @param parameterName The name of the parameter to add.
 * @param value The value of the parameter to add.
 */
public static void addParameter(URIBuilder uri, String parameterName, Object value) {
    if (null != value) {
        uri.addParameter(parameterName, String.valueOf(value));
    }
}

From source file:ch.newscron.shortUrlUtils.ShortenerURL.java

/**
 * Given a shortened goo.gl URL, the function makes a request to the Google API (with key), receives information as a response in JSONObject format and stores data into a ShortLinkStat object.
 * @param shortURL is a String representing the shortened goo.gl URL
 * @return a ShortLinkStat object consisting of the most important information (clicks, long and short URL)
 *//*from ww w .j  ava 2  s. c  om*/
public static ShortLinkStat getURLJSONObject(String shortURL) {
    ShortLinkStat linkStat;

    try {
        // Creating the URL with Google API
        URIBuilder urlData = new URIBuilder(google_url);
        urlData.addParameter("shortUrl", shortURL);
        urlData.addParameter("projection", "FULL");
        URL url = urlData.build().toURL();

        // Get the JSONObject format of shortURL as String
        ObjectMapper mapper = new ObjectMapper();
        JsonNode rootNode = mapper.readTree(url);
        if (rootNode == null) {
            return null;
        }

        linkStat = setData(rootNode);
        return linkStat;

    } catch (Exception e) {
    }

    return null;
}