List of usage examples for java.net SocketException getMessage
public String getMessage()
From source file:edu.usc.pgroup.floe.utils.Utils.java
/** * returns the canonical host name. This assumes a unique host name for * each machine in the cluster does not apply. * FixMe: In local cloud environment (local eucalyptus in system mode) * where the DNS server is not running, this might be an issue. * @return The first IPv4 address found for any interface that is up and * running./* w w w .java 2 s. co m*/ */ public static String getIpAddress() { String ip = null; try { Enumeration<NetworkInterface> interfaces = NetworkInterface.getNetworkInterfaces(); LOGGER.error("Getting ip"); while (interfaces.hasMoreElements()) { LOGGER.error("Next iface"); NetworkInterface current = interfaces.nextElement(); if (!current.isUp() || current.isLoopback() || current.isVirtual()) { continue; } Enumeration<InetAddress> addresses = current.getInetAddresses(); while (addresses.hasMoreElements()) { InetAddress currentAddr = addresses.nextElement(); if (currentAddr.isLoopbackAddress() || (currentAddr instanceof Inet6Address)) { continue; } ip = currentAddr.getHostAddress(); } } } catch (SocketException e) { LOGGER.error("Error occurred while retrieving hostname" + e.getMessage()); throw new RuntimeException("Error occurred while " + "retrieving hostname" + e.getMessage()); } return ip; }
From source file:org.graphwalker.Util.java
protected static InetAddress getInternetAddr(final String nic) { // Find the real network interface NetworkInterface iface = null; InetAddress ia = null;//w w w. jav a2s . com boolean foundNIC = false; try { for (Enumeration<NetworkInterface> ifaces = NetworkInterface.getNetworkInterfaces(); ifaces .hasMoreElements() && foundNIC == false;) { iface = ifaces.nextElement(); Util.logger.debug("Interface: " + iface.getDisplayName()); for (Enumeration<InetAddress> ips = iface.getInetAddresses(); ips.hasMoreElements() && foundNIC == false;) { ia = ips.nextElement(); Util.logger.debug(ia.getCanonicalHostName() + " " + ia.getHostAddress()); if (!ia.isLoopbackAddress()) { Util.logger.debug(" Not a loopback address..."); if (!ia.getHostAddress().contains(":") && nic.equals(iface.getDisplayName())) { Util.logger.debug(" Host address does not contain ':'"); Util.logger.debug(" Interface: " + iface.getName() + " seems to be InternetInterface. I'll take it..."); foundNIC = true; } } } } } catch (SocketException e) { Util.logger.error(e.getMessage()); } finally { if (!foundNIC && nic != null) { Util.logger.error("Could not bind to network interface: " + nic); throw new RuntimeException("Could not bind to network interface: " + nic); } else if (!foundNIC) { Util.logger.error("Could not bind to any network interface"); throw new RuntimeException("Could not bind to any network interface: "); } } return ia; }
From source file:org.jboss.as.jdr.commands.RHQStatusCommand.java
@Override public void execute() throws Exception { File keyFile = new File(System.getProperty("jboss.server.data.dir"), "jdr-token"); if (!keyFile.exists() || !keyFile.canRead()) { this.env.getZip().add("Cannot read access token file provided by [JDR Support] RHQ server plugin", RHQ_SERVER_STATE_JSON);//from ww w .j a v a2s . c om return; } String token = FileUtils.readFileToString(keyFile); try { Socket socket = new Socket(InetAddress.getByName(null), 7079); PrintWriter out = new PrintWriter(socket.getOutputStream(), true); out.println(token); this.env.getZip().add(socket.getInputStream(), RHQ_SERVER_STATE_JSON); out.close(); socket.close(); } catch (SocketException se) { this.env.getZip().add(se.getMessage() + " - Make sure [JDR Support] server plugin is enabled", RHQ_SERVER_STATE_JSON); } catch (Exception e) { this.env.getZip().add("Failed to retrieve status : " + e.getMessage(), RHQ_SERVER_STATE_JSON); } }
From source file:ch.cyberduck.core.DefaultSocketExceptionMappingService.java
@Override public BackgroundException map(final SocketException failure) { final StringBuilder buffer = new StringBuilder(); this.append(buffer, failure.getMessage()); if (StringUtils.equals(failure.getMessage(), "Software caused connection abort")) { return new ConnectionCanceledException(buffer.toString(), failure); }/* ww w .ja v a 2 s .com*/ if (StringUtils.equals(failure.getMessage(), "Socket closed")) { return new ConnectionCanceledException(buffer.toString(), failure); } return new ConnectionRefusedException(buffer.toString(), failure); }
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 .j a v a 2s . c o m * * 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:io.termd.core.telnet.TelnetClientRule.java
/** * Check if the client is disconnected, this affects the input stream of the socket by reading bytes from it. * * @return if the client is disconnected *//*from ww w . j av a 2 s. c o m*/ public boolean checkDisconnected() { try { return socket != null && socket.getInputStream().read() == -1; } catch (SocketException e) { if (e.getMessage().equals("Connection reset")) { return true; } throw TestBase.failure(e); } catch (IOException e) { throw TestBase.failure(e); } }
From source file:com.iqtb.validacion.util.ConectarFTP.java
public boolean connectFTP(String host, String user, String pass) { boolean conn = false; boolean reintentar = false; int intentos = 0; do {/* www .j a v a2s. co m*/ intentos++; logger.info("Intento: " + intentos); try { logger.info("Conectandose a " + host); client.connect(host); verificarRespuesta(client.getReplyCode()); boolean login = client.login(user, pass); if (login) { client.enterLocalPassiveMode(); verificarRespuesta(client.getReplyCode()); conn = true; logger.info("Login correcto"); boolean logout = client.logout(); if (logout) { logger.info("Logout del servidor FTP"); } } else { logger.error("Error en el login."); } logger.info("Desconectando."); client.disconnect(); } catch (ExcepcionFTP e) { logger.error(e.getMessage() + " Se intentara de nuevo"); reintentar = true; } catch (SocketException ex) { logger.error("ERROR: SocketException" + ex.getMessage()); reintentar = true;//No estoy muy seguro de que valla true } catch (IOException ex) { logger.error("IOException: " + ex); reintentar = true; } } while (reintentar && (intentos < 5)); if (reintentar) { logger.error("Se exedio el numero de intentos sin una conexion exitosa, verifique los datos"); } return conn; }
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 ww . j ava 2 s . c o m * * 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 - How long to wait for a connection to establish or a response from the target * @param object - The serializable object to send to the target * @return <code>Object</code> as output from the request * @throws UtilityException {@link com.cws.esolutions.core.utils.exception.UtilityException} if an error occurs processing */ public static final synchronized Object executeTcpRequest(final String hostName, final int portNumber, final int timeout, final Object object) throws UtilityException { final String methodName = NetworkUtils.CNAME + "#executeTcpRequest(final String hostName, final int portNumber, final int timeout, final Object object) throws UtilityException"; if (DEBUG) { DEBUGGER.debug(methodName); DEBUGGER.debug(hostName); DEBUGGER.debug("portNumber: {}", portNumber); DEBUGGER.debug("timeout: {}", timeout); DEBUGGER.debug("object: {}", object); } Socket socket = null; Object resObject = null; try { synchronized (new Object()) { if (StringUtils.isEmpty(InetAddress.getByName(hostName).toString())) { 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); } ObjectOutputStream objectOut = new ObjectOutputStream(socket.getOutputStream()); if (DEBUG) { DEBUGGER.debug("ObjectOutputStream: {}", objectOut); } objectOut.writeObject(object); resObject = new ObjectInputStream(socket.getInputStream()).readObject(); if (DEBUG) { DEBUGGER.debug("resObject: {}", resObject); } 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); } catch (ClassNotFoundException cnfx) { throw new UtilityException(cnfx.getMessage(), cnfx); } 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); } } return resObject; }
From source file:org.cloudfoundry.caldecott.client.SocketClient.java
public SocketClient(Socket socket) { this.socket = socket; try {// w ww . ja v a2 s . co m this.socket.setSoTimeout(SOCKET_TIMEOUT); } catch (SocketException e) { throw new TunnelException("Unable to set timeout on socket " + e.getMessage()); } }
From source file:org.apache.synapse.debug.SynapseDebugTCPListener.java
@Override public void run() { String debug_line = null;//from w ww . j a v a 2 s. c o m while (isDebugModeInProgress) { try { //this is a blocking call debug_line = debugInterface.getPortListenReader().readLine(); if (debug_line != null) { debugManager.processDebugCommand(debug_line); log.debug("debug command received from developer studio - " + debug_line); debug_line = null; } } catch (SocketException ex) { isDebugModeInProgress = false; log.error("Error in Socket Connection " + ex.getMessage(), ex); } catch (IOException ex) { log.error("Unable to process debug commands", ex); } } }