本文整理了Java中org.apache.http.client.utils.URIBuilder.getPath()
方法的一些代码示例,展示了URIBuilder.getPath()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。URIBuilder.getPath()
方法的具体详情如下:
包路径:org.apache.http.client.utils.URIBuilder
类名称:URIBuilder
方法名:getPath
暂无
代码示例来源: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: 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: gocd/gocd
public HttpRequestBuilder withPath(String path) {
try {
URIBuilder uri = new URIBuilder(path);
request.setServerName("test.host");
request.setContextPath(CONTEXT_PATH);
request.setParameters(splitQuery(uri));
request.setRequestURI(CONTEXT_PATH + uri.getPath());
request.setServletPath(uri.getPath());
if (!uri.getQueryParams().isEmpty()) {
request.setQueryString(URLEncodedUtils.format(uri.getQueryParams(), UTF_8));
}
return this;
} catch (Exception e) {
throw new RuntimeException(e);
}
}
代码示例来源:origin: stackoverflow.com
URIBuilder uriBuilder = new URIBuilder("http://example.com/test");
URI uri = uriBuilder.setPath(uriBuilder.getPath() + "/path/to/add")
.build()
.normalize();
// expected : http://example.com/test/path/to/add
代码示例来源:origin: com.intuit.karate/karate-apache
@Override
protected void buildPath(String path) {
String temp = uriBuilder.getPath();
if (!temp.endsWith("/")) {
temp = temp + "/";
}
if (path.startsWith("/")) {
path = path.substring(1);
}
uriBuilder.setPath(temp + path);
build();
}
代码示例来源:origin: stackoverflow.com
String url = "http://example.com/test";
URIBuilder builder = new URIBuilder(url);
builder.setPath((builder.getPath() + "///example").replaceAll("//+", "/"));
System.out.println("Result 2 -> " + builder.toString());
代码示例来源:origin: stackoverflow.com
String url = "http://example.com/test";
URIBuilder builder = new URIBuilder(url);
builder.setPath((builder.getPath() + "/example").replaceAll("//+", "/"));
System.out.println("Result 1 -> " + builder.toString());
代码示例来源:origin: com.sdl.dxa/dxa-common
/**
* Replaces the path in a given URL with a given path.
*
* @param currentUrl url to change
* @param newPath path to replace the old path with
* @return full URL of current request with given path appended
*/
@Contract("_, _ -> !null")
@SneakyThrows(URISyntaxException.class)
public static String replaceContextPath(@NotNull String currentUrl, @NotNull String newPath) {
String pathToSet = new URIBuilder(newPath).getPath();
return new URIBuilder(currentUrl)
.setPath(pathToSet.startsWith("/") ? pathToSet : ("/" + pathToSet))
.build().toString();
}
}
代码示例来源:origin: rcarz/jira-client
/**
* Build a URI from a path and query parmeters.
*
* @param path Path to append to the base URI
* @param params Map of key value pairs
*
* @return the full URI
*
* @throws URISyntaxException when the path is invalid
*/
public URI buildURI(String path, Map<String, String> params) throws URISyntaxException {
URIBuilder ub = new URIBuilder(uri);
ub.setPath(ub.getPath() + path);
if (params != null) {
for (Map.Entry<String, String> ent : params.entrySet())
ub.addParameter(ent.getKey(), ent.getValue());
}
return ub.build();
}
代码示例来源:origin: opencb/opencga
private void setHost(BenchmarkCommandOptions.VariantBenchmarkCommandOptions options) throws URISyntaxException {
URIBuilder uriBuilder = null;
String host = options.host;
if (host == null) {
uriBuilder = new URIBuilder(configuration.getBenchmark().getRest());
} else {
uriBuilder = new URIBuilder(host);
}
String storageRest = commandOptions.commonCommandOptions.params.get("storage.rest");
if (StringUtils.isNotEmpty(storageRest) && storageRest.equals("true")) {
uriBuilder.setPath(uriBuilder.getPath().concat(VariantStorageEngineRestSampler.STORAGE_REST_PATH));
} else {
uriBuilder.setPath(uriBuilder.getPath().concat(VariantStorageEngineRestSampler.REST_PATH));
}
configuration.getBenchmark().setRest(new URI(uriBuilder.toString()));
}
代码示例来源:origin: ibinti/bugvm
/**
* @since 4.1
*/
protected URI createLocationURI(final String location) throws ProtocolException {
try {
final URIBuilder b = new URIBuilder(new URI(location).normalize());
final String host = b.getHost();
if (host != null) {
b.setHost(host.toLowerCase(Locale.ROOT));
}
final String path = b.getPath();
if (TextUtils.isEmpty(path)) {
b.setPath("/");
}
return b.build();
} catch (final URISyntaxException ex) {
throw new ProtocolException("Invalid redirect URI: " + location, ex);
}
}
代码示例来源:origin: org.apache.httpcomponents/httpclient-android
/**
* @since 4.1
*/
protected URI createLocationURI(final String location) throws ProtocolException {
try {
final URIBuilder b = new URIBuilder(new URI(location).normalize());
final String host = b.getHost();
if (host != null) {
b.setHost(host.toLowerCase(Locale.ENGLISH));
}
final String path = b.getPath();
if (TextUtils.isEmpty(path)) {
b.setPath("/");
}
return b.build();
} catch (final URISyntaxException ex) {
throw new ProtocolException("Invalid redirect URI: " + location, ex);
}
}
代码示例来源:origin: sedmelluq/lavaplayer
private static UrlInfo getUrlInfo(String url, boolean retryValidPart) {
try {
if (!url.startsWith("http://") && !url.startsWith("https://")) {
url = "https://" + url;
}
URIBuilder builder = new URIBuilder(url);
return new UrlInfo(builder.getPath(), builder.getQueryParams().stream()
.filter(it -> it.getValue() != null)
.collect(Collectors.toMap(NameValuePair::getName, NameValuePair::getValue)));
} catch (URISyntaxException e) {
if (retryValidPart) {
return getUrlInfo(url.substring(0, e.getIndex() - 1), false);
} else {
throw new FriendlyException("Not a valid URL: " + url, COMMON, e);
}
}
}
代码示例来源:origin: com.bugvm/bugvm-rt
/**
* @since 4.1
*/
protected URI createLocationURI(final String location) throws ProtocolException {
try {
final URIBuilder b = new URIBuilder(new URI(location).normalize());
final String host = b.getHost();
if (host != null) {
b.setHost(host.toLowerCase(Locale.ROOT));
}
final String path = b.getPath();
if (TextUtils.isEmpty(path)) {
b.setPath("/");
}
return b.build();
} catch (final URISyntaxException ex) {
throw new ProtocolException("Invalid redirect URI: " + location, ex);
}
}
代码示例来源:origin: org.apache.marmotta/marmotta-client-java
public static HttpPost createPost(String path, ClientConfiguration config) throws URISyntaxException {
final URIBuilder uriBuilder = new URIBuilder(config.getMarmottaUri());
uriBuilder.setPath(uriBuilder.getPath() + path);
if (StringUtils.isNotBlank(config.getMarmottaContext())) {
uriBuilder.addParameter(CONTEXT, config.getMarmottaContext());
}
final HttpPost post = new HttpPost(uriBuilder.build());
if (StringUtils.isNotBlank(config.getMarmottaUser())) {
final String credentials = String.format("%s:%s", config.getMarmottaUser(), config.getMarmottaPassword());
try {
final String encoded = DatatypeConverter.printBase64Binary(credentials.getBytes("UTF-8"));
post.setHeader("Authorization", String.format("Basic %s", encoded));
} catch (UnsupportedEncodingException e) {
System.err.println("Error encoding credentials: " + e.getMessage());
}
}
return post;
}
代码示例来源:origin: org.apache.hadoop/hadoop-azure
@Override
public long renewDelegationToken(Token<?> token)
throws IOException {
URIBuilder uriBuilder =
new URIBuilder().setPath(DEFAULT_DELEGATION_TOKEN_MANAGER_ENDPOINT)
.addParameter(OP_PARAM_KEY_NAME, RENEW_DELEGATION_TOKEN_OP)
.addParameter(TOKEN_PARAM_KEY_NAME, token.encodeToUrlString());
String responseBody = remoteCallHelper
.makeRemoteRequest(dtServiceUrls, uriBuilder.getPath(),
uriBuilder.getQueryParams(), HttpPut.METHOD_NAME);
Map<?, ?> parsedResp = JsonUtils.parse(responseBody);
return ((Number) parsedResp.get("long")).longValue();
}
代码示例来源:origin: org.apache.hadoop/hadoop-azure
@Override
public void cancelDelegationToken(Token<?> token)
throws IOException {
URIBuilder uriBuilder =
new URIBuilder().setPath(DEFAULT_DELEGATION_TOKEN_MANAGER_ENDPOINT)
.addParameter(OP_PARAM_KEY_NAME, CANCEL_DELEGATION_TOKEN_OP)
.addParameter(TOKEN_PARAM_KEY_NAME, token.encodeToUrlString());
remoteCallHelper.makeRemoteRequest(dtServiceUrls, uriBuilder.getPath(),
uriBuilder.getQueryParams(), HttpPut.METHOD_NAME);
}
}
代码示例来源:origin: org.apache.hadoop/hadoop-azure
private String fullUriString(String relativePath, boolean withTrailingSlash) {
String baseUri = this.baseUri;
if (!baseUri.endsWith("/")) {
baseUri += "/";
}
if (withTrailingSlash && !relativePath.equals("")
&& !relativePath.endsWith("/")) {
relativePath += "/";
}
try {
URIBuilder builder = new URIBuilder(baseUri);
return builder.setPath(builder.getPath() + relativePath).toString();
} catch (URISyntaxException e) {
throw new RuntimeException("problem encoding fullUri", e);
}
}
}
代码示例来源:origin: org.apache.hadoop/hadoop-azure
@Override
public Token<DelegationTokenIdentifier> getDelegationToken(
String renewer) throws IOException {
URIBuilder uriBuilder =
new URIBuilder().setPath(DEFAULT_DELEGATION_TOKEN_MANAGER_ENDPOINT)
.addParameter(OP_PARAM_KEY_NAME, GET_DELEGATION_TOKEN_OP)
.addParameter(RENEWER_PARAM_KEY_NAME, renewer)
.addParameter(SERVICE_PARAM_KEY_NAME,
WASB_DT_SERVICE_NAME.toString());
String responseBody = remoteCallHelper
.makeRemoteRequest(dtServiceUrls, uriBuilder.getPath(),
uriBuilder.getQueryParams(), HttpGet.METHOD_NAME);
return TokenUtils.toDelegationToken(JsonUtils.parse(responseBody));
}
代码示例来源:origin: org.apache.apex/apex-engine
@Override
public ClientResponse handle(ClientRequest cr) throws ClientHandlerException
{
URIBuilder uriBuilder = new URIBuilder(cr.getURI());
String path = uriBuilder.getPath();
uriBuilder.setPath(converter.convertCommandPath(path));
try {
cr.setURI(uriBuilder.build());
ClientResponse response = getNext().handle(cr);
String newEntity = converter.convertResponse(path, response.getEntity(String.class));
response.setEntityInputStream(new ByteArrayInputStream(newEntity.getBytes()));
return response;
} catch (Exception ex) {
throw new ClientHandlerException(ex);
}
}
内容来源于网络,如有侵权,请联系作者删除!