moved empty page retry mechanism to ParserUtils

git-svn-id: https://public-transport-enabler.googlecode.com/svn/trunk@83 0924bc21-9374-b0fa-ee44-9ff1593b38f0
This commit is contained in:
andreas.schildbach 2010-08-15 18:25:06 +00:00
parent f74f4419b7
commit 6648d8fa30
2 changed files with 14 additions and 19 deletions

View file

@ -213,12 +213,8 @@ public class MvvProvider implements NetworkProvider
final LocationType toType, final String to, final Date date, final boolean dep) throws IOException final LocationType toType, final String to, final Date date, final boolean dep) throws IOException
{ {
final String uri = connectionsQueryUri(fromType, from, viaType, via, toType, to, date, dep); final String uri = connectionsQueryUri(fromType, from, viaType, via, toType, to, date, dep);
CharSequence page = ParserUtils.scrape(uri);
while (page.length() == 0) final CharSequence page = ParserUtils.scrape(uri);
{
System.out.println("Got empty page, retrying...");
page = ParserUtils.scrape(uri);
}
final Matcher mError = P_CHECK_CONNECTIONS_ERROR.matcher(page); final Matcher mError = P_CHECK_CONNECTIONS_ERROR.matcher(page);
if (mError.find()) if (mError.find())
@ -266,12 +262,7 @@ public class MvvProvider implements NetworkProvider
public QueryConnectionsResult queryMoreConnections(final String uri) throws IOException public QueryConnectionsResult queryMoreConnections(final String uri) throws IOException
{ {
CharSequence page = ParserUtils.scrape(uri); final CharSequence page = ParserUtils.scrape(uri);
while (page.length() == 0)
{
System.out.println("Got empty page, retrying...");
page = ParserUtils.scrape(uri);
}
return queryConnections(uri, page); return queryConnections(uri, page);
} }
@ -383,12 +374,7 @@ public class MvvProvider implements NetworkProvider
public GetConnectionDetailsResult getConnectionDetails(final String uri) throws IOException public GetConnectionDetailsResult getConnectionDetails(final String uri) throws IOException
{ {
CharSequence page = ParserUtils.scrape(uri); final CharSequence page = ParserUtils.scrape(uri);
while (page.length() == 0)
{
System.out.println("Got empty page, retrying...");
page = ParserUtils.scrape(uri);
}
final Matcher mHead = P_CONNECTION_DETAILS_HEAD.matcher(page); final Matcher mHead = P_CONNECTION_DETAILS_HEAD.matcher(page);
if (mHead.matches()) if (mHead.matches())

View file

@ -85,7 +85,16 @@ public final class ParserUtils
} }
pageReader.close(); pageReader.close();
return buffer;
if (buffer.length() > 0)
return buffer;
else
{
if (tries-- > 0)
System.out.println("got empty page, retrying...");
else
throw new IOException("got empty page: " + url);
}
} }
catch (final SocketTimeoutException x) catch (final SocketTimeoutException x)
{ {