List of usage examples for org.apache.http.client.utils URIBuilder addParameter
public URIBuilder addParameter(final String param, final String value)
From source file:alluxio.cli.LogLevel.java
private static void setLogLevel(final TargetInfo targetInfo, String logName, String level) throws IOException { URIBuilder uriBuilder = new URIBuilder(); uriBuilder.setScheme("http"); uriBuilder.setHost(targetInfo.getHost()); uriBuilder.setPort(targetInfo.getPort()); uriBuilder.setPath(Constants.REST_API_PREFIX + "/" + targetInfo.getRole() + "/" + LOG_LEVEL); uriBuilder.addParameter(LOG_NAME_OPTION_NAME, logName); if (level != null) { uriBuilder.addParameter(LEVEL_OPTION_NAME, level); }//from w w w. j a v a 2 s . c om HttpUtils.post(uriBuilder.toString(), 5000, new HttpUtils.IProcessInputStream() { @Override public void process(InputStream inputStream) throws IOException { ObjectMapper mapper = new ObjectMapper(); LogInfo logInfo = mapper.readValue(inputStream, LogInfo.class); System.out.println(targetInfo.toString() + logInfo.toString()); } }); }
From source file:org.apache.gobblin.utils.HttpUtils.java
/** * Given a url template, interpolate with keys and build the URI after adding query parameters * * <p>/*from w ww . ja v a 2s . com*/ * With url template: http://test.com/resource/(urn:${resourceId})/entities/(entity:${entityId}), * keys: { "resourceId": 123, "entityId": 456 }, queryParams: { "locale": "en_US" }, the outpuT URI is: * http://test.com/resource/(urn:123)/entities/(entity:456)?locale=en_US * </p> * * @param urlTemplate url template * @param keys data map to interpolate url template * @param queryParams query parameters added to the url * @return a uri */ public static URI buildURI(String urlTemplate, Map<String, String> keys, Map<String, String> queryParams) { // Compute base url String url = urlTemplate; if (keys != null && keys.size() != 0) { url = StrSubstitutor.replace(urlTemplate, keys); } try { URIBuilder uriBuilder = new URIBuilder(url); // Append query parameters if (queryParams != null && queryParams.size() != 0) { for (Map.Entry<String, String> entry : queryParams.entrySet()) { uriBuilder.addParameter(entry.getKey(), entry.getValue()); } } return uriBuilder.build(); } catch (URISyntaxException e) { throw new RuntimeException("Fail to build uri", e); } }
From source file:org.wso2.carbon.identity.captcha.util.CaptchaUtil.java
public static String getErrorPage(String status, String statusMsg) { try {// w ww. jav a 2s . c o m URIBuilder uriBuilder = new URIBuilder(CaptchaConstants.ERROR_PAGE); uriBuilder.addParameter("status", status); uriBuilder.addParameter("statusMsg", statusMsg); return uriBuilder.build().toString(); } catch (URISyntaxException e) { if (log.isDebugEnabled()) { log.debug("Error occurred while building URL.", e); } return CaptchaConstants.ERROR_PAGE; } }
From source file:org.wso2.carbon.identity.captcha.util.CaptchaUtil.java
public static String getUpdatedUrl(String url, Map<String, String> attributes) { try {/* w w w.j a va 2 s . c om*/ URIBuilder uriBuilder = new URIBuilder(url); for (Map.Entry<String, String> entry : attributes.entrySet()) { uriBuilder.addParameter(entry.getKey(), entry.getValue()); } return uriBuilder.build().toString(); } catch (URISyntaxException e) { if (log.isDebugEnabled()) { log.debug("Error occurred while building URL.", e); } return url; } }
From source file:com.mxhero.plugin.cloudstorage.onedrive.api.OneDrive.java
/** * Business email.//from ww w. j av a2 s . com * * @param accessToken the access token * @return the string */ @SuppressWarnings("unchecked") private static String businessEmail(String accessToken) { try { URIBuilder builder = new URIBuilder(ApiEnviroment.graphApiUrl.getValue() + "me"); builder.addParameter("api-version", "1.6"); HttpGet httpGet = new HttpGet(builder.toString()); httpGet.setHeader("Authorization", "Bearer " + accessToken); HttpResponse response = HttpClientBuilder.create().build().execute(httpGet); if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) { Map<String, Object> responseObject = (Map<String, Object>) OneDrive.JACKSON .readValue(EntityUtils.toString(response.getEntity()), Map.class); if (responseObject.containsKey("userPrincipalName")) { return (String) responseObject.get("userPrincipalName"); } else { return (String) responseObject.get("mail"); } } throw new RuntimeException( "error reading response with code " + response.getStatusLine().getStatusCode()); } catch (Exception e) { throw new RuntimeException(e); } }
From source file:de.ii.xtraplatform.ogc.api.CSW.java
public static String cleanUrl(String url) { try {//from w ww.j a v a2s. c o m URI inUri = new URI(url.trim()); URIBuilder outUri = new URIBuilder(inUri).removeQuery(); if (inUri.getQuery() != null && !inUri.getQuery().isEmpty()) { for (String inParam : inUri.getQuery().split("&")) { String[] param = inParam.split("="); if (!CSW.hasKVPKey(param[0].toUpperCase())) { outUri.addParameter(param[0], param[1]); } } } return outUri.toString(); } catch (URISyntaxException ex) { return url; } }
From source file:com.hp.autonomy.hod.client.api.authentication.SignedRequest.java
static SignedRequest sign(final Hmac hmac, final String endpoint, final AuthenticationToken<?, TokenType.HmacSha1> token, final Request<String, String> request) { final URIBuilder uriBuilder; try {// w ww .j av a 2s .co m uriBuilder = new URIBuilder(endpoint + request.getPath()); } catch (final URISyntaxException e) { throw new IllegalArgumentException("Invalid endpoint or request path"); } if (request.getQueryParameters() != null) { for (final Map.Entry<String, List<String>> entry : request.getQueryParameters().entrySet()) { for (final String value : entry.getValue()) { uriBuilder.addParameter(entry.getKey(), value); } } } final String bodyString; if (request.getBody() == null) { bodyString = null; } else { final List<NameValuePair> pairs = new LinkedList<>(); for (final Map.Entry<String, List<String>> entry : request.getBody().entrySet()) { pairs.addAll(entry.getValue().stream().map(value -> new BasicNameValuePair(entry.getKey(), value)) .collect(Collectors.toList())); } bodyString = URLEncodedUtils.format(pairs, UTF8); } final String tokenString = hmac.generateToken(request, token); return new SignedRequest(uriBuilder.toString(), request.getVerb(), bodyString, tokenString); }
From source file:org.nebula.framework.client.NebulaRestClient.java
private static String buildQueryString(Object object) throws Exception { Map<String, Object> map = convertValue(object, Map.class); URIBuilder builder = new URIBuilder(); for (String key : map.keySet()) { Object value = map.get(key); if (value == null) { continue; } else if (value instanceof List) { List v = (List) value; for (int i = 0; i < v.size(); i++) { builder.addParameter(key + "[" + i + "]", v.get(i).toString()); }/*from w w w . j a v a2 s.c o m*/ } else { builder.addParameter(key, map.get(key).toString()); } } return builder.build().toString(); }
From source file:com.ibm.watson.movieapp.dialog.rest.SearchTheMovieDbProxyResource.java
/** * Builds the URI from the URI parameter hash * <p>// w w w . j a va 2s. c o m * This will append each of the {key, value} pairs in uriParamsHash to the URI. * * @param uriParamsHash the hashtable containing parameters to be added to the URI for making the call to TMDB * @return URI for making the HTTP call to TMDB API * @throws URISyntaxException if the uri being built is in the incorrect format */ private static URI buildUriStringFromParamsHash(Hashtable<String, String> uriParamsHash, String path) throws URISyntaxException { URIBuilder urib = new URIBuilder(); urib.setScheme("http"); //$NON-NLS-1$ urib.setHost(TMDB_BASE_URL); urib.setPath(path); urib.addParameter("api_key", themoviedbapikey); //$NON-NLS-1$ if (uriParamsHash != null) { Set<String> keys = uriParamsHash.keySet(); for (String key : keys) { urib.addParameter(key, uriParamsHash.get(key)); } } return urib.build(); }
From source file:de.ii.xtraplatform.ogc.api.WFS.java
public static String cleanUrl(String url) { try {/*from www . j ava 2 s . c om*/ URI inUri = new URI(url.trim()); URIBuilder outUri = new URIBuilder(inUri).removeQuery(); if (inUri.getQuery() != null && !inUri.getQuery().isEmpty()) { for (String inParam : inUri.getQuery().split("&")) { String[] param = inParam.split("="); if (!WFS.hasKVPKey(param[0].toUpperCase())) { if (param.length >= 2) outUri.addParameter(param[0], param[1]); else System.out.println("SINGLE " + param[0]); } } } return outUri.toString(); } catch (URISyntaxException ex) { return url; } }