java.net.ConnectException.getMessage()方法的使用及代码示例

x33g5p2x  于2022-01-18 转载在 其他  
字(7.4k)|赞(0)|评价(0)|浏览(119)

本文整理了Java中java.net.ConnectException.getMessage()方法的一些代码示例,展示了ConnectException.getMessage()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ConnectException.getMessage()方法的具体详情如下:
包路径:java.net.ConnectException
类名称:ConnectException
方法名:getMessage

ConnectException.getMessage介绍

暂无

代码示例

代码示例来源:origin: apache/zeppelin

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;
 }
}

代码示例来源:origin: k9mail/k-9

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;
  }
}

代码示例来源:origin: netty/netty

AnnotatedConnectException(ConnectException exception, SocketAddress remoteAddress) {
  super(exception.getMessage() + ": " + remoteAddress);
  initCause(exception);
  setStackTrace(exception.getStackTrace());
}

代码示例来源:origin: redisson/redisson

AnnotatedConnectException(ConnectException exception, SocketAddress remoteAddress) {
  super(exception.getMessage() + ": " + remoteAddress);
  initCause(exception);
  setStackTrace(exception.getStackTrace());
}

代码示例来源:origin: io.netty/netty

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;
  }
}

代码示例来源:origin: wildfly/wildfly

AnnotatedConnectException(ConnectException exception, SocketAddress remoteAddress) {
  super(exception.getMessage() + ": " + remoteAddress);
  initCause(exception);
  setStackTrace(exception.getStackTrace());
}

代码示例来源:origin: alibaba/nacos

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());

代码示例来源:origin: mpetazzoni/ttorrent

throw new AnnounceException(e.getMessage(), e);

代码示例来源:origin: voldemort/voldemort

ex.getCause().getClass());
assertEquals("InnerException is connect Exception",
       connectEx.getMessage(),
       ex.getCause().getMessage());

代码示例来源:origin: opensourceBIM/BIMserver

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() + ")");
  }
}

代码示例来源:origin: dadoonet/fscrawler

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")));
  }
}

代码示例来源:origin: org.eclipse.jgit/org.eclipse.jgit

/**
 * 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$
  }
}

代码示例来源:origin: org.eclipse.jgit/org.eclipse.jgit

/**
 * 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$
  }
}

代码示例来源:origin: adyliu/jafka

logger.error("Reconnect fail and recur now: {}",ce.getMessage());
LockSupport.parkNanos(TimeUnit.SECONDS.toNanos(1));
return send(request);

代码示例来源:origin: haraldk/TwelveMonkeys

pResponse.sendError(HttpServletResponse.SC_BAD_GATEWAY, e.getMessage());

代码示例来源:origin: magefree/mage

} catch (ConnectException ex) {
  String message;
  if (ex.getMessage() != null) {
    message = ex.getMessage();
  } else {
    message = "Unknown error";

代码示例来源:origin: i2p/i2p.i2p

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))

代码示例来源:origin: apache/activemq-artemis

AnnotatedConnectException(ConnectException exception, SocketAddress remoteAddress) {
  super(exception.getMessage() + ": " + remoteAddress);
  initCause(exception);
  setStackTrace(exception.getStackTrace());
}

代码示例来源:origin: org.apache.hbase.thirdparty/hbase-shaded-netty

AnnotatedConnectException(ConnectException exception, SocketAddress remoteAddress) {
  super(exception.getMessage() + ": " + remoteAddress);
  initCause(exception);
  setStackTrace(exception.getStackTrace());
}

代码示例来源:origin: i2p/i2p.i2p

recv.notifyStreamOutgoingConnection ( id, "CONNECTION_REFUSED", e.getMessage() );

相关文章