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

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

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

URIBuilder.<init>介绍

[英]Constructs an empty instance.
[中]构造一个空实例。

代码示例

代码示例来源:origin: stackoverflow.com

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

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

private MySqlJdbcUrl() {
 builder = new URIBuilder();
 builder.setScheme("mysql");
}

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

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

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

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

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

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

代码示例来源: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: stackoverflow.com

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

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

public Client() {
 reqURIBuild = new URIBuilder();
 reqURIBuild.setScheme("http");
 httpclient = HttpClients.createDefault();
 context = new BasicHttpContext();
 cookie = null;
}

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

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

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

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

  }
}

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

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

相关文章