URIBuilder builder = new URIBuilder(); builder.setScheme("http").setHost(host).setPort(port).setPath(restPath + taskUri + "/" + taskId) .setParameter("parts", "all") .setParameter("params", routingOptionsJson) .setParameter("action", "finish"); HttpPost post = getHttpPostMethod(builder.build());
private URI uri(final String path, final Multimap<String, String> query) { checkArgument(path.startsWith("/")); final URIBuilder builder = new URIBuilder() .setScheme("http") .setHost("helios") .setPath(path); for (final Map.Entry<String, String> q : query.entries()) { builder.addParameter(q.getKey(), q.getValue()); } builder.addParameter("user", user); try { return builder.build(); } catch (URISyntaxException e) { throw new RuntimeException(e); } }
public static String addPaginationParam(String url, String paginationParamName, Integer pageNumber) { try { if (pageNumber > 1) { return new URIBuilder(url).addParameter(paginationParamName, String.valueOf(pageNumber)).build().toString(); } } catch (URISyntaxException e) { // If we run into trouble, do nothing - we'll just return the url that we were given. } return url; }
private static String buildUrl(String path, List<NameValuePair> qparams) throws RestApiClientException { URIBuilder builder = new URIBuilder(); builder.setPath(path); ListIterator<NameValuePair> i = qparams.listIterator(); while (i.hasNext()) { NameValuePair keyValue = i.next(); builder.setParameter(keyValue.getName(), keyValue.getValue()); } URI uri; try { uri = builder.build(); } catch (Exception e) { throw new RestApiClientException("Failed to build url; error - " + e.getMessage(), e); } return new HttpGet(uri).getURI().toString(); }
/** * In the case that listening address configured as 0.0.0.0, the publish address will be determined * by the query result for the net interfaces. * * @return the publish address, or {@code null} if the param {@code address} is null. */ public static String getPublishAddress(String schema, String address) { if (address == null) { return address; } try { URI originalURI = new URI(schema + "://" + address); IpPort ipPort = NetUtils.parseIpPort(originalURI); if (ipPort == null) { LOGGER.warn("address {} not valid.", address); return null; } IpPort publishIpPort = genPublishIpPort(schema, ipPort); URIBuilder builder = new URIBuilder(originalURI); return builder.setHost(publishIpPort.getHostOrIp()).setPort(publishIpPort.getPort()).build().toString(); } catch (URISyntaxException e) { LOGGER.warn("address {} not valid.", address); return null; } }
public CompletableFuture<ClusterStateSimpleEntity> fetchClusterMode(String app, String ip, int port) { if (StringUtil.isBlank(ip) || port <= 0) { return AsyncUtils.newFailedFuture(new IllegalArgumentException("Invalid parameter")); } try { URIBuilder uriBuilder = new URIBuilder(); uriBuilder.setScheme("http").setHost(ip).setPort(port) .setPath(FETCH_CLUSTER_MODE_PATH); return executeCommand(FETCH_CLUSTER_MODE_PATH, uriBuilder.build()) .thenApply(r -> JSON.parseObject(r, ClusterStateSimpleEntity.class)); } catch (Exception ex) { logger.warn("Error when fetching cluster mode", ex); return AsyncUtils.newFailedFuture(ex); } }
public static URI createRequestURI(String rootUrl, Map<String, String> query) throws MalformedURLException, URISyntaxException { List<NameValuePair> queryTokens = Lists.newArrayList(); for (Map.Entry<String, String> entry : query.entrySet()) { queryTokens.add(new BasicNameValuePair(entry.getKey(), entry.getValue())); } String encodedQuery = URLEncodedUtils.format(queryTokens, Charsets.UTF_8); URI actualURL = new URIBuilder(rootUrl).setQuery(encodedQuery).build(); return actualURL; }
/** * Adds the fragment to the end of the path and optionally adds an id param depending upon * the value of appendIdToRelativeURI. */ 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; } }
URIBuilder builder = new URIBuilder(); builder.setScheme("http").setHost("www.google.com").setPath("/search") .setParameter("q", "httpclient") .setParameter("btnG", "Google Search") .setParameter("aq", "f") .setParameter("oq", ""); URI uri = builder.build(); HttpGet httpget = new HttpGet(uri); System.out.println(httpget.getURI());
public CompletableFuture<ClusterClientInfoVO> fetchClusterClientInfoAndConfig(String app, String ip, int port) { if (StringUtil.isBlank(ip) || port <= 0) { return AsyncUtils.newFailedFuture(new IllegalArgumentException("Invalid parameter")); } try { URIBuilder uriBuilder = new URIBuilder(); uriBuilder.setScheme("http").setHost(ip).setPort(port) .setPath(FETCH_CLUSTER_CLIENT_CONFIG_PATH); return executeCommand(FETCH_CLUSTER_CLIENT_CONFIG_PATH, uriBuilder.build()) .thenApply(r -> JSON.parseObject(r, ClusterClientInfoVO.class)); } catch (Exception ex) { logger.warn("Error when fetching cluster client config", ex); return AsyncUtils.newFailedFuture(ex); } }
protected String adjustURIForPort(String uri) throws URISyntaxException { URI metadataURI = new URI(uri); if (metadataURI.getPort() < 0) { switch (metadataURI.getScheme()) { case "https": return new URIBuilder(uri).setPort(443).build().toString(); case "http": return new URIBuilder(uri).setPort(80).build().toString(); default: return uri; } } return uri; }
@Override public AuthFlowConfiguration generateConfiguration(String callbackBaseUrl, String id) { String encodedJobId = BaseEncoding.base64Url().encode(id.getBytes(Charsets.UTF_8)); URIBuilder builder = new URIBuilder() .setPath(config.getAuthUrl()) .setParameter("response_type", "code") .setParameter("client_id", clientId) .setParameter("redirect_uri", callbackBaseUrl) .setParameter("scope", String.join(" ", scopes)) .setParameter("state", encodedJobId); if (config.getAdditionalAuthUrlParameters() != null) { for (Entry<String, String> entry : config.getAdditionalAuthUrlParameters().entrySet()) { builder.setParameter(entry.getKey(), entry.getValue()); } } try { String url = builder.build().toString(); return new AuthFlowConfiguration(url, OAUTH_2, getTokenUrl()); } catch (URISyntaxException e) { throw new IllegalStateException("Could not produce url.", e); } }
URIBuilder builder = new URIBuilder().setScheme(scheme).setHost(host).setPort(port); builder.setPath(path); try { LOG.debug("About to issue a GET to {}", builder); HttpGet httpget = new HttpGet(builder.build()); String responseBody; responseBody = httpclient.execute(httpget, GETStringResponseHandler.getInstance());
public String buildLink(String url, Map<String, String[]> params) { URIBuilder builder; try { builder = new URIBuilder(url); if (params != null) { for (String key : params.keySet()) { String[] paramValues = params.get(key); for (String value : paramValues) { builder.addParameter(key, value); } } } return builder.build().toString(); } catch (URISyntaxException e) { LOG.error("Error creating link for breadcrumb ", e); return url; } }
private URI buildUri() { try { final URIBuilder builder = new URIBuilder().setPath(path); for (final Map.Entry<String, String> entry : parameters.entrySet()) { builder.addParameter(entry.getKey(), entry.getValue()); } return builder.build(); } catch (final URISyntaxException e) { throw new IllegalArgumentException("Unable to build REST Service URI", e); } } }
public CompletableFuture<ClusterServerStateVO> fetchClusterServerBasicInfo(String app, String ip, int port) { if (StringUtil.isBlank(ip) || port <= 0) { return AsyncUtils.newFailedFuture(new IllegalArgumentException("Invalid parameter")); } try { URIBuilder uriBuilder = new URIBuilder(); uriBuilder.setScheme("http").setHost(ip).setPort(port) .setPath(FETCH_CLUSTER_SERVER_BASIC_INFO_PATH); return executeCommand(FETCH_CLUSTER_SERVER_BASIC_INFO_PATH, uriBuilder.build()) .thenApply(r -> JSON.parseObject(r, ClusterServerStateVO.class)); } catch (Exception ex) { logger.warn("Error when fetching cluster sever all config and basic info", ex); return AsyncUtils.newFailedFuture(ex); } } }
builder.setMaxConnTotal(100); CloseableHttpClient httpclient = builder.build(); URI uri = new URIBuilder(url).build(); RequestConfig config = custom().setConnectTimeout(timeout) .setConnectionRequestTimeout(timeout)
public static String httpGetRequest(String url, Map<String, Object> headers, Map<String, Object> params) throws URISyntaxException { URIBuilder ub = new URIBuilder(); ub.setPath(url); ArrayList<NameValuePair> pairs = covertParams2NVPS(params); ub.setParameters(pairs); HttpGet httpGet = new HttpGet(ub.build()); for (Map.Entry<String, Object> param : headers.entrySet()) { httpGet.addHeader(param.getKey(), String.valueOf(param.getValue())); } return getResult(httpGet); }
public CompletableFuture<Void> setParamFlowRuleOfMachine(String app, String ip, int port, List<ParamFlowRuleEntity> rules) { if (rules == null) { return CompletableFuture.completedFuture(null); } if (StringUtil.isBlank(ip) || port <= 0) { return AsyncUtils.newFailedFuture(new IllegalArgumentException("Invalid parameter")); } try { String data = JSON.toJSONString( rules.stream().map(ParamFlowRuleEntity::getRule).collect(Collectors.toList()) ); data = URLEncoder.encode(data, DEFAULT_CHARSET.name()); URIBuilder uriBuilder = new URIBuilder(); uriBuilder.setScheme("http").setHost(ip).setPort(port) .setPath(SET_PARAM_RULE_PATH) .setParameter("data", data); return executeCommand(SET_PARAM_RULE_PATH, uriBuilder.build()) .thenCompose(e -> { if (CommandConstants.MSG_SUCCESS.equals(e)) { return CompletableFuture.completedFuture(null); } else { logger.warn("Push parameter flow rules to client failed: " + e); return AsyncUtils.newFailedFuture(new RuntimeException(e)); } }); } catch (Exception ex) { logger.warn("Error when setting parameter flow rule", ex); return AsyncUtils.newFailedFuture(ex); } }
URIBuilder b = new URIBuilder("http://example.com"); b.addParameter("t", "search"); b.addParameter("q", "apples"); Url url = b.build().toUrl();