Java Code Examples for java.net.SocketTimeoutException#getMessage()
The following examples show how to use
java.net.SocketTimeoutException#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: SocketClient.java From react-native-sockets with MIT License | 5 votes |
private void handleSocketTimeoutException(SocketTimeoutException e) { //debug log Log.e(eTag, "Client SocketTimeoutException", e); //emit event String message = e.getMessage(); WritableMap eventParams = Arguments.createMap(); eventParams.putString("error", e.getMessage()); sendEvent(mReactContext, event_timeout, eventParams); }
Example 2
Source File: BaseApi$TempRequestListener.java From MiBandDecompiled with Apache License 2.0 | 5 votes |
public void onSocketTimeoutException(SocketTimeoutException sockettimeoutexception) { Message message = c.obtainMessage(); message.obj = sockettimeoutexception.getMessage(); message.what = -8; c.sendMessage(message); }
Example 3
Source File: HttpClientExecutor.java From cs-actions with Apache License 2.0 | 5 votes |
public CloseableHttpResponse execute() { CloseableHttpResponse response; try { response = closeableHttpClient.execute(httpRequestBase, context); } catch (SocketTimeoutException ste) { throw new RuntimeException("Socket timeout: " + ste.getMessage(), ste); } catch (HttpHostConnectException connectEx) { throw new RuntimeException("Connection error: " + connectEx.getMessage(), connectEx); } catch (IOException e) { throw new RuntimeException("Error while executing http request: " + e.getMessage(), e); } return response; }
Example 4
Source File: BaseApi.java From letv with Apache License 2.0 | 4 votes |
public void onSocketTimeoutException(SocketTimeoutException socketTimeoutException) { Message obtainMessage = this.mHandler.obtainMessage(); obtainMessage.obj = socketTimeoutException.getMessage(); obtainMessage.what = -8; this.mHandler.sendMessage(obtainMessage); }
Example 5
Source File: NetUtils.java From hadoop with Apache License 2.0 | 4 votes |
/** * Like {@link NetUtils#connect(Socket, SocketAddress, int)} but * also takes a local address and port to bind the socket to. * * @param socket * @param endpoint the remote address * @param localAddr the local address to bind the socket to * @param timeout timeout in milliseconds */ public static void connect(Socket socket, SocketAddress endpoint, SocketAddress localAddr, int timeout) throws IOException { if (socket == null || endpoint == null || timeout < 0) { throw new IllegalArgumentException("Illegal argument for connect()"); } SocketChannel ch = socket.getChannel(); if (localAddr != null) { Class localClass = localAddr.getClass(); Class remoteClass = endpoint.getClass(); Preconditions.checkArgument(localClass.equals(remoteClass), "Local address %s must be of same family as remote address %s.", localAddr, endpoint); socket.bind(localAddr); } try { if (ch == null) { // let the default implementation handle it. socket.connect(endpoint, timeout); } else { SocketIOWithTimeout.connect(ch, endpoint, timeout); } } catch (SocketTimeoutException ste) { throw new ConnectTimeoutException(ste.getMessage()); } // There is a very rare case allowed by the TCP specification, such that // if we are trying to connect to an endpoint on the local machine, // and we end up choosing an ephemeral port equal to the destination port, // we will actually end up getting connected to ourself (ie any data we // send just comes right back). This is only possible if the target // daemon is down, so we'll treat it like connection refused. if (socket.getLocalPort() == socket.getPort() && socket.getLocalAddress().equals(socket.getInetAddress())) { LOG.info("Detected a loopback TCP socket, disconnecting it"); socket.close(); throw new ConnectException( "Localhost targeted connection resulted in a loopback. " + "No daemon is listening on the target port."); } }
Example 6
Source File: NetUtils.java From big-c with Apache License 2.0 | 4 votes |
/** * Like {@link NetUtils#connect(Socket, SocketAddress, int)} but * also takes a local address and port to bind the socket to. * * @param socket * @param endpoint the remote address * @param localAddr the local address to bind the socket to * @param timeout timeout in milliseconds */ public static void connect(Socket socket, SocketAddress endpoint, SocketAddress localAddr, int timeout) throws IOException { if (socket == null || endpoint == null || timeout < 0) { throw new IllegalArgumentException("Illegal argument for connect()"); } SocketChannel ch = socket.getChannel(); if (localAddr != null) { Class localClass = localAddr.getClass(); Class remoteClass = endpoint.getClass(); Preconditions.checkArgument(localClass.equals(remoteClass), "Local address %s must be of same family as remote address %s.", localAddr, endpoint); socket.bind(localAddr); } try { if (ch == null) { // let the default implementation handle it. socket.connect(endpoint, timeout); } else { SocketIOWithTimeout.connect(ch, endpoint, timeout); } } catch (SocketTimeoutException ste) { throw new ConnectTimeoutException(ste.getMessage()); } // There is a very rare case allowed by the TCP specification, such that // if we are trying to connect to an endpoint on the local machine, // and we end up choosing an ephemeral port equal to the destination port, // we will actually end up getting connected to ourself (ie any data we // send just comes right back). This is only possible if the target // daemon is down, so we'll treat it like connection refused. if (socket.getLocalPort() == socket.getPort() && socket.getLocalAddress().equals(socket.getInetAddress())) { LOG.info("Detected a loopback TCP socket, disconnecting it"); socket.close(); throw new ConnectException( "Localhost targeted connection resulted in a loopback. " + "No daemon is listening on the target port."); } }
Example 7
Source File: AbstractConnectProtocol.java From mariadb-connector-j with GNU Lesser General Public License v2.1 | 4 votes |
private void postConnectionQueries() throws SQLException { try { if (options.usePipelineAuth && (options.socketTimeout == null || options.socketTimeout == 0 || options.socketTimeout > 500)) { // set a timeout to avoid hang in case server doesn't support pipelining socket.setSoTimeout(500); } boolean mustLoadAdditionalInfo = true; if (globalInfo != null) { if (globalInfo.isAutocommit() == options.autocommit) { mustLoadAdditionalInfo = false; } } if (mustLoadAdditionalInfo) { Map<String, String> serverData = new TreeMap<>(); if (options.usePipelineAuth && !options.createDatabaseIfNotExist) { try { sendPipelineAdditionalData(); readPipelineAdditionalData(serverData); } catch (SQLException sqle) { if ("08".equals(sqle.getSQLState())) { throw sqle; } // in case pipeline is not supported // (proxy flush socket after reading first packet) additionalData(serverData); } } else { additionalData(serverData); } writer.setMaxAllowedPacket(Integer.parseInt(serverData.get("max_allowed_packet"))); autoIncrementIncrement = Integer.parseInt(serverData.get("auto_increment_increment")); loadCalendar(serverData.get("time_zone"), serverData.get("system_time_zone")); } else { writer.setMaxAllowedPacket((int) globalInfo.getMaxAllowedPacket()); autoIncrementIncrement = globalInfo.getAutoIncrementIncrement(); loadCalendar(globalInfo.getTimeZone(), globalInfo.getSystemTimeZone()); } reader.setServerThreadId(this.serverThreadId, isMasterConnection()); writer.setServerThreadId(this.serverThreadId, isMasterConnection()); activeStreamingResult = null; hostFailed = false; if (options.usePipelineAuth) { // reset timeout to configured value if (options.socketTimeout != null) { socket.setSoTimeout(options.socketTimeout); } else { socket.setSoTimeout(0); } } } catch (SocketTimeoutException timeoutException) { destroySocket(); String msg = "Socket error during post connection queries: " + timeoutException.getMessage(); if (options.usePipelineAuth) { msg += "\nServer might not support pipelining, try disabling with option `usePipelineAuth` and `useBatchMultiSend`"; } throw exceptionFactory.create(msg, "08000", timeoutException); } catch (IOException ioException) { destroySocket(); throw exceptionFactory.create( "Socket error during post connection queries: " + ioException.getMessage(), "08000", ioException); } catch (SQLException sqlException) { destroySocket(); throw sqlException; } }