mirror of https://github.com/grpc/grpc-java.git
core: remove GrpcUtil.getHost
This utility is not relevant on supported JDK versions anymore.
This commit is contained in:
parent
ccfd351a2e
commit
6e25c03a7b
|
|
@ -48,10 +48,8 @@ import io.grpc.internal.StreamListener.MessageProducer;
|
||||||
import java.io.Closeable;
|
import java.io.Closeable;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.lang.reflect.InvocationTargetException;
|
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
import java.net.HttpURLConnection;
|
import java.net.HttpURLConnection;
|
||||||
import java.net.InetSocketAddress;
|
|
||||||
import java.net.SocketAddress;
|
import java.net.SocketAddress;
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
import java.net.URISyntaxException;
|
import java.net.URISyntaxException;
|
||||||
|
|
@ -632,25 +630,6 @@ public final class GrpcUtil {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the host via {@link InetSocketAddress#getHostString} if it is possible,
|
|
||||||
* i.e. in jdk >= 7.
|
|
||||||
* Otherwise, return it via {@link InetSocketAddress#getHostName} which may incur a DNS lookup.
|
|
||||||
*/
|
|
||||||
public static String getHost(InetSocketAddress addr) {
|
|
||||||
try {
|
|
||||||
Method getHostStringMethod = InetSocketAddress.class.getMethod("getHostString");
|
|
||||||
return (String) getHostStringMethod.invoke(addr);
|
|
||||||
} catch (NoSuchMethodException e) {
|
|
||||||
// noop
|
|
||||||
} catch (IllegalAccessException e) {
|
|
||||||
// noop
|
|
||||||
} catch (InvocationTargetException e) {
|
|
||||||
// noop
|
|
||||||
}
|
|
||||||
return addr.getHostName();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Marshals a nanoseconds representation of the timeout to and from a string representation,
|
* Marshals a nanoseconds representation of the timeout to and from a string representation,
|
||||||
* consisting of an ASCII decimal representation of a number with at most 8 digits, followed by a
|
* consisting of an ASCII decimal representation of a number with at most 8 digits, followed by a
|
||||||
|
|
|
||||||
|
|
@ -202,14 +202,7 @@ class ProxyDetectorImpl implements ProxyDetector {
|
||||||
|
|
||||||
private ProxiedSocketAddress detectProxy(InetSocketAddress targetAddr) throws IOException {
|
private ProxiedSocketAddress detectProxy(InetSocketAddress targetAddr) throws IOException {
|
||||||
URI uri;
|
URI uri;
|
||||||
String host;
|
String host = targetAddr.getHostString();
|
||||||
try {
|
|
||||||
host = GrpcUtil.getHost(targetAddr);
|
|
||||||
} catch (Throwable t) {
|
|
||||||
// Workaround for Android API levels < 19 if getHostName causes a NetworkOnMainThreadException
|
|
||||||
log.log(Level.WARNING, "Failed to get host for proxy lookup, proceeding without proxy", t);
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
try {
|
try {
|
||||||
uri =
|
uri =
|
||||||
new URI(
|
new URI(
|
||||||
|
|
@ -247,13 +240,14 @@ class ProxyDetectorImpl implements ProxyDetector {
|
||||||
// The prompt string should be the realm as returned by the server.
|
// The prompt string should be the realm as returned by the server.
|
||||||
// We don't have it because we are avoiding the full handshake.
|
// We don't have it because we are avoiding the full handshake.
|
||||||
String promptString = "";
|
String promptString = "";
|
||||||
PasswordAuthentication auth = authenticationProvider.requestPasswordAuthentication(
|
PasswordAuthentication auth =
|
||||||
GrpcUtil.getHost(proxyAddr),
|
authenticationProvider.requestPasswordAuthentication(
|
||||||
proxyAddr.getAddress(),
|
proxyAddr.getHostString(),
|
||||||
proxyAddr.getPort(),
|
proxyAddr.getAddress(),
|
||||||
PROXY_SCHEME,
|
proxyAddr.getPort(),
|
||||||
promptString,
|
PROXY_SCHEME,
|
||||||
null);
|
promptString,
|
||||||
|
null);
|
||||||
|
|
||||||
final InetSocketAddress resolvedProxyAddr;
|
final InetSocketAddress resolvedProxyAddr;
|
||||||
if (proxyAddr.isUnresolved()) {
|
if (proxyAddr.isUnresolved()) {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue