List of usage examples for org.apache.http.client.utils URIBuilder build
public URI build() throws URISyntaxException
From source file:org.talend.dataprep.api.service.command.preparation.PreparationListByFolder.java
/** * Private constructor used to construct the generic command used to list of preparations matching name. * * @param folderId the folder id where to look for preparations. * @param sort how to sort the preparations. * @param order the order to apply to the sort. *//*from w w w .j a v a 2 s . c o m*/ private PreparationListByFolder(final String folderId, final Sort sort, final Order order) { super(GenericCommand.PREPARATION_GROUP); execute(() -> { try { final URIBuilder uriBuilder = new URIBuilder(preparationServiceUrl + "/preparations/search"); uriBuilder.addParameter("folderId", folderId); uriBuilder.addParameter("sort", sort.camelName()); uriBuilder.addParameter("order", order.camelName()); return new HttpGet(uriBuilder.build()); } catch (URISyntaxException e) { throw new TDPException(CommonErrorCodes.UNEXPECTED_EXCEPTION, e); } }); onError(e -> new TDPException(UNABLE_TO_RETRIEVE_PREPARATION_LIST, e)); on(NO_CONTENT, ACCEPTED).then(emptyStream()); on(OK).then(pipeStream()); }
From source file:se.inera.certificate.proxy.mappings.remote.RemoteMappingTest.java
@Test public void testMapToUrl2() throws URISyntaxException { RemoteMapping m = new RemoteMapping("/services", "http://www.google.com:80/test"); URIBuilder builder = new URIBuilder(); builder.setScheme(m.getMappedProtocol()).setHost(m.getMappedHost()).setPort(m.getMappedPort()) .setPath("/some/new/uri").setQuery("some=1&less=34").setFragment("hello"); assertEquals("http://www.google.com:80/some/new/uri?some=1&less=34#hello", builder.build().toString()); }
From source file:com.linemetrics.monk.api.RestClient.java
public URI buildURI(String path, Map<String, String> params) throws URISyntaxException { URIBuilder ub = new URIBuilder(uri); ub.setPath(ub.getPath() + path);//w ww. j a va2 s .c om if (params != null) { for (Map.Entry<String, String> ent : params.entrySet()) ub.addParameter(ent.getKey(), ent.getValue()); } return ub.build(); }
From source file:eu.fthevenet.util.github.GithubApi.java
/** * Returns a specific release from the specified repository. * * @param owner the repository's owner/*from w w w. j a va 2 s . c om*/ * @param repo the repository's name * @param id the id of the release to retrieve * @return An {@link Optional} that contains the specified release if it could be found. * @throws IOException if an IO error occurs while communicating with GitHub. * @throws URISyntaxException if the crafted URI is incorrect. */ public Optional<GithubRelease> getRelease(String owner, String repo, String id) throws IOException, URISyntaxException { URIBuilder requestUrl = new URIBuilder().setScheme(URL_PROTOCOL).setHost(GITHUB_API_HOSTNAME) .setPath("/repos/" + owner + "/" + repo + "/releases/" + id); logger.debug(() -> "requestUrl = " + requestUrl); HttpGet httpget = new HttpGet(requestUrl.build()); return Optional.ofNullable(httpClient.execute(httpget, new AbstractResponseHandler<GithubRelease>() { @Override public GithubRelease handleEntity(HttpEntity entity) throws IOException { return gson.fromJson(EntityUtils.toString(entity), GithubRelease.class); } })); }
From source file:com.epam.ngb.cli.manager.command.handler.http.AbstractAnnotationReferenceHandler.java
@Override public int runCommand() { String url = serverParameters.getServerUrl() + getRequestUrl(); for (Long annotationFileId : annotationFileIds) { try {// w ww. j a v a 2s . c o m URIBuilder builder = new URIBuilder(String.format(url, referenceId)); builder.addParameter("annotationFileId", String.valueOf(annotationFileId)); builder.addParameter("remove", String.valueOf(isRemoving())); HttpPut put = new HttpPut(builder.build()); setDefaultHeader(put); if (isSecure()) { addAuthorizationToRequest(put); } String result = RequestManager.executeRequest(put); checkAndPrintRegistrationResult(result, printJson, printTable); } catch (URISyntaxException e) { throw new ApplicationException(e.getMessage(), e); } } return 0; }
From source file:com.zazuko.wikidata.municipalities.SparqlClient.java
List<Map<String, RDFTerm>> queryResultSet(final String query) throws IOException, URISyntaxException { CloseableHttpClient httpclient = HttpClients.createDefault(); URIBuilder builder = new URIBuilder(endpoint); builder.addParameter("query", query); HttpGet httpGet = new HttpGet(builder.build()); /*List<NameValuePair> nvps = new ArrayList<NameValuePair>(); nvps.add(new BasicNameValuePair("query", query)); httpGet.setEntity(new UrlEncodedFormEntity(nvps));*/ CloseableHttpResponse response2 = httpclient.execute(httpGet); try {//from w w w . j av a2 s .c om HttpEntity entity2 = response2.getEntity(); InputStream in = entity2.getContent(); if (debug) { ByteArrayOutputStream baos = new ByteArrayOutputStream(); for (int ch = in.read(); ch != -1; ch = in.read()) { System.out.print((char) ch); baos.write(ch); } in = new ByteArrayInputStream(baos.toByteArray()); } SAXParserFactory spf = SAXParserFactory.newInstance(); spf.setNamespaceAware(true); SAXParser saxParser = spf.newSAXParser(); XMLReader xmlReader = saxParser.getXMLReader(); final SparqlsResultsHandler sparqlsResultsHandler = new SparqlsResultsHandler(); xmlReader.setContentHandler(sparqlsResultsHandler); xmlReader.parse(new InputSource(in)); /* for (int ch = in.read(); ch != -1; ch = in.read()) { System.out.print((char)ch); } */ // do something useful with the response body // and ensure it is fully consumed EntityUtils.consume(entity2); return sparqlsResultsHandler.getResults(); } catch (ParserConfigurationException ex) { throw new RuntimeException(ex); } catch (SAXException ex) { throw new RuntimeException(ex); } finally { response2.close(); } }
From source file:gov.medicaid.screening.dao.impl.DieteticsAndNutritionPracticeLicenseDAOBean.java
/** * Performs a search for all possible results. * * @param identifier The value to be searched. * @return the search result for licenses * @throws URISyntaxException When an error occurs while building the URL. * @throws ClientProtocolException When client does not support protocol used. * @throws IOException When an error occurs while parsing response. * @throws ParseException When an error occurs while parsing response. * @throws PersistenceException for database related errors * @throws ServiceException for any other errors *//* w ww .j av a2 s . co m*/ private SearchResult<License> getAllResults(String identifier) throws URISyntaxException, ClientProtocolException, IOException, ParseException, PersistenceException, ServiceException { DefaultHttpClient client = new DefaultHttpClient(); URIBuilder builder = new URIBuilder(getSearchURL()); String hostId = builder.build().toString(); HttpGet httpget = new HttpGet(builder.build()); HttpResponse landing = client.execute(httpget); Document document = Jsoup.parse(EntityUtils.toString(landing.getEntity())); HttpPost httppost = new HttpPost(builder.build()); HttpEntity entity = postForm(hostId, client, httppost, new String[][] { { "_ctl0:_ctl1:_ctl0:txtCriteria", identifier }, { "_ctl0:_ctl1:_ctl0:btnSubmit", "Search" }, { "__EVENTTARGET", "" }, { "__EVENTARGUMENT", "" }, { "__VIEWSTATE", document.select("#Form input[name=__VIEWSTATE]").first().val() } }, true); // licenses list List<License> licenseList = new ArrayList<License>(); while (entity != null) { String result = EntityUtils.toString(entity); document = Jsoup.parse(result); Elements trs = document.select(GRID_ROW_SELECTOR); if (trs != null) { for (Element element : trs) { licenseList.add(parseLicense(element.children())); } } // done, check if there are additional results entity = null; Elements elements = document.getElementsByTag("a"); for (Element element : elements) { if (element.text().equals("Next >>")) { entity = postForm(hostId, client, httppost, new String[][] { { "_ctl0:_ctl1:_ctl0:txtCriteria", identifier }, { "__EVENTTARGET", "_ctl0:_ctl1:_ctl0:dgrdLicensee:_ctl29:_ctl1" }, { "__EVENTARGUMENT", "" }, { "__VIEWSTATE", document.select("#Form input[name=__VIEWSTATE]").first().val() } }, true); break; } } } SearchResult<License> result = new SearchResult<License>(); result.setItems(licenseList); return result; }
From source file:com.linagora.james.mailets.GuessClassificationMailet.java
private URI serviceUrlWithQueryParameters(Collection<MailAddress> recipients) throws URISyntaxException { URIBuilder uriBuilder = new URIBuilder(serviceUrl); recipients.forEach(address -> uriBuilder.addParameter("recipients", address.asString())); return uriBuilder.build(); }
From source file:com.uber.jenkins.phabricator.uberalls.UberallsClient.java
public String getCoverage(String sha) { URIBuilder builder; try {// w w w .ja v a 2s . c om builder = getBuilder().setParameter("sha", sha).setParameter("repository", repository); HttpClient client = getClient(); HttpMethod request = new GetMethod(builder.build().toString()); int statusCode = client.executeMethod(request); if (statusCode != HttpStatus.SC_OK) { logger.info(TAG, "Call failed: " + request.getStatusLine()); return null; } return request.getResponseBodyAsString(); } catch (HttpResponseException e) { if (e.getStatusCode() != 404) { e.printStackTrace(logger.getStream()); } } catch (Exception e) { e.printStackTrace(logger.getStream()); } return null; }
From source file:org.eclipse.packagedrone.testing.server.channel.UploadApiV3Test.java
@Test public void upload1Plain() throws URISyntaxException, IOException { final ChannelTester tester = ChannelTester.create(getWebContext(), "uploadapi2a"); tester.assignDeployGroup("m1"); final String deployKey = tester.getDeployKeys().iterator().next(); final File file = getAbsolutePath(CommonResources.BUNDLE_1_RESOURCE); final URIBuilder b = new URIBuilder( resolve("/api/v3/upload/plain/channel/%s/%s", tester.getId(), file.getName())); b.setUserInfo("deploy", deployKey); b.addParameter("foo:bar", "baz"); System.out.println("Request: " + b.build()); try (final CloseableHttpResponse response = upload(b, file)) { final String result = CharStreams .toString(new InputStreamReader(response.getEntity().getContent(), StandardCharsets.UTF_8)); System.out.println("Result: " + response.getStatusLine()); System.out.println(result); Assert.assertEquals(200, response.getStatusLine().getStatusCode()); }/*from ww w.j a v a 2s. c o m*/ final Set<String> arts = tester.getAllArtifactIds(); Assert.assertEquals(1, arts.size()); }