本文整理汇总了Java中io.grpc.internal.GrpcUtil.authorityToUri方法的典型用法代码示例。如果您正苦于以下问题:Java GrpcUtil.authorityToUri方法的具体用法?Java GrpcUtil.authorityToUri怎么用?Java GrpcUtil.authorityToUri使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类io.grpc.internal.GrpcUtil
的用法示例。
在下文中一共展示了GrpcUtil.authorityToUri方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: tls
import io.grpc.internal.GrpcUtil; //导入方法依赖的package包/类
/**
* Returns a {@link ProtocolNegotiator} that ensures the pipeline is set up so that TLS will
* be negotiated, the {@code handler} is added and writes to the {@link io.netty.channel.Channel}
* may happen immediately, even before the TLS Handshake is complete.
*/
public static ProtocolNegotiator tls(SslContext sslContext, String authority) {
Preconditions.checkNotNull(sslContext, "sslContext");
URI uri = GrpcUtil.authorityToUri(Preconditions.checkNotNull(authority, "authority"));
String host;
int port;
if (uri.getHost() != null) {
host = uri.getHost();
port = uri.getPort();
} else {
/*
* Implementation note: We pick -1 as the port here rather than deriving it from the original
* socket address. The SSL engine doens't use this port number when contacting the remote
* server, but rather it is used for other things like SSL Session caching. When an invalid
* authority is provided (like "bad_cert"), picking the original port and passing it in would
* mean that the port might used under the assumption that it was correct. By using -1 here,
* it forces the SSL implementation to treat it as invalid.
*/
host = authority;
port = -1;
}
return new TlsNegotiator(sslContext, host, port);
}
示例2: getOverridenPort
import io.grpc.internal.GrpcUtil; //导入方法依赖的package包/类
@VisibleForTesting
int getOverridenPort() {
URI uri = GrpcUtil.authorityToUri(defaultAuthority);
if (uri.getPort() != -1) {
return uri.getPort();
}
return address.getPort();
}
示例3: getOverridenHost
import io.grpc.internal.GrpcUtil; //导入方法依赖的package包/类
/**
* Gets the overridden authority hostname. If the authority is overridden to be an invalid
* authority, uri.getHost() will (rightly) return null, since the authority is no longer
* an actual service. This method overrides the behavior for practical reasons. For example,
* if an authority is in the form "invalid_authority" (note the "_"), rather than return null,
* we return the input. This is because the return value, in conjunction with getOverridenPort,
* are used by the SSL library to reconstruct the actual authority. It /already/ has a
* connection to the port, independent of this function.
*
* <p>Note: if the defaultAuthority has a port number in it and is also bad, this code will do
* the wrong thing. An example wrong behavior would be "invalid_host:443". Registry based
* authorities do not have ports, so this is even more wrong than before. Sorry.
*/
@VisibleForTesting
String getOverridenHost() {
URI uri = GrpcUtil.authorityToUri(defaultAuthority);
if (uri.getHost() != null) {
return uri.getHost();
}
return defaultAuthority;
}