本文整理了Java中java.net.ConnectException.initCause()
方法的一些代码示例,展示了ConnectException.initCause()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ConnectException.initCause()
方法的具体详情如下:
包路径:java.net.ConnectException
类名称:ConnectException
方法名:initCause
暂无
代码示例来源:origin: redisson/redisson
final boolean failConnectPromise(Throwable cause) {
if (connectPromise != null) {
// SO_ERROR has been shown to return 0 on macOS if detect an error via read() and the write filter was
// not set before calling connect. This means finishConnect will not detect any error and would
// successfully complete the connectPromise and update the channel state to active (which is incorrect).
ChannelPromise connectPromise = AbstractKQueueChannel.this.connectPromise;
AbstractKQueueChannel.this.connectPromise = null;
if (connectPromise.tryFailure((cause instanceof ConnectException) ? cause
: new ConnectException("failed to connect").initCause(cause))) {
closeIfClosed();
return true;
}
}
return false;
}
代码示例来源:origin: wildfly/wildfly
final boolean failConnectPromise(Throwable cause) {
if (connectPromise != null) {
// SO_ERROR has been shown to return 0 on macOS if detect an error via read() and the write filter was
// not set before calling connect. This means finishConnect will not detect any error and would
// successfully complete the connectPromise and update the channel state to active (which is incorrect).
ChannelPromise connectPromise = AbstractKQueueChannel.this.connectPromise;
AbstractKQueueChannel.this.connectPromise = null;
if (connectPromise.tryFailure((cause instanceof ConnectException) ? cause
: new ConnectException("failed to connect").initCause(cause))) {
closeIfClosed();
return true;
}
}
return false;
}
代码示例来源:origin: square/okhttp
/** Does all the work necessary to build a full HTTP or HTTPS connection on a raw socket. */
private void connectSocket(int connectTimeout, int readTimeout, Call call,
EventListener eventListener) throws IOException {
Proxy proxy = route.proxy();
Address address = route.address();
rawSocket = proxy.type() == Proxy.Type.DIRECT || proxy.type() == Proxy.Type.HTTP
? address.socketFactory().createSocket()
: new Socket(proxy);
eventListener.connectStart(call, route.socketAddress(), proxy);
rawSocket.setSoTimeout(readTimeout);
try {
Platform.get().connectSocket(rawSocket, route.socketAddress(), connectTimeout);
} catch (ConnectException e) {
ConnectException ce = new ConnectException("Failed to connect to " + route.socketAddress());
ce.initCause(e);
throw ce;
}
// The following try/catch block is a pseudo hacky way to get around a crash on Android 7.0
// More details:
// https://github.com/square/okhttp/issues/3245
// https://android-review.googlesource.com/#/c/271775/
try {
source = Okio.buffer(Okio.source(rawSocket));
sink = Okio.buffer(Okio.sink(rawSocket));
} catch (NullPointerException npe) {
if (NPE_THROW_WITH_NULL.equals(npe.getMessage())) {
throw new IOException(npe);
}
}
}
代码示例来源:origin: AsyncHttpClient/async-http-client
public void onFailure(Channel channel, Throwable cause) {
// beware, channel can be null
Channels.silentlyCloseChannel(channel);
boolean canRetry = future.incrementRetryAndCheck();
LOGGER.debug("Trying to recover from failing to connect channel {} with a retry value of {} ", channel, canRetry);
if (canRetry//
&& cause != null // FIXME when can we have a null cause?
&& (future.getChannelState() != ChannelState.NEW || StackTraceInspector.recoverOnNettyDisconnectException(cause))) {
if (requestSender.retry(future)) {
return;
}
}
LOGGER.debug("Failed to recover from connect exception: {} with channel {}", cause, channel);
String message = cause.getMessage() != null ? cause.getMessage() : future.getUri().getBaseUrl();
ConnectException e = new ConnectException(message);
e.initCause(cause);
future.abort(e);
}
}
代码示例来源:origin: apache/hbase
"Call to " + addr + " failed on connection exception: " + exception).initCause(exception);
} else if (exception instanceof SocketTimeoutException) {
return (SocketTimeoutException) new SocketTimeoutException(
代码示例来源:origin: apache/geode
c.initCause(e);
} catch (SSLException e) {
ConnectException c = new ConnectException("Problem connecting to peer " + addr);
c.initCause(e);
throw c;
} catch (CancelledKeyException | ClosedSelectorException e) {
String.format("Attempt timed out after %s milliseconds",
connectTime));
c.initCause(e);
throw c;
代码示例来源:origin: prestodb/presto
/** Does all the work necessary to build a full HTTP or HTTPS connection on a raw socket. */
private void connectSocket(int connectTimeout, int readTimeout, Call call,
EventListener eventListener) throws IOException {
Proxy proxy = route.proxy();
Address address = route.address();
rawSocket = proxy.type() == Proxy.Type.DIRECT || proxy.type() == Proxy.Type.HTTP
? address.socketFactory().createSocket()
: new Socket(proxy);
eventListener.connectStart(call, route.socketAddress(), proxy);
rawSocket.setSoTimeout(readTimeout);
try {
Platform.get().connectSocket(rawSocket, route.socketAddress(), connectTimeout);
} catch (ConnectException e) {
ConnectException ce = new ConnectException("Failed to connect to " + route.socketAddress());
ce.initCause(e);
throw ce;
}
// The following try/catch block is a pseudo hacky way to get around a crash on Android 7.0
// More details:
// https://github.com/square/okhttp/issues/3245
// https://android-review.googlesource.com/#/c/271775/
try {
source = Okio.buffer(Okio.source(rawSocket));
sink = Okio.buffer(Okio.sink(rawSocket));
} catch (NullPointerException npe) {
if (NPE_THROW_WITH_NULL.equals(npe.getMessage())) {
throw new IOException(npe);
}
}
}
代码示例来源:origin: com.squareup.okhttp3/okhttp
/** Does all the work necessary to build a full HTTP or HTTPS connection on a raw socket. */
private void connectSocket(int connectTimeout, int readTimeout, Call call,
EventListener eventListener) throws IOException {
Proxy proxy = route.proxy();
Address address = route.address();
rawSocket = proxy.type() == Proxy.Type.DIRECT || proxy.type() == Proxy.Type.HTTP
? address.socketFactory().createSocket()
: new Socket(proxy);
eventListener.connectStart(call, route.socketAddress(), proxy);
rawSocket.setSoTimeout(readTimeout);
try {
Platform.get().connectSocket(rawSocket, route.socketAddress(), connectTimeout);
} catch (ConnectException e) {
ConnectException ce = new ConnectException("Failed to connect to " + route.socketAddress());
ce.initCause(e);
throw ce;
}
// The following try/catch block is a pseudo hacky way to get around a crash on Android 7.0
// More details:
// https://github.com/square/okhttp/issues/3245
// https://android-review.googlesource.com/#/c/271775/
try {
source = Okio.buffer(Okio.source(rawSocket));
sink = Okio.buffer(Okio.sink(rawSocket));
} catch (NullPointerException npe) {
if (NPE_THROW_WITH_NULL.equals(npe.getMessage())) {
throw new IOException(npe);
}
}
}
代码示例来源:origin: mttkay/ignition
ex.initCause(cause);
throw ex;
代码示例来源:origin: i2p/i2p.i2p
/**
* Take a socket from the accept queue.
* Only for subsession, throws IllegalStateException otherwise.
*
* @since 0.9.25
*/
private I2PSocket acceptSocket() throws ConnectException {
if (_acceptQueue == null)
throw new IllegalStateException();
try {
// TODO there's no CoDel or expiration in this queue
return _acceptQueue.take();
} catch (InterruptedException ie) {
ConnectException ce = new ConnectException("interrupted");
ce.initCause(ie);
throw ce;
}
}
代码示例来源:origin: org.eclipse.jgit/org.eclipse.jgit
/**
* Determine the proxy server (if any) needed to obtain a URL.
*
* @param proxySelector
* proxy support for the caller.
* @param u
* location of the server caller wants to talk to.
* @return proxy to communicate with the supplied URL.
* @throws java.net.ConnectException
* the proxy could not be computed as the supplied URL could not
* be read. This failure should never occur.
*/
public static Proxy proxyFor(ProxySelector proxySelector, URL u)
throws ConnectException {
try {
return proxySelector.select(u.toURI()).get(0);
} catch (URISyntaxException e) {
final ConnectException err;
err = new ConnectException(MessageFormat.format(JGitText.get().cannotDetermineProxyFor, u));
err.initCause(e);
throw err;
}
}
代码示例来源:origin: com.ning/async-http-client
private void onFutureFailure(Channel channel, Throwable cause) {
abortChannelPreemption();
boolean canRetry = future.canRetry();
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("Trying to recover from failing to connect channel " + channel + " with a retry value of " + canRetry, cause);
}
if (canRetry
&& cause != null
&& (future.getState() != NettyResponseFuture.STATE.NEW || StackTraceInspector.recoverOnDisconnectException(cause))) {
if (requestSender.retry(future))
return;
}
LOGGER.debug("Failed to recover from connect exception: {} with channel {}", cause, channel);
boolean printCause = cause != null && cause.getMessage() != null;
String printedCause = printCause ? cause.getMessage() : getBaseUrl(future.getUri());
ConnectException e = new ConnectException(printedCause);
if (cause != null) {
e.initCause(cause);
}
future.abort(e);
}
代码示例来源:origin: org.apache.hbase/hbase-client
"Call to " + addr + " failed on connection exception: " + exception).initCause(exception);
} else if (exception instanceof SocketTimeoutException) {
return (SocketTimeoutException) new SocketTimeoutException(
代码示例来源:origin: i2p/i2p.i2p
ce.initCause(ie);
throw ce;
ce.initCause(ie);
throw ce;
代码示例来源:origin: org.webpieces/core-channelmanager2
public void finishConnect() throws IOException {
try {
channel.finishConnect();
} catch(ConnectException e) {
ConnectException exc = new ConnectException("could not connect to="+isConnectingTo);
exc.initCause(e);
throw exc;
}
}
代码示例来源:origin: UrbanCode/terraform
protected int invokeMethod(HttpMethodBase method)
throws IOException {
int result;
try {
result = httpClient.executeMethod(method);
}
catch (ConnectException e) {
throw (ConnectException) new ConnectException(
"Failed connecting to " + method.getURI() + ": " + e.getMessage()).
initCause(e);
}
return result;
}
代码示例来源:origin: apache/activemq-artemis
final boolean failConnectPromise(Throwable cause) {
if (connectPromise != null) {
// SO_ERROR has been shown to return 0 on macOS if detect an error via read() and the write filter was
// not set before calling connect. This means finishConnect will not detect any error and would
// successfully complete the connectPromise and update the channel state to active (which is incorrect).
ChannelPromise connectPromise = AbstractKQueueChannel.this.connectPromise;
AbstractKQueueChannel.this.connectPromise = null;
if (connectPromise.tryFailure((cause instanceof ConnectException) ? cause
: new ConnectException("failed to connect").initCause(cause))) {
closeIfClosed();
return true;
}
}
return false;
}
代码示例来源:origin: apache/activemq-artemis
final boolean failConnectPromise(Throwable cause) {
if (connectPromise != null) {
// SO_ERROR has been shown to return 0 on macOS if detect an error via read() and the write filter was
// not set before calling connect. This means finishConnect will not detect any error and would
// successfully complete the connectPromise and update the channel state to active (which is incorrect).
ChannelPromise connectPromise = AbstractKQueueChannel.this.connectPromise;
AbstractKQueueChannel.this.connectPromise = null;
if (connectPromise.tryFailure((cause instanceof ConnectException) ? cause
: new ConnectException("failed to connect").initCause(cause))) {
closeIfClosed();
return true;
}
}
return false;
}
代码示例来源:origin: org.wildfly.core/wildfly-protocol
@Override
public final ConnectException failedToConnect(final URI uri, final Exception cause) {
final ConnectException result = new ConnectException(String.format(getLoggingLocale(), failedToConnect$str(), uri));
result.initCause(cause);
final StackTraceElement[] st = result.getStackTrace();
result.setStackTrace(Arrays.copyOfRange(st, 1, st.length));
return result;
}
private static final String channelClosed = "WFLYPRT0054: Channel closed";
代码示例来源:origin: wildfly/wildfly-core
@Override
public final ConnectException failedToConnect(final URI uri, final Exception cause) {
final ConnectException result = new ConnectException(String.format(getLoggingLocale(), failedToConnect$str(), uri));
result.initCause(cause);
final StackTraceElement[] st = result.getStackTrace();
result.setStackTrace(Arrays.copyOfRange(st, 1, st.length));
return result;
}
private static final String channelClosed = "WFLYPRT0054: Channel closed";
内容来源于网络,如有侵权,请联系作者删除!