use of java.net.SocketTimeoutException in project Rutgers-Course-Tracker by tevjef.
the class CourseFragment method showError.
@Override
public void showError(Throwable t) {
String message;
Resources resources = getContext().getResources();
if (t instanceof UnknownHostException) {
message = resources.getString(R.string.no_internet);
} else if (t instanceof JsonParseException || t instanceof RutgersServerIOException) {
message = resources.getString(R.string.server_down);
} else if (t instanceof SocketTimeoutException) {
message = resources.getString(R.string.timed_out);
} else {
message = t.getMessage();
}
//error message finalized, now save it.
mViewState.errorMessage = message;
// Redirects the message that would usually be in the snackbar, to error layout.
if (!adapterHasItems()) {
showLayout(LayoutType.ERROR);
TextView textViewMessage = ButterKnife.findById(mErrorView, R.id.text);
textViewMessage.setText(message);
} else {
showSnackBar(message);
}
}
use of java.net.SocketTimeoutException in project Rutgers-Course-Tracker by tevjef.
the class TrackedSectionsFragment method showError.
@Override
public void showError(Throwable t) {
String message;
Resources resources = getContext().getResources();
if (t instanceof UnknownHostException) {
message = resources.getString(R.string.no_internet);
} else if (t instanceof JsonParseException || t instanceof RutgersServerIOException) {
message = resources.getString(R.string.server_down);
} else if (t instanceof SocketTimeoutException) {
message = resources.getString(R.string.timed_out);
} else {
message = t.getMessage();
}
// Save current error message ahead of config change.
mViewState.errorMessage = message;
// https://www.google.com/design/spec/patterns/errors.html#errors-app-errors
if (!adapterHasItems()) {
showLayout(LayoutType.ERROR);
TextView textViewMessage = ButterKnife.findById(mErrorView, R.id.text);
textViewMessage.setText(message);
} else {
showSnackBar(message);
}
}
use of java.net.SocketTimeoutException in project bazel by bazelbuild.
the class RetryingInputStreamTest method maxRetries_givesUp.
@Test
@SuppressWarnings("unchecked")
public void maxRetries_givesUp() throws Exception {
when(delegate.read()).thenReturn(1).thenThrow(new IOException()).thenThrow(new IOException()).thenThrow(new IOException()).thenThrow(new SocketTimeoutException());
when(reconnector.connect(any(Throwable.class), any(ImmutableMap.class))).thenReturn(connection);
when(connection.getInputStream()).thenReturn(delegate);
when(connection.getHeaderField("Content-Range")).thenReturn("bytes 1-42/42");
stream.read();
try {
stream.read();
fail("Expected SocketTimeoutException");
} catch (SocketTimeoutException e) {
assertThat(e.getSuppressed()).hasLength(3);
verify(reconnector, times(3)).connect(any(Throwable.class), eq(ImmutableMap.of("Range", "bytes 1-")));
verify(delegate, times(5)).read();
verify(delegate, times(3)).close();
}
}
use of java.net.SocketTimeoutException in project bazel by bazelbuild.
the class RetryingInputStreamTest method failureWhenNoBytesAreRead_doesntUseRange.
@Test
@SuppressWarnings("unchecked")
public void failureWhenNoBytesAreRead_doesntUseRange() throws Exception {
when(delegate.read()).thenThrow(new SocketTimeoutException());
when(newDelegate.read()).thenReturn(1);
when(reconnector.connect(any(Throwable.class), any(ImmutableMap.class))).thenReturn(connection);
when(connection.getInputStream()).thenReturn(newDelegate);
assertThat(stream.read()).isEqualTo(1);
verify(reconnector).connect(any(Throwable.class), eq(ImmutableMap.<String, String>of()));
verify(delegate).read();
verify(delegate).close();
verify(newDelegate).read();
}
use of java.net.SocketTimeoutException in project Conversations by siacs.
the class DNSHelper method queryDNS.
public static Bundle queryDNS(String host, InetAddress dnsServer) {
Bundle bundle = new Bundle();
try {
client.setTimeout(Config.SOCKET_TIMEOUT * 1000);
final String qname = "_xmpp-client._tcp." + host.toLowerCase(Locale.US);
final String tlsQname = "_xmpps-client._tcp." + host.toLowerCase(Locale.US);
Log.d(Config.LOGTAG, "using dns server: " + dnsServer.getHostAddress() + " to look up " + host);
final Map<Integer, List<TlsSrv>> priorities = new TreeMap<>();
final Map<String, List<String>> ips4 = new TreeMap<>();
final Map<String, List<String>> ips6 = new TreeMap<>();
fillSrvMaps(qname, dnsServer, priorities, ips4, ips6, false);
fillSrvMaps(tlsQname, dnsServer, priorities, ips4, ips6, true);
final List<TlsSrv> result = new ArrayList<>();
for (final List<TlsSrv> s : priorities.values()) {
result.addAll(s);
}
final ArrayList<Bundle> values = new ArrayList<>();
if (result.size() == 0) {
DNSMessage response;
try {
response = client.query(host, TYPE.A, CLASS.IN, dnsServer.getHostAddress());
for (int i = 0; i < response.getAnswers().length; ++i) {
values.add(createNamePortBundle(host, 5222, response.getAnswers()[i].getPayload(), false));
}
} catch (SocketTimeoutException e) {
Log.d(Config.LOGTAG, "ignoring timeout exception when querying A record on " + dnsServer.getHostAddress());
}
try {
response = client.query(host, TYPE.AAAA, CLASS.IN, dnsServer.getHostAddress());
for (int i = 0; i < response.getAnswers().length; ++i) {
values.add(createNamePortBundle(host, 5222, response.getAnswers()[i].getPayload(), false));
}
} catch (SocketTimeoutException e) {
Log.d(Config.LOGTAG, "ignoring timeout exception when querying AAAA record on " + dnsServer.getHostAddress());
}
values.add(createNamePortBundle(host, 5222, false));
bundle.putParcelableArrayList("values", values);
return bundle;
}
for (final TlsSrv tlsSrv : result) {
final SRV srv = tlsSrv.srv;
final String name = srv.getName() != null ? srv.getName().toLowerCase(Locale.US) : null;
if (ips6.containsKey(name)) {
values.add(createNamePortBundle(name, srv.getPort(), ips6, tlsSrv.tls));
} else {
try {
DNSMessage response = client.query(name, TYPE.AAAA, CLASS.IN, dnsServer.getHostAddress());
for (int i = 0; i < response.getAnswers().length; ++i) {
values.add(createNamePortBundle(name, srv.getPort(), response.getAnswers()[i].getPayload(), tlsSrv.tls));
}
} catch (SocketTimeoutException e) {
Log.d(Config.LOGTAG, "ignoring timeout exception when querying AAAA record on " + dnsServer.getHostAddress());
}
}
if (ips4.containsKey(name)) {
values.add(createNamePortBundle(name, srv.getPort(), ips4, tlsSrv.tls));
} else {
DNSMessage response = client.query(name, TYPE.A, CLASS.IN, dnsServer.getHostAddress());
for (int i = 0; i < response.getAnswers().length; ++i) {
values.add(createNamePortBundle(name, srv.getPort(), response.getAnswers()[i].getPayload(), tlsSrv.tls));
}
}
values.add(createNamePortBundle(name, srv.getPort(), tlsSrv.tls));
}
bundle.putParcelableArrayList("values", values);
} catch (SocketTimeoutException e) {
bundle.putString("error", "timeout");
} catch (Exception e) {
bundle.putString("error", "unhandled");
}
return bundle;
}
Aggregations