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); } }
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(); }
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); } }
/** * 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; } }
private URIBuilder build(String relativePath, Map<String, String> parameters) { URIBuilder uriBuilder = new URIBuilder(ninjaTestServer.getServerAddressAsUri()).setPath(relativePath); addParametersToURI(parameters, uriBuilder); return uriBuilder; }
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); } }
@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); } }
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());
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); } } }
/** * Connect DB with specified database */ private Connection open(boolean autoReconnect) throws SQLException { String url = this.config.get(MysqlOptions.JDBC_URL); if (url.endsWith("/")) { url = String.format("%s%s", url, this.database); } else { url = String.format("%s/%s", url, this.database); } int maxTimes = this.config.get(MysqlOptions.JDBC_RECONNECT_MAX_TIMES); int interval = this.config.get(MysqlOptions.JDBC_RECONNECT_INTERVAL); URIBuilder uriBuilder = new URIBuilder(); uriBuilder.setPath(url) .setParameter("rewriteBatchedStatements", "true") .setParameter("useServerPrepStmts", "false") .setParameter("autoReconnect", String.valueOf(autoReconnect)) .setParameter("maxReconnects", String.valueOf(maxTimes)) .setParameter("initialTimeout", String.valueOf(interval)); return this.connect(uriBuilder.toString()); }
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); } } }
private String buildDisconnectsUri() throws URISyntaxException { URIBuilder builder = new URIBuilder(this.uri); builder.setPath("/v1.0/accounts/" + this.accountId + "/disconnects"); return builder.build().toString(); }
public CompletableFuture<Void> modifyClusterServerFlowConfig(String app, String ip, int port, ServerFlowConfig config) { 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(MODIFY_CLUSTER_SERVER_FLOW_CONFIG_PATH) .setParameter("data", JSON.toJSONString(config)); return executeCommand(MODIFY_CLUSTER_SERVER_FLOW_CONFIG_PATH, uriBuilder.build()) .thenCompose(e -> { if (CommandConstants.MSG_SUCCESS.equals(e)) { return CompletableFuture.completedFuture(null); } else { logger.warn("Error when modifying cluster server flow config: " + e); return AsyncUtils.newFailedFuture(new RuntimeException(e)); } }); } catch (Exception ex) { logger.warn("Error when modifying cluster server flow config", ex); return AsyncUtils.newFailedFuture(ex); } }
private String buildOrdersUri() throws URISyntaxException { URIBuilder builder = new URIBuilder(this.uri); builder.setPath("/v1.0/accounts/" + this.accountId + "/orders"); return builder.build().toString(); }
public CompletableFuture<Void> modifyClusterServerNamespaceSet(String app, String ip, int port, Set<String> set) { 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(MODIFY_CLUSTER_SERVER_NAMESPACE_SET_PATH) .setParameter("data", JSON.toJSONString(set)); return executeCommand(MODIFY_CLUSTER_SERVER_NAMESPACE_SET_PATH, uriBuilder.build()) .thenCompose(e -> { if (CommandConstants.MSG_SUCCESS.equals(e)) { return CompletableFuture.completedFuture(null); } else { logger.warn("Error when modifying cluster server NamespaceSet: " + e); return AsyncUtils.newFailedFuture(new RuntimeException(e)); } }); } catch (Exception ex) { logger.warn("Error when modifying cluster server NamespaceSet", ex); return AsyncUtils.newFailedFuture(ex); } }
String build (String baseUrl) { try { return new URIBuilder(baseUrl) .setPath(path) .setParameters(parameters) .build() .toString(); } catch (URISyntaxException e) { throw new RuntimeException(e); } } }
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); } }
public static String getDeploymentRiskUrl(String baseUrl, String toolchainId) throws URISyntaxException { URIBuilder builder = new URIBuilder(baseUrl); builder.setPath(RISK_ANALYSIS_PART); builder.addParameter(TOOLCHAIN_ID_PART, toolchainId); return builder.build().toString(); }