use of java.net.SocketTimeoutException in project hadoop by apache.
the class TestIPC method testIpcTimeout.
@Test(timeout = 60000)
public void testIpcTimeout() throws IOException {
// start server
Server server = new TestServer(1, true);
InetSocketAddress addr = NetUtils.getConnectAddress(server);
server.start();
// start client
Client client = new Client(LongWritable.class, conf);
// set timeout to be less than MIN_SLEEP_TIME
try {
call(client, new LongWritable(RANDOM.nextLong()), addr, MIN_SLEEP_TIME / 2, conf);
fail("Expected an exception to have been thrown");
} catch (SocketTimeoutException e) {
LOG.info("Get a SocketTimeoutException ", e);
}
// set timeout to be bigger than 3*ping interval
call(client, new LongWritable(RANDOM.nextLong()), addr, 3 * PING_INTERVAL + MIN_SLEEP_TIME, conf);
client.stop();
}
use of java.net.SocketTimeoutException in project hadoop by apache.
the class KMSClientProvider method createConnection.
private HttpURLConnection createConnection(final URL url, String method) throws IOException {
HttpURLConnection conn;
try {
final String doAsUser = getDoAsUser();
conn = getActualUgi().doAs(new PrivilegedExceptionAction<HttpURLConnection>() {
@Override
public HttpURLConnection run() throws Exception {
DelegationTokenAuthenticatedURL authUrl = new DelegationTokenAuthenticatedURL(configurator);
return authUrl.openConnection(url, authToken, doAsUser);
}
});
} catch (IOException ex) {
if (ex instanceof SocketTimeoutException) {
LOG.warn("Failed to connect to {}:{}", url.getHost(), url.getPort());
}
throw ex;
} catch (UndeclaredThrowableException ex) {
throw new IOException(ex.getUndeclaredThrowable());
} catch (Exception ex) {
throw new IOException(ex);
}
conn.setUseCaches(false);
conn.setRequestMethod(method);
if (method.equals(HTTP_POST) || method.equals(HTTP_PUT)) {
conn.setDoOutput(true);
}
conn = configureConnection(conn);
return conn;
}
use of java.net.SocketTimeoutException in project camel by apache.
the class CxfTimeoutTest method sendTimeOutMessage.
protected void sendTimeOutMessage(String endpointUri) throws Exception {
Exchange reply = sendJaxWsMessage(endpointUri);
Exception e = reply.getException();
assertNotNull("We should get the exception cause here", e);
assertTrue("We should get the socket time out exception here", e instanceof SocketTimeoutException);
}
use of java.net.SocketTimeoutException in project camel by apache.
the class CxfMessageHeaderTimeoutTest method sendTimeOutMessage.
protected void sendTimeOutMessage(String endpointUri) throws Exception {
Exchange reply = sendJaxWsMessage(endpointUri);
Exception e = reply.getException();
assertNotNull("We should get the exception cause here", e);
assertTrue("We should get the socket time out exception here", e instanceof SocketTimeoutException);
}
use of java.net.SocketTimeoutException in project robovm by robovm.
the class PlainSocketFactory method connectSocket.
// non-javadoc, see interface org.apache.http.conn.SocketFactory
public Socket connectSocket(Socket sock, String host, int port, InetAddress localAddress, int localPort, HttpParams params) throws IOException {
if (host == null) {
throw new IllegalArgumentException("Target host may not be null.");
}
if (params == null) {
throw new IllegalArgumentException("Parameters may not be null.");
}
if (sock == null)
sock = createSocket();
if ((localAddress != null) || (localPort > 0)) {
// we need to bind explicitly
if (localPort < 0)
// indicates "any"
localPort = 0;
InetSocketAddress isa = new InetSocketAddress(localAddress, localPort);
sock.bind(isa);
}
int timeout = HttpConnectionParams.getConnectionTimeout(params);
InetSocketAddress remoteAddress;
if (this.nameResolver != null) {
remoteAddress = new InetSocketAddress(this.nameResolver.resolve(host), port);
} else {
remoteAddress = new InetSocketAddress(host, port);
}
try {
sock.connect(remoteAddress, timeout);
} catch (SocketTimeoutException ex) {
throw new ConnectTimeoutException("Connect to " + remoteAddress + " timed out");
}
return sock;
}
Aggregations