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

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

Introduction

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

Prototype

public URIBuilder(final URI uri) 

Source Link

Document

Construct an instance from the provided URI.

Usage

From source file:com.kurtraschke.ctatt.gtfsrealtime.services.TrainTrackerDataService.java

public Positions fetchAllTrains(List<String> routes)
        throws MalformedURLException, IOException, TrainTrackerDataException, URISyntaxException {
    URIBuilder b = new URIBuilder("http://lapi.transitchicago.com/api/1.0/ttpositions.aspx");
    b.addParameter("key", _trainTrackerKey);
    b.addParameter("rt", Joiner.on(',').join(routes));

    CloseableHttpClient client = HttpClients.custom().setConnectionManager(_connectionManager).build();

    HttpGet httpget = new HttpGet(b.build());
    try (CloseableHttpResponse response = client.execute(httpget)) {
        HttpEntity entity = response.getEntity();
        Positions p = _xmlMapper.readValue(entity.getContent(), Positions.class);

        if (p.errorCode != 0) {
            throw new TrainTrackerDataException(p.errorCode, p.errorName);
        }//  ww w .  j a  v a2  s .c o m

        return p;
    }
}

From source file:com.ritesh.idea.plugin.util.HttpRequestBuilder.java

public static HttpRequestBuilder get(String url) throws URISyntaxException {
    HttpRequestBuilder builder = new HttpRequestBuilder();
    builder.urlBuilder = new URIBuilder(url);
    builder.request = new HttpGet();
    return builder;
}

From source file:integration.webhose.WebhoseIOClient.java

public JsonElement query(String endpoint, Map<String, String> queries) throws URISyntaxException, IOException {
    try {/* w w  w  .ja va2  s .  co m*/
        URIBuilder builder = new URIBuilder(
                String.format("%s/%s?token=%s&format=json", WEBHOSE_BASE_URL, endpoint, mApiKey));
        for (String key : queries.keySet()) {
            builder.addParameter(key, queries.get(key));
        }

        return getResponse(builder.toString());
    } catch (Exception e) {
        //e.printStackTrace();
        throw e;
    }
    //return null;
}

From source file:org.apache.tika.parser.geo.topic.gazetteer.GeoGazetteerClient.java

/**
 * Calls API of lucene-geo-gazetteer to search location name in gazetteer.
 * @param locations List of locations to be searched in gazetteer
 * @return Map of input location strings to gazetteer locations
 *///from  w w  w.j a  v  a 2 s . c o  m
public Map<String, List<Location>> getLocations(List<String> locations) {
    HttpClient httpClient = new DefaultHttpClient();

    try {
        URIBuilder uri = new URIBuilder(url + SEARCH_API);
        for (String loc : locations) {
            uri.addParameter(SEARCH_PARAM, loc);
        }
        HttpGet httpGet = new HttpGet(uri.build());

        HttpResponse resp = httpClient.execute(httpGet);
        String respJson = IOUtils.toString(resp.getEntity().getContent(), Charsets.UTF_8);

        @SuppressWarnings("serial")
        Type typeDef = new TypeToken<Map<String, List<Location>>>() {
        }.getType();

        return new Gson().fromJson(respJson, typeDef);

    } catch (Exception e) {
        LOG.error(e.getMessage(), e);
    }

    return null;
}

From source file:com.netflix.spinnaker.halyard.deploy.spinnaker.v1.profile.MetricRegistryProfileFactoryBuilder.java

public ProfileFactory build(ServiceSettings settings) {
    return new ProfileFactory() {
        @Override//from w ww.j  a va  2  s  .  c  o m
        protected ArtifactService getArtifactService() {
            return artifactService;
        }

        @Override
        protected void setProfile(Profile profile, DeploymentConfiguration deploymentConfiguration,
                SpinnakerRuntimeSettings endpoints) {
            URI uri;
            try {
                String baseUrl;
                if (settings.getBasicAuthEnabled() != null && settings.getBasicAuthEnabled()) {
                    baseUrl = settings.getAuthBaseUrl();
                } else {
                    baseUrl = settings.getBaseUrl();
                }
                uri = new URIBuilder(baseUrl).setHost("localhost").setPath("/spectator/metrics").build();
            } catch (URISyntaxException e) {
                throw new HalException(Problem.Severity.FATAL,
                        "Unable to build service URL: " + e.getMessage());
            }
            profile.appendContents("metrics_url: " + uri.toString());
        }

        @Override
        protected Profile getBaseProfile(String name, String version, String outputFile) {
            return new Profile(name, version, outputFile, "");
        }

        @Override
        public SpinnakerArtifact getArtifact() {
            return SpinnakerArtifact.SPINNAKER_MONITORING_DAEMON;
        }

        @Override
        protected String commentPrefix() {
            return "## ";
        }
    };
}

From source file:com.teradata.tempto.internal.hadoop.hdfs.SimpleHttpRequestsExecutor.java

private URI appendUsername(URI originalUri) {
    URIBuilder uriBuilder = new URIBuilder(originalUri);
    uriBuilder.setParameter("user.name", username);
    try {/* w w  w.j  a  v a  2  s  . co  m*/
        return uriBuilder.build();
    } catch (URISyntaxException e) {
        throw Throwables.propagate(e);
    }
}

From source file:org.commonjava.indy.client.core.module.IndyNfcClientModule.java

private NotFoundCacheDTO getPagedNfcContent(String baseUrl, Integer pageIndex, Integer pageSize)
        throws IndyClientException {
    IndyClientHttp clientHttp = getHttp();
    HttpGet req = clientHttp.newJsonGet(baseUrl);
    URI uri = null;// w w w. j  a va  2 s. co  m
    try {
        uri = new URIBuilder(req.getURI()).addParameter("pageIndex", pageIndex.toString())
                .addParameter("pageSize", pageSize.toString()).build();
    } catch (URISyntaxException e) {
        throw new RuntimeException(e);
    }
    return clientHttp.get(uri.toString(), NotFoundCacheDTO.class);
}

From source file:email.mandrill.MandrillApiHandler.java

public static List<Map<String, Object>> getTags() {
    List<Map<String, Object>> mandrillTagList = new ArrayList<>();

    try {/*  ww w.  j  a  v a 2  s .c  om*/

        HttpClient httpclient = HttpClients.createDefault();
        HttpGet httpGet = new HttpGet("https://mandrillapp.com/api/1.0/tags/list.json");
        URI uri = new URIBuilder(httpGet.getURI()).addParameter("key", SendEmail.MANDRILL_KEY).build();
        logger.info("Getting mandrill tags: " + uri.toString());
        Gson gson = new Gson();
        httpGet.setURI(uri);

        //Execute and get the response.
        HttpResponse response = httpclient.execute(httpGet);
        HttpEntity responseEntity = response.getEntity();
        if (responseEntity != null) {
            String jsonContent = EntityUtils.toString(responseEntity);
            logger.info(jsonContent);
            // Create a Reader from String
            Reader stringReader = new StringReader(jsonContent);

            // Pass the string reader to JsonReader constructor
            JsonReader reader = new JsonReader(stringReader);
            reader.setLenient(true);
            mandrillTagList = gson.fromJson(reader, List.class);

        }

    } catch (URISyntaxException ex) {
        Logger.getLogger(MandrillApiHandler.class.getName()).log(Level.SEVERE, null, ex);
    } catch (IOException ex) {
        Logger.getLogger(MandrillApiHandler.class.getName()).log(Level.SEVERE, null, ex);
    } catch (ParseException ex) {
        Logger.getLogger(MandrillApiHandler.class.getName()).log(Level.SEVERE, null, ex);
    }
    return mandrillTagList;
}