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

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

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

URIBuilder.setParameter介绍

[英]Sets parameter of URI query overriding existing value if set. The parameter name and value are expected to be unescaped and may contain non ASCII characters.

Please note query parameters and custom query component are mutually exclusive. This method will remove custom query if present.
[中]设置URI查询的参数,如果设置,则覆盖现有值。参数名称和值应为非scaped,并且可能包含非ASCII字符。
请注意,查询参数和自定义查询组件是互斥的。此方法将删除自定义查询(如果存在)。

代码示例

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

public MySqlJdbcUrl setParameter(String param, String value) {
 builder.setParameter(param, value);
 return this;
}

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

private void addParametersToURI(Map<String, String> parameters, URIBuilder uriBuilder) {
  if (parameters != null) {
    for (Entry<String, String> param : parameters.entrySet()) {
      uriBuilder.setParameter(param.getKey(), param.getValue());
    }
  }
}

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

/**
 * Set the value of a session attribute on the server
 */
public Response set(String key, String value, boolean storeRespCookie)
  throws IOException, URISyntaxException {
 resetURI();
 reqURIBuild.setParameter("cmd", QueryCommand.SET.name());
 reqURIBuild.setParameter("param", key);
 reqURIBuild.setParameter("value", value);
 return doRequest(new HttpGet(reqURIBuild.build()), storeRespCookie);
}

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

/**
 * Invalidate this clients session on the server
 */
public Response invalidate(boolean storeRespCookie) throws IOException, URISyntaxException {
 resetURI();
 reqURIBuild.setParameter("cmd", QueryCommand.INVALIDATE.name());
 reqURIBuild.setParameter("param", "null");
 return doRequest(new HttpGet(reqURIBuild.build()), storeRespCookie);
}

代码示例来源: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: apache/geode

/**
 * Instantiate and execute a function in the server. Note that this function must be present in
 * the sesssion testing war.
 */
public Response executionFunction(
  Class<? extends Function<HttpServletRequest, String>> functionClass)
  throws IOException, URISyntaxException {
 resetURI();
 reqURIBuild.setParameter("cmd", QueryCommand.FUNCTION.name());
 reqURIBuild.setParameter("function", functionClass.getName());
 return doRequest(new HttpGet(reqURIBuild.build()), true);
}

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

@Override
public boolean sendHeartbeat() throws Exception {
  if (StringUtil.isEmpty(consoleHost)) {
    return false;
  }
  URIBuilder uriBuilder = new URIBuilder();
  uriBuilder.setScheme("http").setHost(consoleHost).setPort(consolePort)
    .setPath("/registry/machine")
    .setParameter("app", AppNameUtil.getAppName())
    .setParameter("v", Constants.SENTINEL_VERSION)
    .setParameter("version", String.valueOf(System.currentTimeMillis()))
    .setParameter("hostname", HostNameUtil.getHostName())
    .setParameter("ip", TransportConfig.getHeartbeatClientIp())
    .setParameter("port", TransportConfig.getPort())
    .setParameter("pid", String.valueOf(PidUtil.getPid()));
  HttpGet request = new HttpGet(uriBuilder.build());
  request.setConfig(requestConfig);
  // Send heartbeat request.
  CloseableHttpResponse response = client.execute(request);
  response.close();
  return true;
}

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

/**
 * Get the value of a session attribute on the server
 */
public Response get(String key, boolean storeRespCookie) throws IOException, URISyntaxException {
 resetURI();
 reqURIBuild.setParameter("cmd", QueryCommand.GET.name());
 reqURIBuild.setParameter("param", key);
 return doRequest(new HttpGet(reqURIBuild.build()), storeRespCookie);
}

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

/**
 * Remove the session attribute on the server
 *
 * @param key - the session attribute to remove
 * @param storeRespCookie - whether or not to store the session cookie of this request
 */
public Response remove(String key, boolean storeRespCookie)
  throws URISyntaxException, IOException {
 resetURI();
 reqURIBuild.setParameter("cmd", QueryCommand.REMOVE.name());
 reqURIBuild.setParameter("param", key);
 return doRequest(new HttpGet(reqURIBuild.build()), storeRespCookie);
}

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

/**
 * Set the maximum inactive interval for this client's session on the server.
 *
 * If this time interval elapses without activity on the session, the session will expire.
 *
 * @param time - Time in seconds until the session should expire
 */
public Response setMaxInactive(int time, boolean storeRespCookie)
  throws IOException, URISyntaxException {
 resetURI();
 reqURIBuild.setParameter("cmd", QueryCommand.SET_MAX_INACTIVE.name());
 reqURIBuild.setParameter("value", Integer.toString(time));
 return doRequest(new HttpGet(reqURIBuild.build()), storeRespCookie);
}

代码示例来源: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: 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<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: alibaba/Sentinel

public CompletableFuture<Void> modifyClusterServerTransportConfig(String app, String ip, int port, ServerTransportConfig 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_TRANSPORT_CONFIG_PATH)
      .setParameter("port", config.getPort().toString())
      .setParameter("idleSeconds", config.getIdleSeconds().toString());
    return executeCommand(MODIFY_CLUSTER_SERVER_TRANSPORT_CONFIG_PATH, uriBuilder.build())
      .thenCompose(e -> {
        if (CommandConstants.MSG_SUCCESS.equals(e)) {
          return CompletableFuture.completedFuture(null);
        } else {
          logger.warn("Error when modifying cluster server transport config: " + e);
          return AsyncUtils.newFailedFuture(new RuntimeException(e));
        }
      });
  } catch (Exception ex) {
    logger.warn("Error when modifying cluster server transport config", ex);
    return AsyncUtils.newFailedFuture(ex);
  }
}

代码示例来源: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: 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: alibaba/Sentinel

public CompletableFuture<Void> modifyClusterMode(String app, String ip, int port, int mode) {
  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_MODE_PATH)
      .setParameter("mode", String.valueOf(mode));
    return executeCommand(MODIFY_CLUSTER_MODE_PATH, uriBuilder.build())
      .thenCompose(e -> {
        if (CommandConstants.MSG_SUCCESS.equals(e)) {
          return CompletableFuture.completedFuture(null);
        } else {
          logger.warn("Error when modifying cluster mode: " + e);
          return AsyncUtils.newFailedFuture(new RuntimeException(e));
        }
      });
  } catch (Exception ex) {
    logger.warn("Error when modifying cluster mode", ex);
    return AsyncUtils.newFailedFuture(ex);
  }
}

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

public CompletableFuture<Void> modifyClusterClientConfig(String app, String ip, int port, ClusterClientConfig 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_CLIENT_CONFIG_PATH)
      .setParameter("data", JSON.toJSONString(config));
    return executeCommand(MODIFY_CLUSTER_MODE_PATH, uriBuilder.build())
      .thenCompose(e -> {
        if (CommandConstants.MSG_SUCCESS.equals(e)) {
          return CompletableFuture.completedFuture(null);
        } else {
          logger.warn("Error when modifying cluster client config: " + e);
          return AsyncUtils.newFailedFuture(new RuntimeException(e));
        }
      });
  } catch (Exception ex) {
    logger.warn("Error when modifying cluster client config", ex);
    return AsyncUtils.newFailedFuture(ex);
  }
}

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

uriBuilder.setScheme("http").setHost(ip).setPort(port)
  .setPath(GET_RULES_PATH)
  .setParameter("type", AUTHORITY_TYPE);
try {
  String body = httpGetContent(uriBuilder.build().toString());

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

/**
 * helper function to build a valid URI.
 *
 * @param host host name.
 * @param port host port.
 * @param path extra path after host.
 * @param isHttp indicates if whether Http or HTTPS should be used.
 * @param params extra query parameters.
 * @return the URI built from the inputs.
 */
public static URI buildUri(final String host, final int port, final String path,
  final boolean isHttp, final Pair<String, String>... params) throws IOException {
 final URIBuilder builder = new URIBuilder();
 builder.setScheme(isHttp ? "http" : "https").setHost(host).setPort(port);
 if (null != path && path.length() > 0) {
  builder.setPath(path);
 }
 if (params != null) {
  for (final Pair<String, String> pair : params) {
   builder.setParameter(pair.getFirst(), pair.getSecond());
  }
 }
 try {
  return builder.build();
 } catch (final URISyntaxException e) {
  throw new IOException(e);
 }
}

相关文章