本文整理了Java中com.ning.http.client.uri.Uri.getScheme()
方法的一些代码示例,展示了Uri.getScheme()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Uri.getScheme()
方法的具体详情如下:
包路径:com.ning.http.client.uri.Uri
类名称:Uri
方法名:getScheme
暂无
代码示例来源:origin: com.ning/async-http-client
private boolean isWSRequest(final Uri requestUri) {
return requestUri.getScheme().startsWith("ws");
}
代码示例来源:origin: com.ning/async-http-client
public static boolean isSecure(final Uri uri) {
final String scheme = uri.getScheme();
return ("https".equals(scheme) || "wss".equals(scheme));
}
代码示例来源:origin: com.ning/async-http-client
private void validateSupportedScheme(Uri uri) {
final String scheme = uri.getScheme();
if (scheme == null || !scheme.equalsIgnoreCase("http") && !scheme.equalsIgnoreCase("https") && !scheme.equalsIgnoreCase("ws")
&& !scheme.equalsIgnoreCase("wss")) {
throw new IllegalArgumentException("The URI scheme, of the URI " + uri
+ ", must be equal (ignoring case) to 'http', 'https', 'ws', or 'wss'");
}
}
代码示例来源:origin: com.ning/async-http-client
private void validateWebSocketRequest(Request request, Uri uri, AsyncHandler<?> asyncHandler) {
if (asyncHandler instanceof WebSocketUpgradeHandler) {
if (!uri.getScheme().startsWith(WEBSOCKET))
throw new IllegalArgumentException("WebSocketUpgradeHandler but scheme isn't ws or wss: " + uri.getScheme());
else if (!request.getMethod().equals(HttpMethod.GET.getName()))
throw new IllegalArgumentException("WebSocketUpgradeHandler but method isn't GET: " + request.getMethod());
} else if (uri.getScheme().startsWith(WEBSOCKET)) {
throw new IllegalArgumentException("No WebSocketUpgradeHandler but scheme is " + uri.getScheme());
}
}
代码示例来源:origin: com.ning/async-http-client
private void convertToUpgradeRequest(final HttpTransactionContext ctx) {
final Uri requestUri = ctx.requestUri;
ctx.wsRequestURI = requestUri;
ctx.requestUri = requestUri.withNewScheme("ws".equals(requestUri.getScheme()) ? "http" : "https");
}
代码示例来源:origin: com.ning/async-http-client
public static boolean isSecure(Uri uri) {
return isSecure(uri.getScheme());
}
代码示例来源:origin: com.ning/async-http-client
public final static String getBaseUrl(Uri uri) {
return uri.getScheme() + "://" + getAuthority(uri);
}
代码示例来源:origin: com.ning/async-http-client
public final static boolean isSameHostAndProtocol(Uri uri1, Uri uri2) {
return uri1.getScheme().equals(uri2.getScheme()) && uri1.getHost().equals(uri2.getHost())
&& getDefaultPort(uri1) == getDefaultPort(uri2);
}
代码示例来源: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
public static boolean useProxyConnect(Uri uri) {
return isSecure(uri) || isWebSocket(uri.getScheme());
}
}
代码示例来源:origin: com.ning/async-http-client
public Channel pollAndVerifyCachedChannel(Uri uri, ProxyServer proxy, ConnectionPoolPartitioning connectionPoolPartitioning, AsyncHandler<?> asyncHandler) {
if (asyncHandler instanceof AsyncHandlerExtensions)
AsyncHandlerExtensions.class.cast(asyncHandler).onPoolConnection();
final Channel channel = channelManager.poll(uri, proxy, connectionPoolPartitioning);
if (channel != null) {
LOGGER.debug("Using cached Channel {}\n for uri {}\n", channel, uri);
try {
// Always make sure the channel who got cached support the proper protocol. It could
// only occurs when a HttpMethod.CONNECT is used against a proxy that requires upgrading from http to
// https.
channelManager.verifyChannelPipeline(channel.getPipeline(), uri.getScheme());
} catch (Exception ex) {
LOGGER.debug(ex.getMessage(), ex);
}
}
return channel;
}
代码示例来源: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
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
/**
* Return true if the {@link Future} can be recovered. There is some scenario where a connection can be closed by an
* unexpected IOException, and in some situation we can recover from that exception.
*
* @return true if that {@link Future} cannot be recovered.
*/
public boolean canBeReplayed() {
return !isDone() && canRetry()
&& !(Channels.isChannelValid(channel) && !uri.getScheme().equalsIgnoreCase("https")) && !isInAuth();
}
代码示例来源: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 HttpURLConnection createUrlConnection(Request request) throws IOException, URISyntaxException {
ProxyServer proxyServer = ProxyUtils.getProxyServer(config, request);
Realm realm = request.getRealm() != null ? request.getRealm() : config.getRealm();
Proxy proxy = null;
if (proxyServer != null || realm != null) {
try {
proxy = configureProxyAndAuth(proxyServer, realm);
} catch (AuthenticationException e) {
throw new IOException(e.getMessage());
}
}
HttpURLConnection urlConnection = (HttpURLConnection)
request.getUri().toJavaNetURI().toURL().openConnection(proxy == null ? Proxy.NO_PROXY : proxy);
if (request.getUri().getScheme().equals("https")) {
HttpsURLConnection secure = (HttpsURLConnection) urlConnection;
SSLContext sslContext;
try {
sslContext = SslUtils.getInstance().getSSLContext(config);
} catch (GeneralSecurityException e) {
throw new IOException(e.getMessage());
}
secure.setSSLSocketFactory(sslContext.getSocketFactory());
secure.setHostnameVerifier(config.getHostnameVerifier());
}
return urlConnection;
}
代码示例来源: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
} else {
final Uri uri = request.getUri();
scheme = uri.getScheme();
host = uri.getHost();
port = getPort(scheme, uri.getPort());
代码示例来源:origin: com.ning/async-http-client
private boolean exitAfterHandlingConnect(//
final Channel channel,//
final NettyResponseFuture<?> future,//
final Request request,//
ProxyServer proxyServer,//
int statusCode,//
HttpRequest httpRequest) throws IOException {
if (statusCode == OK.getCode() && httpRequest.getMethod() == HttpMethod.CONNECT) {
if (future.isKeepAlive())
future.attachChannel(channel, true);
try {
Uri requestUri = request.getUri();
String scheme = requestUri.getScheme();
String host = requestUri.getHost();
int port = getDefaultPort(requestUri);
logger.debug("Connecting to proxy {} for scheme {}", proxyServer, scheme);
channelManager.upgradeProtocol(channel.getPipeline(), scheme, host, port);
} catch (Throwable ex) {
requestSender.abort(channel, future, ex);
}
future.setReuseChannel(true);
future.setConnectAllowed(false);
requestSender.sendNextRequest(new RequestBuilder(future.getRequest()).build(), future);
return true;
}
return false;
}
代码示例来源:origin: com.ning/async-http-client
ClientBootstrap bootstrap = channelManager.getBootstrap(request.getUri().getScheme(), useProxy, useSSl);
内容来源于网络,如有侵权,请联系作者删除!