List of usage examples for org.apache.http.client.utils URIBuilder URIBuilder
public URIBuilder()
From source file:client.QueryLastFm.java
License:asdf
public static void findSimilarTracks(PrintWriter track_id_out, String sourceMbid, String trackName, String artistName) throws Exception { String destMbid;/*from w w w . j ava 2 s .c o m*/ CloseableHttpClient httpclient = HttpClients.createDefault(); try { Thread.sleep(50); //1000 milliseconds is one second. } catch (InterruptedException ex) { Thread.currentThread().interrupt(); } try { URI uri = new URIBuilder().setScheme("http").setHost("ws.audioscrobbler.com").setPath("/2.0/") .setParameter("method", "track.getsimilar").setParameter("artist", artistName) .setParameter("track", trackName).setParameter("limit", "10") .setParameter("api_key", "88858618961414f8bec919bddd057044").build(); // new URIBuilder(). HttpGet request = new HttpGet(uri); // request. // This is useful for last.fm logging and preventing them from blocking this client request.setHeader(HttpHeaders.USER_AGENT, "nileshmore@gatech.edu - ClassAssignment at GeorgiaTech Non-commercial use"); CloseableHttpResponse response = httpclient.execute(request); int statusCode = response.getStatusLine().getStatusCode(); DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder = factory.newDocumentBuilder(); try { if (statusCode == 200) { HttpEntity entity1 = response.getEntity(); BufferedReader br = new BufferedReader( new InputStreamReader((response.getEntity().getContent()))); Document document = builder.parse((response.getEntity().getContent())); Element root = document.getDocumentElement(); root.normalize(); NodeList mbidList = root.getElementsByTagName("mbid"); // System.out.println("mbid" + mbidList.getLength()); for (int n = 0; n < mbidList.getLength(); n++) { Node attribute = mbidList.item(n); if (mbidList.item(n).hasChildNodes()) { if (mbidList.item(n).getParentNode().getNodeName().matches("track")) // to get correct mbid { destMbid = mbidList.item(n).getFirstChild().getNodeValue(); // track_id_out.print(sourceMbid); // track_id_out.print(","); // track_id_out.println(destMbid); if (isAlreadyInserted(sourceMbid, destMbid)) // if not inserted , insert into map { // System.out.println(sourceMbid + "---" + destMbid); // track_id_out.print(sourceMbid); // track_id_out.print(","); // track_id_out.println(destMbid); // continue; } /*if(isAlreadyInserted(sourceMbid, destMbid)) { System.out.println("Ok got the match !!"); }*/ else { track_id_out.print(sourceMbid); track_id_out.print(","); track_id_out.println(destMbid); // // track_id_out.print(","); // track_id_out.println("Undirected"); } // track_id_out.print() } } } } } finally { response.close(); } } finally { httpclient.close(); } }
From source file:com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.ServiceSettings.java
private URIBuilder buildBaseUri() { if (StringUtils.isEmpty(overrideBaseUrl)) { return new URIBuilder().setScheme(getScheme()).setPort(getPort()).setHost(getAddress()); } else {/* w ww .j av a 2s . c om*/ try { return new URIBuilder(overrideBaseUrl); } catch (URISyntaxException e) { throw new HalException(Problem.Severity.FATAL, "Illegal override baseURL: " + overrideBaseUrl, e); } } }
From source file:com.clxcommunications.xms.BatchFilterTest.java
@Property public void generatesValidQueryParameters(int page, int pageSize, Set<String> senders, Set<String> tags, LocalDate startDate, LocalDate endDate) throws Exception { // Constrain `senders` and `tags` to strings not containing ',' assumeThat(senders, not(hasItem(containsString(",")))); assumeThat(tags, not(hasItem(containsString(",")))); BatchFilter filter = ClxApi.batchFilter().pageSize(pageSize).senders(senders).tags(tags) .startDate(startDate).endDate(endDate).build(); List<NameValuePair> params = filter.toQueryParams(page); // Will throw IllegalArgumentException if an invalid URI is attempted. new URIBuilder().addParameters(params).build(); }
From source file:ee.ria.xroad.proxy.testsuite.testcases.GetListCentralServicesMessage.java
@Override protected URI getClientUri() throws URISyntaxException { return new URIBuilder().setScheme("http").setHost("localhost") .setPort(SystemProperties.getClientProxyHttpPort()).setPath(MetadataRequests.LIST_CENTRAL_SERVICES) .setParameter(PARAM_INSTANCE_IDENTIFIER, EXPECTED_XR_INSTANCE).build(); }
From source file:ee.ria.xroad.proxy.testsuite.testcases.GetListClientsMessage.java
@Override protected URI getClientUri() throws URISyntaxException { return new URIBuilder().setScheme("http").setHost("localhost") .setPort(SystemProperties.getClientProxyHttpPort()).setPath(MetadataRequests.LIST_CLIENTS) .setParameter(PARAM_INSTANCE_IDENTIFIER, EXPECTED_XR_INSTANCE).build(); }
From source file:org.geosdi.geoplatform.experimental.openam.support.config.connector.base.BaseOpenAMConnector.java
/** * @param openAMConnectorSettings//from w w w.j a v a 2 s.com * @param <Settings> * @return {@link URIBuilder} * @throws Exception */ default <Settings extends GPConnectorSettings, Request extends BaseOpenAMRequest> URIBuilder buildURI( Settings openAMConnectorSettings, Request openAMConnectorRequest) throws Exception { Preconditions.checkNotNull(openAMConnectorSettings, "The Ape2015 Connector Settings must not be null."); return new URIBuilder().setScheme(openAMConnectorSettings.getScheme()) .setHost(openAMConnectorSettings.getHost()) .setPath(openAMConnectorSettings.getPath().concat(openAMConnectorRequest.getPath())); }
From source file:org.wuspba.ctams.ws.ITBandContestEntryController.java
@Test public void testListBand() throws Exception { CloseableHttpClient httpclient = HttpClients.createDefault(); URI uri = new URIBuilder().setScheme(PROTOCOL).setHost(HOST).setPort(PORT).setPath(PATH) .setParameter("band", TestFixture.INSTANCE.skye.getId()).build(); HttpGet httpGet = new HttpGet(uri); try (CloseableHttpResponse response = httpclient.execute(httpGet)) { assertEquals(response.getStatusLine().toString(), IntegrationTestUtils.OK_STRING); HttpEntity entity = response.getEntity(); CTAMSDocument doc = IntegrationTestUtils.convertEntity(entity); assertEquals(doc.getBandContestEntry().size(), 1); testEquality(doc.getBandContestEntry().get(0), TestFixture.INSTANCE.bandContestEntry); EntityUtils.consume(entity);//ww w . j av a 2 s . c om } uri = new URIBuilder().setScheme(PROTOCOL).setHost(HOST).setPort(PORT).setPath(PATH) .setParameter("band", "garbage").build(); httpGet = new HttpGet(uri); try (CloseableHttpResponse response = httpclient.execute(httpGet)) { assertEquals(response.getStatusLine().toString(), IntegrationTestUtils.OK_STRING); HttpEntity entity = response.getEntity(); CTAMSDocument doc = IntegrationTestUtils.convertEntity(entity); assertEquals(doc.getBandContestEntry().size(), 0); EntityUtils.consume(entity); } }
From source file:org.wuspba.ctams.ws.ITHiredJudgeController.java
@Test public void testListJudge() throws Exception { CloseableHttpClient httpclient = HttpClients.createDefault(); URI uri = new URIBuilder().setScheme(PROTOCOL).setHost(HOST).setPort(PORT).setPath(PATH) .setParameter("judge", TestFixture.INSTANCE.judgeAndy.getId()).build(); HttpGet httpGet = new HttpGet(uri); try (CloseableHttpResponse response = httpclient.execute(httpGet)) { assertEquals(response.getStatusLine().toString(), IntegrationTestUtils.OK_STRING); HttpEntity entity = response.getEntity(); CTAMSDocument doc = IntegrationTestUtils.convertEntity(entity); assertEquals(doc.getHiredJudges().size(), 1); testEquality(doc.getHiredJudges().get(0), TestFixture.INSTANCE.hiredJudgeAndy); EntityUtils.consume(entity);// w ww .ja v a 2 s .c om } uri = new URIBuilder().setScheme(PROTOCOL).setHost(HOST).setPort(PORT).setPath(PATH) .setParameter("judge", "garbage").build(); httpGet = new HttpGet(uri); try (CloseableHttpResponse response = httpclient.execute(httpGet)) { assertEquals(response.getStatusLine().toString(), IntegrationTestUtils.OK_STRING); HttpEntity entity = response.getEntity(); CTAMSDocument doc = IntegrationTestUtils.convertEntity(entity); assertEquals(doc.getHiredJudges().size(), 0); EntityUtils.consume(entity); } }
From source file:org.wuspba.ctams.ws.ITSoloContestEntryController.java
@Test public void testListPerson() throws Exception { CloseableHttpClient httpclient = HttpClients.createDefault(); URI uri = new URIBuilder().setScheme(PROTOCOL).setHost(HOST).setPort(PORT).setPath(PATH) .setParameter("person", TestFixture.INSTANCE.elaine.getId()).build(); HttpGet httpGet = new HttpGet(uri); try (CloseableHttpResponse response = httpclient.execute(httpGet)) { assertEquals(response.getStatusLine().toString(), IntegrationTestUtils.OK_STRING); HttpEntity entity = response.getEntity(); CTAMSDocument doc = IntegrationTestUtils.convertEntity(entity); assertEquals(doc.getSoloContestEntry().size(), 1); testEquality(doc.getSoloContestEntry().get(0), TestFixture.INSTANCE.soloContestEntry); EntityUtils.consume(entity);// w ww . j a v a2 s .com } uri = new URIBuilder().setScheme(PROTOCOL).setHost(HOST).setPort(PORT).setPath(PATH) .setParameter("person", "garbage").build(); httpGet = new HttpGet(uri); try (CloseableHttpResponse response = httpclient.execute(httpGet)) { assertEquals(response.getStatusLine().toString(), IntegrationTestUtils.OK_STRING); HttpEntity entity = response.getEntity(); CTAMSDocument doc = IntegrationTestUtils.convertEntity(entity); assertEquals(doc.getSoloContestEntry().size(), 0); EntityUtils.consume(entity); } }
From source file:net.packet.Request.java
/** * Returns the composed endpoint URI.// www . jav a 2s.co m * * @return {@link URI} * @throws URISyntaxException when URI is incorrect */ public URI buildUri() throws URISyntaxException { URIBuilder ub = new URIBuilder(); ub.setScheme(Constants.URI_SCHEME); ub.setHost(Constants.HOSTNAME); String path = (null == pathParams) ? endpoint.getPath() : String.format(endpoint.getPath(), pathParams); ub.setPath(path); if (null != queryParams) { for (Map.Entry<String, String> entry : queryParams.entrySet()) { ub.setParameter(entry.getKey(), entry.getValue()); } } return ub.build(); }