org.apache.http.client.utils.URIBuilder.setPath()方法的使用及代码示例

x33g5p2x  于2022-01-31 转载在 其他  
字(11.7k)|赞(0)|评价(0)|浏览(158)

本文整理了Java中org.apache.http.client.utils.URIBuilder.setPath()方法的一些代码示例,展示了URIBuilder.setPath()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。URIBuilder.setPath()方法的具体详情如下:
包路径:org.apache.http.client.utils.URIBuilder
类名称:URIBuilder
方法名:setPath

URIBuilder.setPath介绍

[英]Sets URI path. The value is expected to be unescaped and may contain non ASCII characters.
[中]设置URI路径。该值应为不可替换的,并且可能包含非ASCII字符。

代码示例

代码示例来源:origin: gocd/gocd

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();
}

代码示例来源:origin: spotify/helios

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);
 }
}

代码示例来源:origin: apache/incubator-gobblin

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();
}

代码示例来源:origin: alibaba/Sentinel

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);
  }
}

代码示例来源:origin: BroadleafCommerce/BroadleafCommerce

/**
 * 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;
  }
}

代码示例来源:origin: ninjaframework/ninja

private URIBuilder build(String relativePath, Map<String, String> parameters) {
  URIBuilder uriBuilder =
      new URIBuilder(ninjaTestServer.getServerAddressAsUri()).setPath(relativePath);
  addParametersToURI(parameters, uriBuilder);
  return uriBuilder;
}

代码示例来源:origin: alibaba/Sentinel

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);
  }
}

代码示例来源:origin: google/data-transfer-project

@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);
 }
}

代码示例来源:origin: hugegraph/hugegraph

/**
 * 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);
  }
}

代码示例来源:origin: apache/storm

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());

代码示例来源:origin: apache/cloudstack

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);
    }
  }
}

代码示例来源:origin: hugegraph/hugegraph

/**
 * 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());
}

代码示例来源:origin: alibaba/Sentinel

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);
    }
  }
}

代码示例来源:origin: org.restcomm/restcomm-connect.provisioning.number.bandwidth

private String buildDisconnectsUri() throws URISyntaxException {
  URIBuilder builder = new URIBuilder(this.uri);
  builder.setPath("/v1.0/accounts/" + this.accountId + "/disconnects");
  return builder.build().toString();
}

代码示例来源:origin: alibaba/Sentinel

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);
  }
}

代码示例来源:origin: org.restcomm/restcomm-connect.provisioning.number.bandwidth

private String buildOrdersUri() throws URISyntaxException {
  URIBuilder builder = new URIBuilder(this.uri);
  builder.setPath("/v1.0/accounts/" + this.accountId + "/orders");
  return builder.build().toString();
}

代码示例来源:origin: alibaba/Sentinel

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);
  }
}

代码示例来源:origin: com.lyncode/testy-http

String build (String baseUrl) {
    try {
      return new URIBuilder(baseUrl)
          .setPath(path)
          .setParameters(parameters)
          .build()
          .toString();
    } catch (URISyntaxException e) {
      throw new RuntimeException(e);
    }
  }
}

代码示例来源:origin: alibaba/Sentinel

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);
  }
}

代码示例来源:origin: com.ibm.devops/ibm-cloud-devops

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();
}

相关文章