List of usage examples for org.apache.http.client.utils URIBuilder URIBuilder
public URIBuilder(final URI uri)
From source file:com.redhat.jenkins.plugins.bayesian.Bayesian.java
public Bayesian(String url) throws URISyntaxException { URI uri = new URI(url); String host = uri.getHost();//from www.ja v a2 s . c om if (host.indexOf('.') == -1) { // looks like it's a short domain name // TODO: there can be dots in short domain names as well List<String> cnames = DnsFiddler.getActualCNAME(host); if (!cnames.isEmpty()) { String hostname = cnames.get(0); if (hostname.endsWith(".")) { hostname = hostname.substring(0, hostname.length() - 1); } uri = new URIBuilder(uri).setHost(hostname).build(); } cnames = null; } this.url = uri.toString(); }
From source file:com.github.tmyroadctfig.icloud4j.PhotosService.java
/** * Gets the sync token.//from w w w . j ava 2 s .co m * * @return the sync token. */ private String getSyncToken() { try { URIBuilder uriBuilder = new URIBuilder(endPoint + "/startup"); iCloudService.populateUriParameters(uriBuilder); HttpGet httpGet = new HttpGet(uriBuilder.build()); iCloudService.populateRequestHeadersParameters(httpGet); String rawResponse = iCloudService.getHttpClient().execute(httpGet, new StringResponseHandler()); Type type = new TypeToken<Map<String, String>>() { }.getType(); Map<String, Object> responseMap = ICloudUtils.fromJson(rawResponse, type); return (String) responseMap.get("syncToken"); } catch (Exception e) { throw Throwables.propagate(e); } }
From source file:org.talend.dataprep.api.service.command.dataset.CreateDataSet.java
private HttpRequestBase onExecute(String name, String tag, String contentType, InputStream dataSetContent) { try {/*from w w w . ja va 2s .co m*/ URIBuilder uriBuilder = new URIBuilder(datasetServiceUrl + "/datasets"); uriBuilder.addParameter("name", name); uriBuilder.addParameter("tag", tag); final HttpPost post = new HttpPost(uriBuilder.build()); post.addHeader("Content-Type", contentType); //$NON-NLS-1$ post.setEntity(new InputStreamEntity(dataSetContent)); return post; } catch (URISyntaxException e) { throw new TDPException(CommonErrorCodes.UNEXPECTED_EXCEPTION, e); } }
From source file:com.github.tmyroadctfig.icloud4j.FindMyIPhoneService.java
/** * Gets a list of devices./*from w w w . j a v a2s.c o m*/ * * @return the list of devices. */ @SuppressWarnings("deprecation") public List<AppleDevice> getDevices() { try { URIBuilder uriBuilder = new URIBuilder(refreshUrl); iCloudService.populateUriParameters(uriBuilder); URI uri = uriBuilder.build(); String requestJson = "{\"clientContext\": {\"fmly\": true, \"shouldLocate\": true, \"selectedDevice\": \"all\"}}"; HttpPost post = new HttpPost(uri); post.setEntity(new StringEntity(requestJson, null, "UTF-8")); iCloudService.populateRequestHeadersParameters(post); FindMyIPhoneResponse findMyIPhoneResponse = ICloudUtils.parseJsonResponse(iCloudService.getHttpClient(), post, FindMyIPhoneResponse.class); return Arrays.asList(findMyIPhoneResponse.content); } catch (Exception e) { throw Throwables.propagate(e); } }
From source file:io.gravitee.gateway.standalone.QueryParametersTest.java
@Test public void call_get_query_params_emptyvalue() throws Exception { String query = ""; URI target = new URIBuilder("http://localhost:8082/test/my_team").addParameter("q", null).build(); Response response = Request.Get(target).execute(); HttpResponse returnResponse = response.returnResponse(); assertEquals(HttpStatus.SC_OK, returnResponse.getStatusLine().getStatusCode()); String responseContent = StringUtils.copy(returnResponse.getEntity().getContent()); assertEquals(query, responseContent); }
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 ww . j a va 2 s .c o m*/ 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:com.google.appengine.tck.byteman.DiffEntityGroupTest.java
private void doTest(URI root, boolean xg) throws Exception { try (CloseableHttpClient client = HttpClients.createMinimal()) { List<Thread> threads = new ArrayList<>(); Holder h1 = new Holder(); URIBuilder builder = new URIBuilder(root + "/ctx"); builder.addParameter("eg", "EG1"); builder.addParameter("c", "1"); builder.addParameter("p", "1"); builder.addParameter("xg", String.valueOf(xg)); threads.add(execute(client, new HttpPost(builder.build()), h1)); Holder h2 = new Holder(); builder = new URIBuilder(root + "/ctx"); builder.addParameter("eg", "EG2"); builder.addParameter("c", "2"); builder.addParameter("p", "2"); builder.addParameter("xg", String.valueOf(xg)); threads.add(execute(client, new HttpPost(builder.build()), h2)); join(threads);/* w w w. j ava 2 s. c o m*/ System.out.println("h1 = " + h1); System.out.println("h2 = " + h2); Assert.assertTrue("Expected ok: " + h1, h1.out.startsWith("OK1")); Assert.assertTrue("Expected ok: " + h2, h2.out.startsWith("OK2")); } }
From source file:org.broadleafcommerce.core.catalog.service.CatalogURLServiceImpl.java
/** * Adds the fragment to the end of the path and optionally adds an id param depending upon * the value of appendIdToRelativeURI./*from w w w. j av a2 s . c om*/ */ protected String buildRelativeUrlWithParam(String currentUrl, String fragment, String idParam, String idValue) { try { URIBuilder builder = new URIBuilder(currentUrl); builder.setPath(builder.getPath() + "/" + fragment); if (appendIdToRelativeURI) { builder.setParameter(idParam, String.valueOf(idValue)); } return builder.build().toString(); } catch (URISyntaxException e) { return currentUrl; } }
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 w w w . j a v a 2s .c o m*/ final Set<String> arts = tester.getAllArtifactIds(); Assert.assertEquals(1, arts.size()); }