public static boolean checkIfRemoteEndpointAccessible(String host, int port) { try { Socket discover = new Socket(); discover.setSoTimeout(1000); discover.connect(new InetSocketAddress(host, port), 1000); discover.close(); return true; } catch (ConnectException cne) { // end point is not accessible if (LOGGER.isDebugEnabled()) { LOGGER.debug("Remote endpoint '" + host + ":" + port + "' is not accessible " + "(might be initializing): " + cne.getMessage()); } return false; } catch (IOException ioe) { // end point is not accessible if (LOGGER.isDebugEnabled()) { LOGGER.debug("Remote endpoint '" + host + ":" + port + "' is not accessible " + "(might be initializing): " + ioe.getMessage()); } return false; } }
private void handleConnectException(ConnectException e) throws ConnectException { String message = e.getMessage(); String[] tokens = message.split("-"); if (tokens.length > 1 && tokens[1] != null) { Timber.e(e, "Stripping host/port from ConnectionException for %s", getLogId()); throw new ConnectException(tokens[1].trim()); } else { throw e; } }
AnnotatedConnectException(ConnectException exception, SocketAddress remoteAddress) { super(exception.getMessage() + ": " + remoteAddress); initCause(exception); setStackTrace(exception.getStackTrace()); }
AnnotatedConnectException(ConnectException exception, SocketAddress remoteAddress) { super(exception.getMessage() + ": " + remoteAddress); initCause(exception); setStackTrace(exception.getStackTrace()); }
private static void connect(SelectionKey k) throws IOException { NioClientSocketChannel ch = (NioClientSocketChannel) k.attachment(); try { if (ch.channel.finishConnect()) { k.cancel(); if (ch.timoutTimer != null) { ch.timoutTimer.cancel(); } ch.worker.register(ch, ch.connectFuture); } } catch (ConnectException e) { ConnectException newE = new ConnectException(e.getMessage() + ": " + ch.requestedRemoteAddress); newE.setStackTrace(e.getStackTrace()); throw newE; } }
AnnotatedConnectException(ConnectException exception, SocketAddress remoteAddress) { super(exception.getMessage() + ": " + remoteAddress); initCause(exception); setStackTrace(exception.getStackTrace()); }
beat.finishCheck(false, true, Switch.getTcpHealthParams().getMax(), "tcp:unable2connect:" + e.getMessage()); } catch (Exception e) { beat.finishCheck(false, false, Switch.getTcpHealthParams().getMax(), "tcp:error:" + e.getMessage());
throw new AnnounceException(e.getMessage(), e);
ex.getCause().getClass()); assertEquals("InnerException is connect Exception", connectEx.getMessage(), ex.getCause().getMessage());
public static String getContent(URL url, int timeOut) throws IOException { try { URLConnection openConnection = url.openConnection(); openConnection.setConnectTimeout(timeOut); openConnection.setReadTimeout(timeOut); ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); InputStream in = openConnection.getInputStream(); IOUtils.copy(in, byteArrayOutputStream); in.close(); return new String(byteArrayOutputStream.toByteArray(), Charsets.UTF_8); } catch (ConnectException e) { throw new ConnectException(e.getMessage() + " (" + url.toString() + ")"); } }
private static void testClusterRunning() throws IOException { try { ESVersion version = esClient.getVersion(); staticLogger.info("Starting integration tests against an external cluster running elasticsearch [{}]", version); } catch (ConnectException e) { // If we have an exception here, let's ignore the test staticLogger.warn("Integration tests are skipped: [{}]", e.getMessage()); assumeThat("Integration tests are skipped", e.getMessage(), not(containsString("Connection refused"))); } }
/** * Get the HTTP response code from the request. * <p> * Roughly the same as <code>c.getResponseCode()</code> but the * ConnectException is translated to be more understandable. * * @param c * connection the code should be obtained from. * @return r HTTP status code, usually 200 to indicate success. See * {@link org.eclipse.jgit.transport.http.HttpConnection} for other * defined constants. * @throws java.io.IOException * communications error prevented obtaining the response code. */ public static int response(java.net.HttpURLConnection c) throws IOException { try { return c.getResponseCode(); } catch (ConnectException ce) { final URL url = c.getURL(); final String host = (url == null) ? "<null>" : url.getHost(); //$NON-NLS-1$ // The standard J2SE error message is not very useful. // if ("Connection timed out: connect".equals(ce.getMessage())) //$NON-NLS-1$ throw new ConnectException(MessageFormat.format( JGitText.get().connectionTimeOut, host)); throw new ConnectException(ce.getMessage() + " " + host); //$NON-NLS-1$ } }
/** * Get the HTTP response code from the request. * <p> * Roughly the same as <code>c.getResponseCode()</code> but the * ConnectException is translated to be more understandable. * * @param c * connection the code should be obtained from. * @return r HTTP status code, usually 200 to indicate success. See * {@link org.eclipse.jgit.transport.http.HttpConnection} for other * defined constants. * @throws java.io.IOException * communications error prevented obtaining the response code. * @since 3.3 */ public static int response(HttpConnection c) throws IOException { try { return c.getResponseCode(); } catch (ConnectException ce) { final URL url = c.getURL(); final String host = (url == null) ? "<null>" : url.getHost(); //$NON-NLS-1$ // The standard J2SE error message is not very useful. // if ("Connection timed out: connect".equals(ce.getMessage())) //$NON-NLS-1$ throw new ConnectException(MessageFormat.format(JGitText.get().connectionTimeOut, host)); throw new ConnectException(ce.getMessage() + " " + host); //$NON-NLS-1$ } }
logger.error("Reconnect fail and recur now: {}",ce.getMessage()); LockSupport.parkNanos(TimeUnit.SECONDS.toNanos(1)); return send(request);
pResponse.sendError(HttpServletResponse.SC_BAD_GATEWAY, e.getMessage());
} catch (ConnectException ex) { String message; if (ex.getMessage() != null) { message = ex.getMessage(); } else { message = "Unknown error";
if (_log.shouldLog(Log.DEBUG)) _log.debug("STREAM CONNECT failed", e); notifyStreamResult ( verbose, "CONNECTION_REFUSED", e.getMessage()); } catch (NoRouteToHostException e) { if (_log.shouldLog(Log.DEBUG))
AnnotatedConnectException(ConnectException exception, SocketAddress remoteAddress) { super(exception.getMessage() + ": " + remoteAddress); initCause(exception); setStackTrace(exception.getStackTrace()); }
AnnotatedConnectException(ConnectException exception, SocketAddress remoteAddress) { super(exception.getMessage() + ": " + remoteAddress); initCause(exception); setStackTrace(exception.getStackTrace()); }
recv.notifyStreamOutgoingConnection ( id, "CONNECTION_REFUSED", e.getMessage() );