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

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

Introduction

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

Prototype

public URIBuilder setPath(final String path) 

Source Link

Document

Sets URI path.

Usage

From source file:webrequester.AbstractWebRequest.java

protected URI buildURI() {
    try {/*from  w ww . j ava  2s . c o m*/
        URIBuilder uriB = new URIBuilder();
        uriB.setScheme(scheme).setHost(host);
        if (port > 0) {
            uriB.setPort(port);
        }

        uriB.setPath(path);
        for (NameValuePair pair : listParameters) {
            uriB.setParameter(pair.getName(), pair.getValue());
        }
        return uriB.build();
    } catch (URISyntaxException ex) {
        return null;
    }
}

From source file:org.apache.ambari.view.weather.CityResourceProvider.java

private Map<String, Object> getWeatherProperty(String city, String units) throws IOException {
    URIBuilder uriBuilder = new URIBuilder();
    uriBuilder.setScheme("http");
    uriBuilder.setHost("api.openweathermap.org");
    uriBuilder.setPath("/data/2.5/weather");
    uriBuilder.setParameter("q", city);
    uriBuilder.setParameter("units", units);

    String url = uriBuilder.toString();

    InputStream in = readFrom(url);
    try {//from   ww  w .  j  a  v  a 2 s  . com
        Type mapType = new TypeToken<Map<String, Object>>() {
        }.getType();
        Map<String, Object> results = new Gson().fromJson(IOUtils.toString(in, "UTF-8"), mapType);

        ArrayList list = (ArrayList) results.get("weather");
        if (list != null) {
            Map weather = (Map) list.get(0);
            results.put("weather", weather);
            results.put("icon_src", "http://openweathermap.org/img/w/" + weather.get("icon"));
        }
        return results;
    } finally {
        in.close();
    }
}

From source file:com.fredhopper.core.connector.index.upload.impl.RestPublishingStrategy.java

protected URI createUri(final String scheme, final String host, final Integer port, final String servername,
        final String path, final List<NameValuePair> params) {
    Preconditions.checkArgument(StringUtils.isNotBlank(scheme));
    Preconditions.checkArgument(StringUtils.isNotBlank(host));
    Preconditions.checkArgument(port != null);
    Preconditions.checkArgument(StringUtils.isNotBlank(servername));
    Preconditions.checkArgument(StringUtils.isNotBlank(path));

    final URIBuilder uriBuilder = new URIBuilder();
    uriBuilder.setScheme(scheme);/*w  w  w.  jav a2s .  co  m*/
    uriBuilder.setHost(host);
    uriBuilder.setPort(port.intValue());
    uriBuilder.setPath("/".concat(servername).concat(path));
    if (CollectionUtils.isNotEmpty(params)) {
        uriBuilder.setParameters(params);
    }
    try {
        return uriBuilder.build();
    } catch (final URISyntaxException ex) {
        throw new IllegalArgumentException(ex);
    }
}

From source file:org.apache.streams.riak.http.RiakHttpPersistWriter.java

@Override
public void write(StreamsDatum entry) {

    Objects.nonNull(client);/*from   ww  w  . j a v  a  2  s.  c o  m*/

    String id = null;
    String document;
    String bucket;
    String bucketType;
    String contentType;
    String charset;
    if (StringUtils.isNotBlank(entry.getId())) {
        id = entry.getId();
    }
    if (entry.getDocument() instanceof String) {
        document = (String) entry.getDocument();
    } else {
        try {
            document = MAPPER.writeValueAsString(entry.getDocument());
        } catch (Exception e) {
            LOGGER.warn("Exception", e);
            return;
        }
    }
    if (entry.getMetadata() != null && entry.getMetadata().containsKey("bucket")
            && entry.getMetadata().get("bucket") instanceof String
            && StringUtils.isNotBlank((String) entry.getMetadata().get("bucket"))) {
        bucket = (String) entry.getMetadata().get("bucket");
    } else {
        bucket = configuration.getDefaultBucket();
    }
    if (entry.getMetadata() != null && entry.getMetadata().containsKey("bucketType")
            && entry.getMetadata().get("bucketType") instanceof String
            && StringUtils.isNotBlank((String) entry.getMetadata().get("bucketType"))) {
        bucketType = (String) entry.getMetadata().get("bucketType");
    } else {
        bucketType = configuration.getDefaultBucketType();
    }
    if (entry.getMetadata() != null && entry.getMetadata().containsKey("charset")
            && entry.getMetadata().get("charset") instanceof String
            && StringUtils.isNotBlank((String) entry.getMetadata().get("charset"))) {
        charset = (String) entry.getMetadata().get("charset");
    } else {
        charset = configuration.getDefaultCharset();
    }
    if (entry.getMetadata() != null && entry.getMetadata().containsKey("contentType")
            && entry.getMetadata().get("contentType") instanceof String
            && StringUtils.isNotBlank((String) entry.getMetadata().get("contentType"))) {
        contentType = (String) entry.getMetadata().get("contentType");
    } else {
        contentType = configuration.getDefaultContentType();
    }

    URIBuilder uriBuilder = new URIBuilder(client.baseURI);
    if (bucket != null && StringUtils.isNotBlank(bucket)) {
        uriBuilder.setPath("/riak/" + bucket);
    }
    if (id != null && StringUtils.isNotBlank(id)) {
        uriBuilder.setPath("/riak/" + bucket + "/" + id);
    }

    URI uri;
    try {
        uri = uriBuilder.build();
    } catch (URISyntaxException e) {
        LOGGER.warn("URISyntaxException", e);
        return;
    }

    HttpPost post = new HttpPost();
    post.setHeader("Content-Type", contentType + "; charset=" + charset);
    post.setURI(uri);
    HttpEntity entity;
    try {
        entity = new StringEntity(document);
        post.setEntity(entity);
    } catch (UnsupportedEncodingException e) {
        LOGGER.warn("UnsupportedEncodingException", e);
        return;
    }

    try {
        HttpResponse response = client.client().execute(post);
    } catch (IOException e) {
        LOGGER.warn("IOException", e);
        return;
    }

}

From source file:org.mobicents.servlet.restcomm.provisioning.number.bandwidth.BandwidthNumberProvisioningManager.java

private String buildDisconnectsUri() throws URISyntaxException {
    URIBuilder builder = new URIBuilder(this.uri);
    builder.setPath("/v1.0/accounts/" + this.accountId + "/disconnects");
    return builder.build().toString();
}

From source file:org.mobicents.servlet.restcomm.provisioning.number.bandwidth.BandwidthNumberProvisioningManager.java

private String buildOrdersUri() throws URISyntaxException {
    URIBuilder builder = new URIBuilder(this.uri);
    builder.setPath("/v1.0/accounts/" + this.accountId + "/orders");
    return builder.build().toString();
}

From source file:org.n52.sos.service.it.SosITBase.java

/**
 * Get URI for the relative sos path and query using test host, port, and
 * basepath/*ww w. j a  va2s . c om*/
 * 
 * @param path
 *            The relative test endpoint
 * @param query
 *            Query parameters to add to the request
 * @return Constructed URI
 * @throws URISyntaxException
 */
protected URI getURI(String path, String query) throws URISyntaxException {
    URIBuilder b = new URIBuilder();
    b.setScheme("http");
    b.setHost(host);
    b.setPort(port);
    b.setPath(getPath(path));
    b.setQuery(query);
    b.setFragment(null);

    return b.build();
}

From source file:com.collective.celos.CelosClient.java

public void clearCache() throws Exception {
    URIBuilder uriBuilder = new URIBuilder(address);
    uriBuilder.setPath(uriBuilder.getPath() + CLEAR_CACHE_PATH);
    executePost(uriBuilder.build());/*from  w  w  w. ja va2s.  co  m*/
}

From source file:org.apache.streams.riak.http.RiakHttpPersistReader.java

@Override
public StreamsResultSet readAll() {

    Queue<StreamsDatum> readAllQueue = constructQueue();

    URIBuilder lk = null;

    try {// www  .  j  a v  a 2 s .  com

        lk = new URIBuilder(client.baseURI.toString());
        lk.setPath(client.baseURI.getPath().concat("/buckets/" + configuration.getDefaultBucket() + "/keys"));
        lk.setParameter("keys", "true");

    } catch (URISyntaxException e) {
        LOGGER.warn("URISyntaxException", e);
    }

    HttpResponse lkResponse = null;
    try {
        HttpGet lkGet = new HttpGet(lk.build());
        lkResponse = client.client().execute(lkGet);
    } catch (IOException e) {
        LOGGER.warn("IOException", e);
        return null;
    } catch (URISyntaxException e) {
        LOGGER.warn("URISyntaxException", e);
        return null;
    }

    String lkEntityString = null;
    try {
        lkEntityString = EntityUtils.toString(lkResponse.getEntity());
    } catch (IOException e) {
        LOGGER.warn("IOException", e);
        return null;
    }

    JsonNode lkEntityNode = null;
    try {
        lkEntityNode = MAPPER.readValue(lkEntityString, JsonNode.class);
    } catch (IOException e) {
        LOGGER.warn("IOException", e);
        return null;
    }

    ArrayNode keysArray = null;
    keysArray = (ArrayNode) lkEntityNode.get("keys");
    Iterator<JsonNode> keysIterator = keysArray.iterator();

    while (keysIterator.hasNext()) {
        JsonNode keyNode = keysIterator.next();
        String key = keyNode.asText();

        URIBuilder gk = null;

        try {

            gk = new URIBuilder(client.baseURI.toString());
            gk.setPath(client.baseURI.getPath()
                    .concat("/buckets/" + configuration.getDefaultBucket() + "/keys/" + key));

        } catch (URISyntaxException e) {
            LOGGER.warn("URISyntaxException", e);
            continue;
        }

        HttpResponse gkResponse = null;
        try {
            HttpGet gkGet = new HttpGet(gk.build());
            gkResponse = client.client().execute(gkGet);
        } catch (IOException e) {
            LOGGER.warn("IOException", e);
            continue;
        } catch (URISyntaxException e) {
            LOGGER.warn("URISyntaxException", e);
            continue;
        }

        String gkEntityString = null;
        try {
            gkEntityString = EntityUtils.toString(gkResponse.getEntity());
        } catch (IOException e) {
            LOGGER.warn("IOException", e);
            continue;
        }

        readAllQueue.add(new StreamsDatum(gkEntityString, key));
    }

    return new StreamsResultSet(readAllQueue);
}

From source file:com.collective.celos.CelosClient.java

public void rerunSlot(WorkflowID workflowID, ScheduledTime scheduledTime) throws Exception {
    URIBuilder uriBuilder = new URIBuilder(address);
    uriBuilder.setPath(uriBuilder.getPath() + RERUN_PATH);
    uriBuilder.addParameter(ID_PARAM, workflowID.toString());
    uriBuilder.addParameter(TIME_PARAM, scheduledTime.toString());
    executePost(uriBuilder.build());/*w  ww. j a  v  a2 s . com*/
}