Java Code Examples for java.net.ConnectException#getMessage()

The following examples show how to use java.net.ConnectException#getMessage() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: NioClientBoss.java    From simple-netty-source with Apache License 2.0 6 votes vote down vote up
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;
    }
}
 
Example 2
Source File: HttpAuthClient.java    From monasca-common with Apache License 2.0 6 votes vote down vote up
private HttpResponse sendGet(HttpGet httpGet)
    throws ClientProtocolException {
  HttpResponse response;

  if (appConfig.getAdminAuthMethod().equalsIgnoreCase(Config.TOKEN)) {
    httpGet.setHeader(new BasicHeader(TOKEN, appConfig.getAdminToken()));
  } else {
    httpGet.setHeader(new BasicHeader(TOKEN, getAdminToken()));
  }

  try {

    response = client.execute(httpGet);

  } catch (ConnectException c) {
    httpGet.abort();
    throw new ServiceUnavailableException(c.getMessage());
  } catch (IOException e) {
    httpGet.abort();

    throw new ClientProtocolException(
        "IO Exception during GET request ", e);
  }
  return response;
}
 
Example 3
Source File: TcpConnectorService.java    From linstor-server with GNU General Public License v3.0 5 votes vote down vote up
protected void establishConnection(SelectionKey currentKey)
    throws IOException
{
    // first, remove OP_Connect interest (fixes an immediate return of selector.select()
    // with no ready keys bug)
    currentKey.interestOps(0); // when controller wants to send a message, this will be changed to
    // OP_WRITE automatically

    @SuppressWarnings("resource")
    SocketChannel channel = (SocketChannel) currentKey.channel();
    Peer peer = (Peer) currentKey.attachment();
    try
    {
        channel.finishConnect();
        peer.connectionEstablished();
        connObserver.outboundConnectionEstablished(peer);
    }
    catch (ConnectException conExc)
    {
        String message = conExc.getMessage();
        errorReporter.logTrace(
            "Outbound connection to " + peer +
            " failed" +
            (message != null ? ": " + message : "")
        );
    }
    catch (NoRouteToHostException noRouteExc)
    {
        // ignore, Reconnector will retry later
    }
}
 
Example 4
Source File: StateUtils.java    From HouSi with Apache License 2.0 5 votes vote down vote up
public static String handleException(Throwable e) {
    if (e instanceof HttpException) {
        HttpException httpException = (HttpException) e;
        return httpException.code() + " " + httpException.message();
    } else if (e instanceof ConnectException) {
        ConnectException connectException = (ConnectException) e;
        return connectException.getMessage();
    } else {
        return "unknown error";
    }
}
 
Example 5
Source File: NetUtils.java    From BIMserver with GNU Affero General Public License v3.0 5 votes vote down vote up
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() + ")");
	}
}
 
Example 6
Source File: AbstractChannel.java    From netty-4.1.22 with Apache License 2.0 4 votes vote down vote up
AnnotatedConnectException(ConnectException exception, SocketAddress remoteAddress) {
    super(exception.getMessage() + ": " + remoteAddress);
    initCause(exception);
    setStackTrace(exception.getStackTrace());
}
 
Example 7
Source File: RetryableConnectException.java    From servicetalk with Apache License 2.0 4 votes vote down vote up
/**
 * Create a new instance.
 * @param cause the original cause.
 */
public RetryableConnectException(final ConnectException cause) {
    super(cause.getMessage());
    initCause(cause);
}