List of usage examples for java.net UnknownHostException UnknownHostException
public UnknownHostException(String message)
From source file:jnode.vm.NetAPIImpl.java
public byte[][] getHostByName(String hostname) throws UnknownHostException { ArrayList<byte[]> list = null; for (NetworkLayer layer : networkLayerManager.getNetworkLayers()) { final ProtocolAddress[] addrs = layer.getHostByName(hostname); if (addrs != null) { if (list == null) { list = new ArrayList<byte[]>(); }/*from www.j a v a2s.c o m*/ final int cnt = addrs.length; for (int j = 0; j < cnt; j++) { final ProtocolAddress pa = addrs[j]; if (pa != null) { list.add(pa.toByteArray()); } } } } if ((list == null) || list.isEmpty()) { throw new UnknownHostException(hostname); } else { return (byte[][]) list.toArray(new byte[list.size()][]); } }
From source file:com.googlecode.jmxtrans.model.output.OpenTSDBGenericWriterTests.java
@Test @Ignore("issue with classloader used by powermockito and the securityManager which use ClassLoader.getResource") public void testLocalhostUnknownHostException() throws Exception { UnknownHostException unknownHostException = new UnknownHostException("X-TEST-UHE-X"); try {/* w w w .ja v a 2s . c o m*/ PowerMockito.mockStatic(InetAddress.class); PowerMockito.when(InetAddress.getLocalHost()).thenThrow(unknownHostException); createWriter(); Assert.fail("LifecycleException missing"); } catch (UnknownHostException ex) { // Verify. Assert.assertSame(unknownHostException, ex); } }
From source file:jnode.vm.NetAPIImpl.java
/** * @see java.net.VMNetAPI#getHostByAddr(byte[]) *//* w w w. j a va 2 s. co m*/ public String getHostByAddr(byte[] ip) throws UnknownHostException { throw new UnknownHostException("Not implemented"); }
From source file:org.apache.phoenix.hive.util.PhoenixStorageHandlerUtil.java
private static String reverseDNS(InetAddress ipAddress) throws NamingException, UnknownHostException { String hostName = reverseDNSCacheMap.get(ipAddress); if (hostName == null) { String ipAddressString = null; try {//from w w w. ja v a 2 s . c o m ipAddressString = DNS.reverseDns(ipAddress, null); } catch (Exception e) { // We can use InetAddress in case the jndi failed to pull up the reverse DNS entry // from the name service. Also, in case of ipv6, we need to use the InetAddress // since resolving reverse DNS using jndi doesn't work well with ipv6 addresses. ipAddressString = InetAddress.getByName(ipAddress.getHostAddress()).getHostName(); } if (ipAddressString == null) { throw new UnknownHostException("No host found for " + ipAddress); } hostName = Strings.domainNamePointerToHostName(ipAddressString); reverseDNSCacheMap.put(ipAddress, hostName); } return hostName; }
From source file:org.getlantern.firetweet.util.net.FiretweetHostAddressResolver.java
private InetAddress[] fromAddressString(String host, String address) throws UnknownHostException { InetAddress inetAddress = InetAddress.getByName(address); if (inetAddress instanceof Inet4Address) { return new InetAddress[] { Inet4Address.getByAddress(host, inetAddress.getAddress()) }; } else if (inetAddress instanceof Inet6Address) { return new InetAddress[] { Inet6Address.getByAddress(host, inetAddress.getAddress()) }; }/*from w ww .ja v a 2s . c o m*/ throw new UnknownHostException("Bad address " + host + " = " + address); }
From source file:com.qiniu.android.http.ClientConnectionOperator.java
private String[] systemResolv(String domain) throws UnknownHostException { if (dnsResolver == null) { InetAddress[] addresses = InetAddress.getAllByName(domain); String[] x = new String[addresses.length]; for (int i = 0; i < addresses.length; i++) { x[i] = addresses[i].getHostAddress(); }/*from ww w . j a va 2 s . co m*/ return x; } try { return dnsResolver.query(new Domain(domain, true, false, 3600)); } catch (IOException e) { throw new UnknownHostException(e.getMessage()); } }
From source file:org.cloudifysource.dsl.utils.IPUtils.java
/** * Validates a connection can be made to the given address and port, within * the given time limit./*from w ww . java2s . c om*/ * * @param ipAddress * The IP address to connect to * @param port * The port number to use * @param timeout * The time to wait before timing out, in seconds * @throws IOException * Reports a failure to connect or resolve the given address. */ public static void validateConnection(final String ipAddress, final int port, final int timeout) throws IOException { final Socket socket = new Socket(); try { final InetSocketAddress endPoint = new InetSocketAddress(ipAddress, port); if (endPoint.isUnresolved()) { throw new UnknownHostException(ipAddress); } socket.connect(endPoint, safeLongToInt(TimeUnit.SECONDS.toMillis(timeout), true)); } finally { try { socket.close(); } catch (final IOException ioe) { // ignore } } }
From source file:org.mulgara.resolver.http.HttpContent.java
/** * Obtain a valid connection and follow redirects if necessary. * // w w w .j a v a2 s . co m * @param methodType request the headders (HEAD) or body (GET) * @return valid connection method. Can be null. * @throws NotModifiedException if the content validates against the cache * @throws IOException if there's difficulty communicating with the web site */ private HttpMethod establishConnection(int methodType) throws IOException, NotModifiedException { if (logger.isDebugEnabled()) logger.debug("Establishing connection"); HttpMethod method = getConnectionMethod(methodType); assert method != null; Header header = null; /* // Add cache validation headers to the request if (lastModifiedMap.containsKey(httpUri)) { String lastModified = (String) lastModifiedMap.get(httpUri); assert lastModified != null; method.addRequestHeader("If-Modified-Since", lastModified); } if (eTagMap.containsKey(httpUri)) { String eTag = (String) eTagMap.get(httpUri); assert eTag != null; method.addRequestHeader("If-None-Match", eTag); } */ // Make the request if (logger.isDebugEnabled()) logger.debug("Executing HTTP request"); connection.open(); method.execute(state, connection); if (logger.isDebugEnabled()) { logger.debug("Executed HTTP request, response code " + method.getStatusCode()); } // Interpret the response header if (method.getStatusCode() == HttpStatus.SC_NOT_MODIFIED) { // cache has been validated throw new NotModifiedException(httpUri); } else if (!isValidStatusCode(method.getStatusCode())) { throw new UnknownHostException("Unable to obtain connection to " + httpUri + ". Returned status code " + method.getStatusCode()); } else { // has a redirection been issued int numberOfRedirection = 0; while (isRedirected(method.getStatusCode()) && numberOfRedirection <= MAX_NO_REDIRECTS) { // release the existing connection method.releaseConnection(); //attempt to follow the redirects numberOfRedirection++; // obtain the new location header = method.getResponseHeader("location"); if (header != null) { try { initialiseSettings(new URL(header.getValue())); if (logger.isInfoEnabled()) { logger.info("Redirecting to " + header.getValue()); } // attempt a new connection to this location method = getConnectionMethod(methodType); connection.open(); method.execute(state, connection); if (!isValidStatusCode(method.getStatusCode())) { throw new UnknownHostException( "Unable to obtain connection to " + " the redirected site " + httpUri + ". Returned status code " + method.getStatusCode()); } } catch (URISyntaxException ex) { throw new IOException( "Unable to follow redirection to " + header.getValue() + " Not a valid URI"); } } else { throw new IOException("Unable to obtain redirecting detaild from " + httpUri); } } } // Update metadata about the cached document Header lastModifiedHeader = method.getResponseHeader("Last-Modified"); if (lastModifiedHeader != null) { logger.debug(lastModifiedHeader.toString()); assert lastModifiedHeader.getElements().length >= 1; assert lastModifiedHeader.getElements()[0].getName() != null; assert lastModifiedHeader.getElements()[0].getName() instanceof String; // previous code: added to cache } Header eTagHeader = method.getResponseHeader("Etag"); if (eTagHeader != null) { logger.debug(eTagHeader.toString()); assert eTagHeader.getElements().length >= 1; assert eTagHeader.getElements()[0].getName() != null; assert eTagHeader.getElements()[0].getName() instanceof String; // previous code: added to cache } return method; }
From source file:net.yacy.cora.protocol.http.HTTPClient.java
private static PoolingHttpClientConnectionManager initPoolingConnectionManager() { final PlainConnectionSocketFactory plainsf = PlainConnectionSocketFactory.getSocketFactory(); final Registry<ConnectionSocketFactory> registry = RegistryBuilder.<ConnectionSocketFactory>create() .register("http", plainsf).register("https", getSSLSocketFactory()).build(); final PoolingHttpClientConnectionManager pooling = new PoolingHttpClientConnectionManager(registry, null, null, new DnsResolver() { @Override//from w w w. j av a 2s . com public InetAddress[] resolve(final String host0) throws UnknownHostException { final InetAddress ip = Domains.dnsResolve(host0); if (ip == null) throw new UnknownHostException(host0); return new InetAddress[] { ip }; } }, DEFAULT_POOLED_CONNECTION_TIME_TO_LIVE, TimeUnit.SECONDS); initPoolMaxConnections(pooling, maxcon); pooling.setValidateAfterInactivity(default_timeout); // on init set to default 5000ms final SocketConfig socketConfig = SocketConfig.custom() // Defines whether the socket can be bound even though a previous connection is still in a timeout state. .setSoReuseAddress(true) // SO_TIMEOUT: maximum period inactivity between two consecutive data packets in milliseconds .setSoTimeout(3000) // conserve bandwidth by minimizing the number of segments that are sent .setTcpNoDelay(false).build(); pooling.setDefaultSocketConfig(socketConfig); return pooling; }
From source file:org.apache.hadoop.hbase.ipc.BlockingRpcConnection.java
BlockingRpcConnection(BlockingRpcClient rpcClient, ConnectionId remoteId) throws IOException { super(rpcClient.conf, AbstractRpcClient.WHEEL_TIMER, remoteId, rpcClient.clusterId, rpcClient.userProvider.isHBaseSecurityEnabled(), rpcClient.codec, rpcClient.compressor); this.rpcClient = rpcClient; if (remoteId.getAddress().isUnresolved()) { throw new UnknownHostException("unknown host: " + remoteId.getAddress().getHostName()); }//from w w w . java 2 s. co m this.connectionHeaderPreamble = getConnectionHeaderPreamble(); ConnectionHeader header = getConnectionHeader(); ByteArrayOutputStream baos = new ByteArrayOutputStream(4 + header.getSerializedSize()); DataOutputStream dos = new DataOutputStream(baos); dos.writeInt(header.getSerializedSize()); header.writeTo(dos); assert baos.size() == 4 + header.getSerializedSize(); this.connectionHeaderWithLength = baos.getBuffer(); UserGroupInformation ticket = remoteId.ticket.getUGI(); this.threadName = "IPC Client (" + this.rpcClient.socketFactory.hashCode() + ") connection to " + remoteId.getAddress().toString() + ((ticket == null) ? " from an unknown user" : (" from " + ticket.getUserName())); if (this.rpcClient.conf.getBoolean(BlockingRpcClient.SPECIFIC_WRITE_THREAD, false)) { callSender = new CallSender(threadName, this.rpcClient.conf); callSender.start(); } else { callSender = null; } }