List of usage examples for org.apache.http.client.utils URIBuilder setPath
public URIBuilder setPath(final String path)
From source file:org.sahli.asciidoc.confluence.publisher.client.http.HttpRequestFactory.java
public HttpGet getAttachmentsRequest(String contentId, Integer limit, Integer start, String expandOptions) { assertMandatoryParameter(isNotBlank(contentId), "contentId"); URIBuilder uriBuilder = new URIBuilder(); uriBuilder.setPath(this.confluenceRestApiEndpoint + "/content/" + contentId + "/child/attachment"); if (limit != null) { uriBuilder.addParameter("limit", limit.toString()); }//from w ww . ja v a 2 s .co m if (start != null) { uriBuilder.addParameter("start", start.toString()); } if (isNotBlank(expandOptions)) { uriBuilder.addParameter("expand", expandOptions); } HttpGet getAttachmentsRequest; try { getAttachmentsRequest = new HttpGet(uriBuilder.build().toString()); } catch (URISyntaxException e) { throw new RuntimeException("Invalid URL", e); } return getAttachmentsRequest; }
From source file:com.anrisoftware.simplerest.owncloudocs.OwncloudOcsUploadFile.java
private URI getRequestURI0() throws URISyntaxException { URI baseUri = account.getBaseUri(); String extraPath = baseUri.getPath(); URIBuilder builder = new URIBuilder(baseUri); builder.setUserInfo(account.getUser(), account.getPassword()); String statusPath = String.format("%s%s%s", extraPath, propertiesProvider.getOwncloudWebdavPath(), remotePath);//from ww w . j a v a 2 s.c om builder.setPath(statusPath); return builder.build(); }
From source file:it.txt.ens.core.impl.test.BasicENSResourceTest.java
private void testURI(ENSResource resource) { URIBuilder uriBuilder = new URIBuilder(); uriBuilder.addParameter(ENSResource.NAMESPACE_PARAMETER_NAME, resource.getNamespace()); uriBuilder.addParameter(ENSResource.PATTERN_PARAMETER_NAME, resource.getPattern()); uriBuilder.setHost(resource.getHost()); uriBuilder.setPath(resource.getPath()); uriBuilder.setScheme(ENSResource.URI_SCHEME); try {/*ww w . j a v a 2 s.c o m*/ assertEquals("Unexpected resourceURI", uriBuilder.build(), resource.getURI()); } catch (URISyntaxException e) { fail(e.getMessage()); e.printStackTrace(); } }
From source file:com.derpgroup.livefinder.resource.AuthResource.java
public Response buildRedirect(String path, String host, String reason, String fragment) { URIBuilder uriBuilder = new URIBuilder(); uriBuilder.setPath(path); if (!StringUtils.isEmpty(host)) { uriBuilder.setPath(host);/* ww w . j a va2s .c om*/ } if (!StringUtils.isEmpty(path)) { uriBuilder.setPath(path); } if (!StringUtils.isEmpty(reason)) { uriBuilder.addParameter("reason", reason); } if (!StringUtils.isEmpty(fragment)) { uriBuilder.setFragment(fragment); } try { return Response.seeOther(uriBuilder.build()).build(); } catch (URISyntaxException e) { return Response.serverError().entity("Unknown exception.").build(); } }
From source file:net.packet.Request.java
/** * Returns the composed endpoint URI.// w ww .j av a2s. c o 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(); }
From source file:org.jasig.portlet.proxy.service.proxy.document.URLRewritingFilter.java
protected String getRelativePathUrl(final String fullUrl) throws URISyntaxException { final URIBuilder uriBuilder = new URIBuilder(fullUrl); uriBuilder.removeQuery();/*from ww w . ja v a 2 s. c o m*/ final String path = uriBuilder.getPath(); int lastSlash = path.lastIndexOf('/'); if (lastSlash < 0) { uriBuilder.setPath(""); } else { uriBuilder.setPath(path.substring(0, lastSlash + 1)); } return uriBuilder.build().toString(); }
From source file:net.datacrow.onlinesearch.discogs.task.DiscogsMusicSearch.java
@Override protected Collection<Object> getItemKeys() throws Exception { HttpClient httpClient = getHttpClient(); List<NameValuePair> queryParams = new ArrayList<NameValuePair>(); queryParams.add(new BasicNameValuePair("q", getQuery())); URIBuilder builder = new URIBuilder(); builder.setScheme("http"); builder.setHost("api.discogs.com"); builder.setPath("/database/search"); builder.setQuery(URLEncodedUtils.format(queryParams, "UTF-8")); URI uri = builder.build();//from w w w . j a v a2s. c o m HttpGet httpGet = new HttpGet(uri); HttpOAuthHelper au = new HttpOAuthHelper("application/json"); au.handleRequest(httpGet, _CONSUMER_KEY, _CONSUMER_SECRET, null, queryParams); HttpResponse httpResponse = httpClient.execute(httpGet); String response = getReponseText(httpResponse); httpClient.getConnectionManager().shutdown(); Collection<Object> keys = new ArrayList<Object>(); int counter = 0; for (String key : StringUtils.getValuesBetween("\"id\":", "}", response)) { keys.add(key.trim()); if (counter++ >= maxQuerySize) break; } return keys; }
From source file:net.datacrow.onlinesearch.discogs.task.DiscogsMusicSearch.java
@Override protected DcObject getItem(Object key, boolean full) throws Exception { HttpClient httpClient = getHttpClient(); URIBuilder builder = new URIBuilder(); builder.setScheme("http"); builder.setHost("api.discogs.com"); builder.setPath("/release/" + key); URI uri = builder.build();//from ww w .j a v a2 s. c o m HttpGet httpGet = new HttpGet(uri); HttpOAuthHelper au = new HttpOAuthHelper("application/json"); au.handleRequest(httpGet, _CONSUMER_KEY, _CONSUMER_SECRET); HttpResponse httpResponse = httpClient.execute(httpGet); String response = getReponseText(httpResponse); httpClient.getConnectionManager().shutdown(); MusicAlbum ma = new MusicAlbum(); ma.addExternalReference(DcRepository.ExternalReferences._DISCOGS, (String) key); ma.setValue(DcObject._SYS_SERVICEURL, uri.toString()); JsonParser jsonParser = new JsonParser(); JsonObject jsonObject = (JsonObject) jsonParser.parse(response); JsonObject eRespone = jsonObject.getAsJsonObject("resp"); JsonObject eRelease = eRespone.getAsJsonObject("release"); if (eRelease != null) { ma.setValue(MusicAlbum._A_TITLE, eRelease.get("title").getAsString()); ma.setValue(MusicAlbum._C_YEAR, eRelease.get("year").getAsString()); ma.setValue(MusicAlbum._N_WEBPAGE, eRelease.get("uri").getAsString()); ma.createReference(MusicAlbum._F_COUNTRY, eRelease.get("country").getAsString()); setStorageMedium(ma, eRelease); setRating(ma, eRelease); setGenres(ma, eRelease); setArtists(ma, eRelease); addTracks(ma, eRelease); setImages(ma, eRelease); } Thread.sleep(1000); return ma; }
From source file:com.seleniumtests.connectors.selenium.SeleniumRobotGridConnector.java
/** * Upload a file given file path//from www . j av a2 s. com * @param filePath */ @Override public void uploadFile(String filePath) { try (CloseableHttpClient client = HttpClients.createDefault();) { // zip file List<File> appFiles = new ArrayList<>(); appFiles.add(new File(filePath)); File zipFile = FileUtility.createZipArchiveFromFiles(appFiles); HttpHost serverHost = new HttpHost(hubUrl.getHost(), hubUrl.getPort()); URIBuilder builder = new URIBuilder(); builder.setPath("/grid/admin/FileServlet/"); builder.addParameter("output", "app"); HttpPost httpPost = new HttpPost(builder.build()); httpPost.setHeader(HttpHeaders.CONTENT_TYPE, MediaType.OCTET_STREAM.toString()); FileInputStream fileInputStream = new FileInputStream(zipFile); InputStreamEntity entity = new InputStreamEntity(fileInputStream); httpPost.setEntity(entity); CloseableHttpResponse response = client.execute(serverHost, httpPost); if (response.getStatusLine().getStatusCode() != 200) { throw new SeleniumGridException( "could not upload file: " + response.getStatusLine().getReasonPhrase()); } else { // TODO call remote API throw new NotImplementedException("call remote Robot to really upload file"); } } catch (IOException | URISyntaxException e) { throw new SeleniumGridException("could not upload file", e); } }
From source file:net.rcarz.jiraclient.RestClient.java
/** * Build a URI from a path and query parmeters. * * @param path Path to append to the base URI * @param params Map of key value pairs/* www. j a v a 2 s .co m*/ * * @return the full URI * * @throws URISyntaxException when the path is invalid */ public URI buildURI(String path, Map<String, String> params) throws URISyntaxException { URIBuilder ub = new URIBuilder(uri); ub.setPath(ub.getPath() + path); if (params != null) { for (Map.Entry<String, String> ent : params.entrySet()) ub.addParameter(ent.getKey(), ent.getValue()); } return ub.build(); }