mirror of
https://gitlab.com/oeffi/public-transport-enabler.git
synced 2025-07-13 16:20:34 +00:00
handle typical network exceptions in AsyncTasks
git-svn-id: https://public-transport-enabler.googlecode.com/svn/trunk@343 0924bc21-9374-b0fa-ee44-9ff1593b38f0
This commit is contained in:
parent
45465a87ee
commit
114f8db546
5 changed files with 12 additions and 53 deletions
|
@ -17,10 +17,8 @@
|
|||
|
||||
package de.schildbach.pte;
|
||||
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.SocketTimeoutException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
|
@ -113,10 +111,6 @@ public abstract class AbstractEfaProvider implements NetworkProvider
|
|||
{
|
||||
throw new RuntimeException(x);
|
||||
}
|
||||
catch (final SocketTimeoutException x)
|
||||
{
|
||||
throw new RuntimeException(x);
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (is != null)
|
||||
|
@ -289,13 +283,13 @@ public abstract class AbstractEfaProvider implements NetworkProvider
|
|||
stations.add(ownStation);
|
||||
|
||||
if (maxStations == 0 || maxStations >= stations.size())
|
||||
return new NearbyStationsResult(uri, stations);
|
||||
return new NearbyStationsResult(stations);
|
||||
else
|
||||
return new NearbyStationsResult(uri, stations.subList(0, maxStations));
|
||||
return new NearbyStationsResult(stations.subList(0, maxStations));
|
||||
}
|
||||
else if ("notidentified".equals(nameState))
|
||||
{
|
||||
return new NearbyStationsResult(uri, NearbyStationsResult.Status.INVALID_STATION);
|
||||
return new NearbyStationsResult(NearbyStationsResult.Status.INVALID_STATION);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -306,14 +300,6 @@ public abstract class AbstractEfaProvider implements NetworkProvider
|
|||
{
|
||||
throw new RuntimeException(x);
|
||||
}
|
||||
catch (final FileNotFoundException x)
|
||||
{
|
||||
return new NearbyStationsResult(uri, NearbyStationsResult.Status.SERVICE_DOWN);
|
||||
}
|
||||
catch (final SocketTimeoutException x)
|
||||
{
|
||||
return new NearbyStationsResult(uri, NearbyStationsResult.Status.SERVICE_DOWN);
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (is != null)
|
||||
|
@ -792,14 +778,6 @@ public abstract class AbstractEfaProvider implements NetworkProvider
|
|||
{
|
||||
throw new RuntimeException(x);
|
||||
}
|
||||
catch (final FileNotFoundException x)
|
||||
{
|
||||
return new QueryDeparturesResult(QueryDeparturesResult.Status.SERVICE_DOWN, Integer.parseInt(stationId));
|
||||
}
|
||||
catch (final SocketTimeoutException x)
|
||||
{
|
||||
return new QueryDeparturesResult(QueryDeparturesResult.Status.SERVICE_DOWN, Integer.parseInt(stationId));
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (is != null)
|
||||
|
@ -855,10 +833,6 @@ public abstract class AbstractEfaProvider implements NetworkProvider
|
|||
is = ParserUtils.scrapeInputStream(uri);
|
||||
return queryConnections(uri, is);
|
||||
}
|
||||
catch (final SocketTimeoutException x)
|
||||
{
|
||||
return new QueryConnectionsResult(QueryConnectionsResult.Status.SERVICE_DOWN);
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (is != null)
|
||||
|
@ -874,10 +848,6 @@ public abstract class AbstractEfaProvider implements NetworkProvider
|
|||
is = ParserUtils.scrapeInputStream(uri);
|
||||
return queryConnections(uri, is);
|
||||
}
|
||||
catch (final SocketTimeoutException x)
|
||||
{
|
||||
return new QueryConnectionsResult(QueryConnectionsResult.Status.SERVICE_DOWN);
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (is != null)
|
||||
|
|
|
@ -19,7 +19,6 @@ package de.schildbach.pte;
|
|||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.SocketTimeoutException;
|
||||
import java.text.DateFormat;
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
|
@ -178,10 +177,6 @@ public abstract class AbstractHafasProvider implements NetworkProvider
|
|||
{
|
||||
throw new RuntimeException(x);
|
||||
}
|
||||
catch (final SocketTimeoutException x)
|
||||
{
|
||||
throw new RuntimeException(x);
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (is != null)
|
||||
|
@ -254,6 +249,7 @@ public abstract class AbstractHafasProvider implements NetworkProvider
|
|||
final DateFormat DATE_FORMAT = new SimpleDateFormat("yyyyMMdd");
|
||||
|
||||
InputStream is = null;
|
||||
|
||||
try
|
||||
{
|
||||
is = ParserUtils.scrapeInputStream(apiUri, wrap(request));
|
||||
|
@ -479,10 +475,6 @@ public abstract class AbstractHafasProvider implements NetworkProvider
|
|||
{
|
||||
throw new RuntimeException(x);
|
||||
}
|
||||
catch (final SocketTimeoutException x)
|
||||
{
|
||||
throw new RuntimeException(x);
|
||||
}
|
||||
catch (final ParseException x)
|
||||
{
|
||||
throw new RuntimeException(x);
|
||||
|
@ -770,9 +762,9 @@ public abstract class AbstractHafasProvider implements NetworkProvider
|
|||
}
|
||||
|
||||
if (maxStations == 0 || maxStations >= stations.size())
|
||||
return new NearbyStationsResult(uri, stations);
|
||||
return new NearbyStationsResult(stations);
|
||||
else
|
||||
return new NearbyStationsResult(uri, stations.subList(0, maxStations));
|
||||
return new NearbyStationsResult(stations.subList(0, maxStations));
|
||||
}
|
||||
|
||||
protected static final Pattern P_NORMALIZE_LINE = Pattern.compile("([A-Za-zÄÖÜäöüßáàâéèêíìîóòôúùû/-]+)[\\s-]*(.*)");
|
||||
|
|
|
@ -125,9 +125,9 @@ public final class BahnProvider extends AbstractHafasProvider
|
|||
}
|
||||
|
||||
if (maxStations == 0 || maxStations >= stations.size())
|
||||
return new NearbyStationsResult(uri, stations);
|
||||
return new NearbyStationsResult(stations);
|
||||
else
|
||||
return new NearbyStationsResult(uri, stations.subList(0, maxStations));
|
||||
return new NearbyStationsResult(stations.subList(0, maxStations));
|
||||
}
|
||||
|
||||
private String connectionsQueryUri(final Location from, final Location via, final Location to, final Date date, final boolean dep)
|
||||
|
|
|
@ -119,9 +119,9 @@ public class MvvProvider extends AbstractEfaProvider
|
|||
}
|
||||
|
||||
if (maxStations == 0 || maxStations >= stations.size())
|
||||
return new NearbyStationsResult(uri, stations);
|
||||
return new NearbyStationsResult(stations);
|
||||
else
|
||||
return new NearbyStationsResult(uri, stations.subList(0, maxStations));
|
||||
return new NearbyStationsResult(stations.subList(0, maxStations));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -29,20 +29,17 @@ public final class NearbyStationsResult
|
|||
OK, INVALID_STATION, SERVICE_DOWN
|
||||
}
|
||||
|
||||
public final String uri;
|
||||
public final Status status;
|
||||
public final List<Station> stations;
|
||||
|
||||
public NearbyStationsResult(final String uri, List<Station> stations)
|
||||
public NearbyStationsResult(final List<Station> stations)
|
||||
{
|
||||
this.uri = uri;
|
||||
this.status = Status.OK;
|
||||
this.stations = stations;
|
||||
}
|
||||
|
||||
public NearbyStationsResult(final String uri, final Status status)
|
||||
public NearbyStationsResult(final Status status)
|
||||
{
|
||||
this.uri = uri;
|
||||
this.status = status;
|
||||
this.stations = null;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue