List of usage examples for java.net UnknownHostException getMessage
public String getMessage()
From source file:org.openo.nfvo.emsdriver.northbound.service.EmsDriverApplication.java
private void msbRegisteEmsDriverService(EmsDriverConfiguration configuration) { DefaultServerFactory defaultServerFactory = (DefaultServerFactory) configuration.getServerFactory(); HttpConnectorFactory connector = (HttpConnectorFactory) defaultServerFactory.getAdminConnectors().get(0); MsbRegisterVo registerVo = new MsbRegisterVo(); ServiceNodeVo serviceNode = new ServiceNodeVo(); String ip = ""; try {/*from w w w. j av a2s.co m*/ ip = InetAddress.getLocalHost().getHostAddress(); } catch (UnknownHostException e) { log.error("Unable to get host ip: " + e.getMessage()); } if (ip.equals("")) { ip = connector.getBindHost(); } serviceNode.setIp(ip); serviceNode.setPort(String.valueOf(connector.getPort())); serviceNode.setTtl(0); List<ServiceNodeVo> nodeList = new ArrayList<ServiceNodeVo>(); nodeList.add(serviceNode); registerVo.setServiceName("emsdriver"); registerVo.setUrl("/openoapi/emsdriver/v1"); registerVo.setNodes(nodeList); MsbRestServiceProxy.registerService(registerVo); log.info("register monitor-umc service to msb finished."); }
From source file:mitm.common.util.InetNetworkFilter.java
/** * Returns true if the address is accepted by this filter, false if not. *//*from w w w. j av a 2s .c om*/ public synchronized boolean isAccepted(String address) { for (InetNetwork network : networks) { try { if (network.contains(address)) { return true; } } catch (UnknownHostException e) { logger.warn("UnknownHostException. Message: " + e.getMessage()); } } return false; }
From source file:fr.jayasoft.ivy.url.BasicURLHandler.java
public boolean isReachable(URL url, int timeout) { try {/*from ww w. j a v a 2 s. c o m*/ URLConnection con = url.openConnection(); if (con instanceof HttpURLConnection) { int status = ((HttpURLConnection) con).getResponseCode(); if (status == HttpStatus.SC_OK) { return true; } if (status == HttpStatus.SC_PROXY_AUTHENTICATION_REQUIRED) { Message.warn("Your proxy requires authentication."); } else if (String.valueOf(status).startsWith("4")) { Message.verbose( "CLIENT ERROR: " + ((HttpURLConnection) con).getResponseMessage() + " url=" + url); } else if (String.valueOf(status).startsWith("5")) { Message.error( "SERVER ERROR: " + ((HttpURLConnection) con).getResponseMessage() + " url=" + url); } Message.debug("HTTP response status: " + status + " url=" + url); } else { int contentLength = con.getContentLength(); return contentLength > 0; } } catch (UnknownHostException e) { Message.warn("Host " + e.getMessage() + " not found. url=" + url); Message.info( "You probably access the destination server through a proxy server that is not well configured."); } catch (IOException e) { Message.error("Server access Error: " + e.getMessage() + " url=" + url); } return false; }
From source file:gov.hhs.fha.nhinc.lift.proxy.properties.imp.ConsumerProxyPropertiesFacadeRI.java
@Override public InetAddress getClientProxyAddress() { try {// ww w.ja v a2 s.c o m //only expects connection on the localhost from the file downloader return InetAddress.getByName("localhost"); } catch (UnknownHostException e) { log.error(e.getMessage()); } return null; }
From source file:com.cws.esolutions.core.utils.NetworkUtils.java
/** * Creates an telnet connection to a target host and port number. Silently * succeeds if no issues are encountered, if so, exceptions are logged and * re-thrown back to the requestor./*from w w w .ja va 2s . com*/ * * If an exception is thrown during the <code>socket.close()</code> operation, * it is logged but NOT re-thrown. It's not re-thrown because it does not indicate * a connection failure (indeed, it means the connection succeeded) but it is * logged because continued failures to close the socket could result in target * system instability. * * @param hostName - The target host to make the connection to * @param portNumber - The port number to attempt the connection on * @param timeout - The timeout for the connection * @throws UtilityException {@link com.cws.esolutions.core.utils.exception.UtilityException} if an error occurs processing */ public static final synchronized void executeTelnetRequest(final String hostName, final int portNumber, final int timeout) throws UtilityException { final String methodName = NetworkUtils.CNAME + "#executeTelnetRequest(final String hostName, final int portNumber, final int timeout) throws UtilityException"; if (DEBUG) { DEBUGGER.debug(methodName); DEBUGGER.debug(hostName); DEBUGGER.debug("portNumber: {}", portNumber); DEBUGGER.debug("timeout: {}", timeout); } Socket socket = null; try { synchronized (new Object()) { if (InetAddress.getByName(hostName) == null) { throw new UnknownHostException("No host was found in DNS for the given name: " + hostName); } InetSocketAddress socketAddress = new InetSocketAddress(hostName, portNumber); socket = new Socket(); socket.setSoTimeout((int) TimeUnit.SECONDS.toMillis(timeout)); socket.setSoLinger(false, 0); socket.setKeepAlive(false); socket.connect(socketAddress, (int) TimeUnit.SECONDS.toMillis(timeout)); if (!(socket.isConnected())) { throw new ConnectException("Failed to connect to host " + hostName + " on port " + portNumber); } PrintWriter pWriter = new PrintWriter(socket.getOutputStream(), true); pWriter.println(NetworkUtils.TERMINATE_TELNET + NetworkUtils.CRLF); pWriter.flush(); pWriter.close(); } } catch (ConnectException cx) { throw new UtilityException(cx.getMessage(), cx); } catch (UnknownHostException ux) { throw new UtilityException(ux.getMessage(), ux); } catch (SocketException sx) { throw new UtilityException(sx.getMessage(), sx); } catch (IOException iox) { throw new UtilityException(iox.getMessage(), iox); } finally { try { if ((socket != null) && (!(socket.isClosed()))) { socket.close(); } } catch (IOException iox) { // log it - this could cause problems later on ERROR_RECORDER.error(iox.getMessage(), iox); } } }
From source file:com.stratio.cassandra.index.schema.ColumnMapperInet.java
/** {@inheritDoc} */ @Override/* w ww . jav a2 s .com*/ public String indexValue(String name, Object value) { if (value == null) { return null; } else if (value instanceof InetAddress) { InetAddress inetAddress = (InetAddress) value; return inetAddress.getHostAddress(); } else if (value instanceof String) { String svalue = (String) value; if (IPV4_PATTERN.matcher(svalue).matches() || IPV6_PATTERN.matcher(svalue).matches() || IPV6_COMPRESSED_PATTERN.matcher(svalue).matches()) { try { return InetAddress.getByName(svalue).getHostAddress(); } catch (UnknownHostException e) { Log.error(e, e.getMessage()); } } } throw new IllegalArgumentException(String.format("Value '%s' cannot be cast to InetAddress", value)); }
From source file:com.stratio.cassandra.index.schema.ColumnMapperInet.java
/** {@inheritDoc} */ @Override/*ww w .j av a2 s . co m*/ public String queryValue(String name, Object value) { if (value == null) { return null; } else if (value instanceof InetAddress) { InetAddress inetAddress = (InetAddress) value; return inetAddress.getHostAddress(); } else if (value instanceof String) { String svalue = (String) value; if (IPV4_PATTERN.matcher(svalue).matches() || IPV6_PATTERN.matcher(svalue).matches() || IPV6_COMPRESSED_PATTERN.matcher(svalue).matches()) { try { return InetAddress.getByName(svalue).getHostAddress(); } catch (UnknownHostException e) { Log.error(e, e.getMessage()); } } else { return svalue; } } throw new IllegalArgumentException(String.format("Value '%s' cannot be cast to InetAddress", value)); }
From source file:com.predic8.membrane.core.interceptor.acl.Resource.java
public boolean checkAccess(String hostname, String ip) { if (log.isDebugEnabled()) { log.debug("Hostname: " + hostname + (router.getTransport().isReverseDNS() ? "" : " (reverse DNS is disabled in configuration)")); log.debug("IP: " + ip); try {//from w w w . ja v a 2 s. co m log.debug("Hostaddress (might require slow DNS lookup): " + router.getDnsCache().getHostName(InetAddress.getByName(ip))); } catch (UnknownHostException e) { log.debug("Failed to get hostname from address: " + e.getMessage()); } } for (AbstractClientAddress cAdd : clientAddresses) { if (cAdd.matches(hostname, ip)) return true; } return false; }
From source file:org.jumlabs.jcr.oak.rpc.AppConfiguration.java
@Bean public MongoConnection mongoConnection() { MongoClientURI uri = new MongoClientURI( "mongodb://" + connectionSettings.getMongoHost() + "/" + connectionSettings.getMongoDB()); MongoConnection mongo = null;/* w w w . j a v a 2 s.c om*/ try { mongo = new MongoConnection(uri.getURI()); } catch (UnknownHostException ex) { logger.error(ex.getMessage(), ex); } return mongo; }
From source file:org.springframework.cloud.client.discovery.noop.NoopDiscoveryClientAutoConfiguration.java
@PostConstruct public void init() { String host = "localhost"; try {// ww w.ja v a 2 s . c o m host = InetAddress.getLocalHost().getHostName(); } catch (UnknownHostException e) { log.warn("Cannot get host info: (" + e.getMessage() + ")"); } int port = findPort(); this.serviceInstance = new DefaultServiceInstance( this.environment.getProperty("spring.application.name", "application"), host, port, false); }