本文整理了Java中com.ning.http.client.uri.Uri.getPort()
方法的一些代码示例,展示了Uri.getPort()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Uri.getPort()
方法的具体详情如下:
包路径:com.ning.http.client.uri.Uri
类名称:Uri
方法名:getPort
暂无
代码示例来源:origin: com.ning/async-http-client
public final static String getAuthority(Uri uri) {
int port = uri.getPort() != -1 ? uri.getPort() : getDefaultPort(uri);
return uri.getHost() + ":" + port;
}
代码示例来源:origin: com.ning/async-http-client
public static final int getDefaultPort(Uri uri) {
int port = uri.getPort();
if (port == -1)
port = getSchemeDefaultPort(uri.getScheme());
return port;
}
代码示例来源: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 void addHostHeaderIfNeeded(final Request request, final Uri uri,
final HttpRequestPacket requestPacket) {
if (!requestPacket.containsHeader(Header.Host)) {
String host = request.getVirtualHost();
if (host != null) {
requestPacket.addHeader(Header.Host, host);
} else {
if (uri.getPort() == -1) {
requestPacket.addHeader(Header.Host, uri.getHost());
} else {
requestPacket.addHeader(Header.Host, uri.getHost() + ':' + uri.getPort());
}
}
}
}
代码示例来源:origin: com.ning/async-http-client
private String hostHeader(Request request, Uri uri) {
String virtualHost = request.getVirtualHost();
if (virtualHost != null)
return virtualHost;
else {
String host = uri.getHost();
int port = uri.getPort();
return port == -1 || port == getSchemeDefaultPort(uri.getScheme()) ? host : host + ":" + port;
}
}
代码示例来源: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
if (uri.getPort() == -1 || request.getVirtualHost() != null) {
urlConnection.setRequestProperty("Host", host);
} else {
urlConnection.setRequestProperty("Host", host + ":" + uri.getPort());
代码示例来源: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: com.ning/async-http-client
scheme = uri.getScheme();
host = uri.getHost();
port = getPort(scheme, uri.getPort());
代码示例来源:origin: com.ning/async-http-client
scheme = uri.getScheme();
host = uri.getHost();
port = getPort(scheme, uri.getPort());
代码示例来源:origin: org.glassfish.grizzly/grizzly-http-client
public static final int getDefaultPort(Uri uri) {
int port = uri.getPort();
if (port == -1)
port = getSchemeDefaultPort(uri.getScheme());
return port;
}
代码示例来源:origin: com.ning/async-http-client
uri.getHost(), uri.getPort()));
代码示例来源:origin: com.ning/async-http-client
String origin = "http://" + uri.getHost() + ":" + (uri.getPort() == -1 ? isSecure(uri.getScheme()) ? 443 : 80 : uri.getPort());
代码示例来源:origin: javaee/grizzly-ahc
private static int getPort(Uri uri) {
int port = uri.getPort();
if (port == -1)
port = uri.getScheme().equals("http") ? 80 : 443;
return port;
}
代码示例来源:origin: javaee/grizzly-ahc
private static int getPort(Uri uri) {
int port = uri.getPort();
if (port == -1)
port = uri.getScheme().equals("http") ? 80 : 443;
return port;
}
代码示例来源: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 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");
}
内容来源于网络,如有侵权,请联系作者删除!