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 MySqlJdbcUrl() { builder = new URIBuilder(); builder.setScheme("mysql"); }
public String urlFor(String path) throws URISyntaxException { URIBuilder baseUri = new URIBuilder(baseUrl); String originalPath = baseUri.getPath(); if (originalPath == null) { originalPath = ""; } if (originalPath.endsWith(DELIMITER) && path.startsWith(DELIMITER)) { path = path.replaceFirst(DELIMITER, ""); } return baseUri.setPath(originalPath + path).toString(); }
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());
private URIBuilder build(String relativePath, Map<String, String> parameters) { URIBuilder uriBuilder = new URIBuilder(ninjaTestServer.getServerAddressAsUri()).setPath(relativePath); addParametersToURI(parameters, uriBuilder); return uriBuilder; }
public Client() { reqURIBuild = new URIBuilder(); reqURIBuild.setScheme("http"); httpclient = HttpClients.createDefault(); context = new BasicHttpContext(); cookie = null; }
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); } }
/** * Connect DB without specified database */ private Connection openWithoutDB(int timeout) { String jdbcUrl = this.config.get(MysqlOptions.JDBC_URL); String url = new URIBuilder().setPath(jdbcUrl) .setParameter("socketTimeout", String.valueOf(timeout)) .toString(); try { return connect(url); } catch (SQLException e) { throw new BackendException("Failed to access %s, " + "please ensure it is ok", jdbcUrl); } }
public String sslServerUrl(String sslPort) { String serverUrl = serverUrl(); try { // backward compatibility, since the agent.jar requires an ssl url, but the old bootstrapper does not have one. URIBuilder url = new URIBuilder(serverUrl); if (url.getScheme().equals("http")) { url.setPort(Integer.valueOf(sslPort)); url.setScheme("https"); } return url.toString(); } catch (URISyntaxException e) { throw bomb(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; } }