From 287c84454f50d7ac2e52879eda3e77a2cba1de43 Mon Sep 17 00:00:00 2001 From: Andreas Schildbach Date: Tue, 11 Jun 2013 21:46:33 +0200 Subject: [PATCH] interpret HTTP_NOT_FOUND as expired session when querying for more connections --- .../schildbach/pte/AbstractEfaProvider.java | 5 ++ .../pte/exception/NotFoundException.java | 46 +++++++++++++++++++ .../de/schildbach/pte/util/ParserUtils.java | 9 ++++ 3 files changed, 60 insertions(+) create mode 100644 enabler/src/de/schildbach/pte/exception/NotFoundException.java diff --git a/enabler/src/de/schildbach/pte/AbstractEfaProvider.java b/enabler/src/de/schildbach/pte/AbstractEfaProvider.java index 4b04d965..aa574cc2 100644 --- a/enabler/src/de/schildbach/pte/AbstractEfaProvider.java +++ b/enabler/src/de/schildbach/pte/AbstractEfaProvider.java @@ -67,6 +67,7 @@ import de.schildbach.pte.dto.ResultHeader; import de.schildbach.pte.dto.StationDepartures; import de.schildbach.pte.dto.Stop; import de.schildbach.pte.exception.InvalidDataException; +import de.schildbach.pte.exception.NotFoundException; import de.schildbach.pte.exception.ParserException; import de.schildbach.pte.exception.ProtocolException; import de.schildbach.pte.exception.SessionExpiredException; @@ -1686,6 +1687,10 @@ public abstract class AbstractEfaProvider extends AbstractNetworkProvider { throw new ParserException(x); } + catch (final NotFoundException x) + { + throw new SessionExpiredException(); + } catch (final ProtocolException x) // must be html content { is.reset(); diff --git a/enabler/src/de/schildbach/pte/exception/NotFoundException.java b/enabler/src/de/schildbach/pte/exception/NotFoundException.java new file mode 100644 index 00000000..5d778903 --- /dev/null +++ b/enabler/src/de/schildbach/pte/exception/NotFoundException.java @@ -0,0 +1,46 @@ +/* + * Copyright 2013 the original author or authors. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package de.schildbach.pte.exception; + +import java.io.IOException; +import java.net.URL; + +/** + * @author Andreas Schildbach + */ +public class NotFoundException extends IOException +{ + private final URL url; + + public NotFoundException() + { + this.url = null; + } + + public NotFoundException(final URL url) + { + super(url.toString()); + + this.url = url; + } + + public URL getUrl() + { + return url; + } +} diff --git a/enabler/src/de/schildbach/pte/util/ParserUtils.java b/enabler/src/de/schildbach/pte/util/ParserUtils.java index b5b07c6b..b1b0d24b 100644 --- a/enabler/src/de/schildbach/pte/util/ParserUtils.java +++ b/enabler/src/de/schildbach/pte/util/ParserUtils.java @@ -40,6 +40,7 @@ import java.util.regex.Pattern; import java.util.zip.GZIPInputStream; import de.schildbach.pte.exception.BlockedException; +import de.schildbach.pte.exception.NotFoundException; import de.schildbach.pte.exception.UnexpectedRedirectException; /** @@ -197,6 +198,10 @@ public final class ParserUtils { throw new BlockedException(url); } + else if (responseCode == HttpURLConnection.HTTP_NOT_FOUND) + { + throw new NotFoundException(url); + } else { final String message = "got response: " + responseCode + " " + connection.getResponseMessage(); @@ -348,6 +353,10 @@ public final class ParserUtils { throw new BlockedException(url); } + else if (responseCode == HttpURLConnection.HTTP_NOT_FOUND) + { + throw new NotFoundException(url); + } else { final String message = "got response: " + responseCode + " " + connection.getResponseMessage();