本文整理了Java中com.ning.http.client.uri.Uri.getPath()
方法的一些代码示例,展示了Uri.getPath()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Uri.getPath()
方法的具体详情如下:
包路径:com.ning.http.client.uri.Uri
类名称:Uri
方法名:getPath
暂无
代码示例来源:origin: com.ning/async-http-client
/**
* Convenient for HTTP layer when targeting server root
*
* @return the raw path or "/" if it's null
*/
public final static String getNonEmptyPath(Uri uri) {
return isNonEmpty(uri.getPath()) ? uri.getPath() : "/";
}
代码示例来源:origin: com.ning/async-http-client
private String baseUrl(Uri uri) {
/* 07-Oct-2010, tatu: URL may contain default port number; if so, need to extract
* from base URL.
*/
String scheme = uri.getScheme();
StringBuilder sb = StringUtils.stringBuilder();
sb.append(scheme).append("://").append(uri.getHost());
int port = uri.getPort();
if (scheme.equals("http")) {
if (port == 80)
port = -1;
} else if (scheme.equals("https")) {
if (port == 443)
port = -1;
}
if (port != -1)
sb.append(':').append(port);
if (isNonEmpty(uri.getPath()))
sb.append(uri.getPath());
return sb.toString();
}
代码示例来源:origin: com.ning/async-http-client
private boolean overrideWithContext(Uri context, String originalUrl) {
boolean isRelative = false;
// only use context if the schemes match
if (context != null && (scheme == null || scheme.equalsIgnoreCase(context.getScheme()))) {
// see RFC2396 5.2.3
String contextPath = context.getPath();
if (isNotEmpty(contextPath) && contextPath.charAt(0) == '/')
scheme = null;
if (scheme == null) {
scheme = context.getScheme();
userInfo = context.getUserInfo();
host = context.getHost();
port = context.getPort();
path = contextPath;
isRelative = true;
}
}
return isRelative;
}
代码示例来源:origin: com.ning/async-http-client
public Uri encode(Uri uri, List<Param> queryParams) {
String newPath = encodePath(uri.getPath());
String newQuery = encodeQuery(uri.getQuery(), queryParams);
return new Uri(uri.getScheme(),//
uri.getUserInfo(),//
uri.getHost(),//
uri.getPort(),//
newPath,//
newQuery);
}
代码示例来源:origin: org.glassfish.grizzly/grizzly-http-client
/**
* Convenient for HTTP layer when targeting server root
*
* @return the raw path or "/" if it's null
*/
public final static String getNonEmptyPath(Uri uri) {
return isNonEmpty(uri.getPath()) ? uri.getPath() : "/";
}
代码示例来源:origin: javaee/grizzly-ahc
/**
* Convenient for HTTP layer when targeting server root
*
* @return the raw path or "/" if it's null
*/
public final static String getNonEmptyPath(Uri uri) {
return isNonEmpty(uri.getPath()) ? uri.getPath() : "/";
}
代码示例来源:origin: javaee/grizzly-ahc
@Test
public void testRelativeUriWithConsecutiveDotsFromRoot() {
Uri context = Uri.create("https://hello.com/");
Uri url = Uri.create(context, "../../../other/content/img.png");
assertEquals(url.getScheme(), "https");
assertEquals(url.getHost(), "hello.com");
assertEquals(url.getPort(), -1);
assertEquals(url.getPath(), "/../../../other/content/img.png");
assertNull(url.getQuery());
}
代码示例来源:origin: javaee/grizzly-ahc
@Test
public void testRootRelativeURIWithNonRootContext() {
Uri context = Uri.create("https://graph.facebook.com/foo/bar");
Uri url = Uri.create(context, "/750198471659552/accounts/test-users?method=get&access_token=750198471659552lleveCvbUu_zqBa9tkT3tcgaPh4");
assertEquals(url.getScheme(), "https");
assertEquals(url.getHost(), "graph.facebook.com");
assertEquals(url.getPort(), -1);
assertEquals(url.getPath(), "/750198471659552/accounts/test-users");
assertEquals(url.getQuery(), "method=get&access_token=750198471659552lleveCvbUu_zqBa9tkT3tcgaPh4");
}
代码示例来源:origin: javaee/grizzly-ahc
@Test
public void testNonRootRelativeURIWithNonRootContext() {
Uri context = Uri.create("https://graph.facebook.com/foo/bar");
Uri url = Uri.create(context, "750198471659552/accounts/test-users?method=get&access_token=750198471659552lleveCvbUu_zqBa9tkT3tcgaPh4");
assertEquals(url.getScheme(), "https");
assertEquals(url.getHost(), "graph.facebook.com");
assertEquals(url.getPort(), -1);
assertEquals(url.getPath(), "/foo/750198471659552/accounts/test-users");
assertEquals(url.getQuery(), "method=get&access_token=750198471659552lleveCvbUu_zqBa9tkT3tcgaPh4");
}
代码示例来源:origin: javaee/grizzly-ahc
@Test
public void testSimpleParsing() {
Uri url = Uri.create("https://graph.facebook.com/750198471659552/accounts/test-users?method=get&access_token=750198471659552lleveCvbUu_zqBa9tkT3tcgaPh4");
assertEquals(url.getScheme(), "https");
assertEquals(url.getHost(), "graph.facebook.com");
assertEquals(url.getPort(), -1);
assertEquals(url.getPath(), "/750198471659552/accounts/test-users");
assertEquals(url.getQuery(), "method=get&access_token=750198471659552lleveCvbUu_zqBa9tkT3tcgaPh4");
}
代码示例来源:origin: javaee/grizzly-ahc
@Test
public void testAbsoluteURIWithContext() {
Uri context = Uri.create("https://hello.com/foo/bar");
Uri url = Uri.create(context, "https://graph.facebook.com/750198471659552/accounts/test-users?method=get&access_token=750198471659552lleveCvbUu_zqBa9tkT3tcgaPh4");
assertEquals(url.getScheme(), "https");
assertEquals(url.getHost(), "graph.facebook.com");
assertEquals(url.getPort(), -1);
assertEquals(url.getPath(), "/750198471659552/accounts/test-users");
assertEquals(url.getQuery(), "method=get&access_token=750198471659552lleveCvbUu_zqBa9tkT3tcgaPh4");
}
代码示例来源:origin: javaee/grizzly-ahc
@Test
public void testRelativeUriWithDotsAboveRoot() {
Uri context = Uri.create("https://hello.com/level1");
Uri url = Uri.create(context, "../other/content/img.png");
assertEquals(url.getScheme(), "https");
assertEquals(url.getHost(), "hello.com");
assertEquals(url.getPort(), -1);
assertEquals(url.getPath(), "/../other/content/img.png");
assertNull(url.getQuery());
}
代码示例来源:origin: javaee/grizzly-ahc
@Test
public void testRelativeUriWithConsecutiveDotsFromRootResource() {
Uri context = Uri.create("https://hello.com/level1");
Uri url = Uri.create(context, "../../../other/content/img.png");
assertEquals(url.getScheme(), "https");
assertEquals(url.getHost(), "hello.com");
assertEquals(url.getPort(), -1);
assertEquals(url.getPath(), "/../../../other/content/img.png");
assertNull(url.getQuery());
}
代码示例来源:origin: javaee/grizzly-ahc
@Test
public void testRelativeUriWithDots() {
Uri context = Uri.create("https://hello.com/level1/level2/");
Uri url = Uri.create(context, "../other/content/img.png");
assertEquals(url.getScheme(), "https");
assertEquals(url.getHost(), "hello.com");
assertEquals(url.getPort(), -1);
assertEquals(url.getPath(), "/level1/other/content/img.png");
assertNull(url.getQuery());
}
代码示例来源:origin: javaee/grizzly-ahc
@Test
public void testRelativeUriWithAbsoluteDots() {
Uri context = Uri.create("https://hello.com/level1/");
Uri url = Uri.create(context, "/../other/content/img.png");
assertEquals(url.getScheme(), "https");
assertEquals(url.getHost(), "hello.com");
assertEquals(url.getPort(), -1);
assertEquals(url.getPath(), "/../other/content/img.png");
assertNull(url.getQuery());
}
代码示例来源:origin: javaee/grizzly-ahc
@Test
public void testRelativeUriWithConsecutiveDots() {
Uri context = Uri.create("https://hello.com/level1/level2/");
Uri url = Uri.create(context, "../../other/content/img.png");
assertEquals(url.getScheme(), "https");
assertEquals(url.getHost(), "hello.com");
assertEquals(url.getPort(), -1);
assertEquals(url.getPath(), "/other/content/img.png");
assertNull(url.getQuery());
}
代码示例来源:origin: javaee/grizzly-ahc
@Test
public void testRelativeUriWithConsecutiveDotsAboveRoot() {
Uri context = Uri.create("https://hello.com/level1/level2");
Uri url = Uri.create(context, "../../other/content/img.png");
assertEquals(url.getScheme(), "https");
assertEquals(url.getHost(), "hello.com");
assertEquals(url.getPort(), -1);
assertEquals(url.getPath(), "/../other/content/img.png");
assertNull(url.getQuery());
}
代码示例来源:origin: javaee/grizzly-ahc
@Test
public void testRootRelativeURIWithRootContext() {
Uri context = Uri.create("https://graph.facebook.com");
Uri url = Uri.create(context, "/750198471659552/accounts/test-users?method=get&access_token=750198471659552lleveCvbUu_zqBa9tkT3tcgaPh4");
assertEquals(url.getScheme(), "https");
assertEquals(url.getHost(), "graph.facebook.com");
assertEquals(url.getPort(), -1);
assertEquals(url.getPath(), "/750198471659552/accounts/test-users");
assertEquals(url.getQuery(), "method=get&access_token=750198471659552lleveCvbUu_zqBa9tkT3tcgaPh4");
}
代码示例来源:origin: javaee/grizzly-ahc
public Uri encode(Uri uri, List<Param> queryParams) {
String newPath = encodePath(uri.getPath());
String newQuery = encodeQuery(uri.getQuery(), queryParams);
return new Uri(uri.getScheme(),//
uri.getUserInfo(),//
uri.getHost(),//
uri.getPort(),//
newPath,//
newQuery);
}
代码示例来源:origin: org.glassfish.grizzly/grizzly-http-client
public Uri encode(Uri uri, List<Param> queryParams) {
String newPath = encodePath(uri.getPath());
String newQuery = encodeQuery(uri.getQuery(), queryParams);
return new Uri(uri.getScheme(),//
uri.getUserInfo(),//
uri.getHost(),//
uri.getPort(),//
newPath,//
newQuery);
}
内容来源于网络,如有侵权,请联系作者删除!