List of usage examples for org.apache.http.client.utils URIBuilder setPath
public URIBuilder setPath(final String path)
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); if (params != null) { for (Map.Entry<String, String> ent : params.entrySet()) ub.addParameter(ent.getKey(), ent.getValue()); }/* w w w. j av a 2s. c o m*/ return ub.build(); }
From source file:models.Pagination.java
private URI createReference(final String path, final int limit, final int offset, final Map<String, String> conditions) { final URIBuilder uriBuilder = new URIBuilder(); uriBuilder.setPath(path); for (Map.Entry<String, String> entry : conditions.entrySet()) { uriBuilder.addParameter(entry.getKey(), entry.getValue()); }// w w w . j a v a 2 s. c o m uriBuilder.addParameter("limit", String.valueOf(limit)); uriBuilder.addParameter("offset", String.valueOf(offset)); try { return uriBuilder.build(); } catch (final URISyntaxException e) { throw new RuntimeException("Failed building uri", e); } }
From source file:ca.islandora.fcrepo.client.FcrepoClient.java
@Override public IFcrepoResponse extendTransaction(final String uri) throws FcrepoOperationFailedException { try {//from w ww. j av a 2 s. c o m URIBuilder uriBuilder = new URIBuilder(uri); uriBuilder.setPath(uriBuilder.getPath() + "/fcr:tx"); final String fullUri = uriBuilder.build().toString(); final IFcrepoRequest request = new CreateResourceRequest(httpClient, fullUri); return request.execute(); } catch (URISyntaxException ex) { throw new FcrepoOperationFailedException(null, -1, ex.getMessage()); } }
From source file:ca.islandora.fcrepo.client.FcrepoClient.java
@Override public IFcrepoResponse createTransaction() throws FcrepoOperationFailedException { try {//from w ww . jav a 2 s. co m URIBuilder uriBuilder = new URIBuilder(baseUri); uriBuilder.setPath(uriBuilder.getPath() + "/fcr:tx"); final String uri = uriBuilder.build().toString(); final IFcrepoRequest request = new CreateResourceRequest(httpClient, uri); return request.execute(); } catch (URISyntaxException ex) { throw new FcrepoOperationFailedException(null, -1, ex.getMessage()); } }
From source file:ca.islandora.fcrepo.client.FcrepoClient.java
@Override public IFcrepoResponse commitTransaction(final String uri) throws FcrepoOperationFailedException { try {/* w w w . j av a 2s .c om*/ URIBuilder uriBuilder = new URIBuilder(baseUri); uriBuilder.setPath(uriBuilder.getPath() + "/fcr:tx/fcr:commit"); final String fullUri = uriBuilder.build().toString(); final IFcrepoRequest request = new CreateResourceRequest(httpClient, fullUri); return request.execute(); } catch (URISyntaxException ex) { throw new FcrepoOperationFailedException(null, -1, ex.getMessage()); } }
From source file:ca.islandora.fcrepo.client.FcrepoClient.java
@Override public IFcrepoResponse rollbackTransaction(final String uri) throws FcrepoOperationFailedException { try {/*from ww w .j a v a 2 s .c o m*/ URIBuilder uriBuilder = new URIBuilder(baseUri); uriBuilder.setPath(uriBuilder.getPath() + "/fcr:tx/fcr:rollback"); final String fullUri = uriBuilder.build().toString(); final IFcrepoRequest request = new CreateResourceRequest(httpClient, fullUri); return request.execute(); } catch (URISyntaxException ex) { throw new FcrepoOperationFailedException(null, -1, ex.getMessage()); } }
From source file:nl.esciencecenter.ptk.web.URIQueryParameters.java
/** * Create URI encoded query String from this parameter list. * /*w w w . jav a 2 s. com*/ * @return URI query string. * @throws UnsupportedEncodingException */ public String toQueryString() throws UnsupportedEncodingException { // Use Apache URI builder ! URIBuilder uriBuilder = new URIBuilder(); uriBuilder.setHost("host"); uriBuilder.setScheme("scheme"); uriBuilder.setPath("/"); for (String key : this.keySet()) { uriBuilder.setParameter(key, this.get(key)); } // todo: better URI query encoding. return uriBuilder.toString().substring("scheme://host/?".length()); }
From source file:org.berlin.crawl.bean.BotSeed.java
public URIBuilder toBuilder() { final URIBuilder b = new URIBuilder(); b.setPath(path); b.setHost(host);/*from w w w . j av a 2 s . c o m*/ b.setScheme(scheme); return b; }
From source file:io.kamax.mxisd.lookup.provider.RemoteIdentityServerFetcher.java
@Override public Optional<SingleLookupReply> find(String remote, SingleLookupRequest request) { log.info("Looking up {} 3PID {} using {}", request.getType(), request.getThreePid(), remote); try {//www . java 2 s .co m URIBuilder b = new URIBuilder(remote); b.setPath("/_matrix/identity/api/v1/lookup"); b.addParameter("medium", request.getType()); b.addParameter("address", request.getThreePid()); HttpGet req = new HttpGet(b.build()); try (CloseableHttpResponse res = client.execute(req)) { int statusCode = res.getStatusLine().getStatusCode(); String body = EntityUtils.toString(res.getEntity()); if (statusCode != 200) { log.warn("Remote returned status code {}", statusCode); log.warn("Body: {}", body); return Optional.empty(); } JsonObject obj = GsonUtil.parseObj(body); if (obj.has("address")) { log.debug("Found 3PID mapping: {}", gson.toJson(obj)); return Optional.of(SingleLookupReply.fromRecursive(request, gson.toJson(obj))); } log.info("Empty 3PID mapping from {}", remote); return Optional.empty(); } } catch (IOException e) { log.warn("Error looking up 3PID mapping {}: {}", request.getThreePid(), e.getMessage()); return Optional.empty(); } catch (JsonParseException e) { log.warn("Invalid JSON answer from {}", remote); return Optional.empty(); } catch (URISyntaxException e) { log.warn("Invalid remote address: {}", e.getMessage(), e); return Optional.empty(); } }
From source file:es.upv.grycap.coreutils.fiber.net.UrlBuilder.java
/** * Creates a new URL relative to the base URL provided in the constructor of this class. The new relative URL * includes the path, query parameters and the internal reference of the {@link UrlBuilder#baseUrl base URL} * provided with this class. An additional fragment, as well as additional query parameters can be optionally * added to the new URL. In addition to the parameters passed to the method as an argument, the supplied * fragment can also include parameters that will be added to the created URL. The created URL is normalized * and unencoded before returning it to the caller. The current implementation has the following limitations: * <ul>/* w ww. j av a2 s . co m*/ * <li>Arrays are not supported: <tt>q=foo&q=bar</tt> will produce an error.</li> * <li>Internal references are only supported in the base URL. Any additional reference provided with the * fragment will be silently ignored: the fragment <tt>/rd#ref</tt> will be appended to the base URL as * <tt>/rd</tt>, ignoring the internal reference.</li> * </ul> * @param fragment - optional URL fragment (may include parameters, but not references) that will be added * to the base URL * @param params - optional query parameters that will be added to the base URL * @return A relative URL created from the base URL provided in the constructor of this class and adding the * fragment and parameters passed as arguments to this method. */ public String buildRelativeUrl(final @Nullable String fragment, final @Nullable Map<String, String> params) { String url = null; final Optional<String> fragment2 = ofNullable(trimToNull(fragment)); try { final Optional<URL> fragmentUrl = ofNullable( fragment2.isPresent() ? new URL("http://example.com/" + fragment2.get()) : null); final URIBuilder uriBuilder = new URIBuilder(); // add path uriBuilder.setPath(new StringBuilder(ofNullable(trimToNull(baseUrl.getPath())).orElse("/")) .append(fragmentUrl.isPresent() ? "/" + stripEnd(fragmentUrl.get().getPath(), "/") : "") .toString().replaceAll("[/]{2,}", "/")); // add query parameters if (isNotBlank(baseUrl.getQuery())) { uriBuilder.setParameters(URLEncodedUtils.parse(baseUrl.getQuery(), defaultCharset())); } if (fragmentUrl.isPresent() && isNotBlank(fragmentUrl.get().getQuery())) { URLEncodedUtils.parse(fragmentUrl.get().getQuery(), defaultCharset()).stream().forEach(p -> { uriBuilder.addParameter(p.getName(), p.getValue()); }); } ofNullable(params).orElse(emptyMap()).entrySet().stream().forEach(p -> { uriBuilder.addParameter(p.getKey(), p.getValue()); }); // add internal reference uriBuilder.setFragment(baseUrl.getRef()); // build relative URL url = uriBuilder.build().normalize().toString(); } catch (MalformedURLException | URISyntaxException e) { throw new IllegalStateException( new StringBuilder("Failed to create relative URL from provided parameters: fragment=") .append(fragment2.orElse("null")).append(", params=") .append(params != null ? params.toString() : "null").toString(), e); } return url; }