mirror of
https://gitlab.com/oeffi/public-transport-enabler.git
synced 2025-07-14 08:40:29 +00:00
When failing to parsing XML, always include the first part of the content into ParseException.
This commit is contained in:
parent
6c02caf0f4
commit
cbf19ab96e
2 changed files with 52 additions and 14 deletions
|
@ -372,9 +372,12 @@ public abstract class AbstractEfaProvider extends AbstractNetworkProvider
|
||||||
// System.out.println(parameters);
|
// System.out.println(parameters);
|
||||||
|
|
||||||
InputStream is = null;
|
InputStream is = null;
|
||||||
|
String firstChars = null;
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
is = ParserUtils.scrapeInputStream(uri.toString(), httpPost ? parameters.substring(1) : null, null, httpReferer, null, 3);
|
is = ParserUtils.scrapeInputStream(uri.toString(), httpPost ? parameters.substring(1) : null, null, httpReferer, null, 3);
|
||||||
|
firstChars = ParserUtils.peekFirstChars(is);
|
||||||
|
|
||||||
final XmlPullParser pp = parserFactory.newPullParser();
|
final XmlPullParser pp = parserFactory.newPullParser();
|
||||||
pp.setInput(is, null);
|
pp.setInput(is, null);
|
||||||
|
@ -423,7 +426,7 @@ public abstract class AbstractEfaProvider extends AbstractNetworkProvider
|
||||||
}
|
}
|
||||||
catch (final XmlPullParserException x)
|
catch (final XmlPullParserException x)
|
||||||
{
|
{
|
||||||
throw new ParserException(x);
|
throw new ParserException("cannot parse xml: " + firstChars, x);
|
||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
|
@ -495,9 +498,12 @@ public abstract class AbstractEfaProvider extends AbstractNetworkProvider
|
||||||
// System.out.println(parameters);
|
// System.out.println(parameters);
|
||||||
|
|
||||||
InputStream is = null;
|
InputStream is = null;
|
||||||
|
String firstChars = null;
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
is = ParserUtils.scrapeInputStream(uri.toString(), httpPost ? parameters.substring(1) : null, null, httpReferer, null, 3);
|
is = ParserUtils.scrapeInputStream(uri.toString(), httpPost ? parameters.substring(1) : null, null, httpReferer, null, 3);
|
||||||
|
firstChars = ParserUtils.peekFirstChars(is);
|
||||||
|
|
||||||
final XmlPullParser pp = parserFactory.newPullParser();
|
final XmlPullParser pp = parserFactory.newPullParser();
|
||||||
pp.setInput(is, null);
|
pp.setInput(is, null);
|
||||||
|
@ -572,7 +578,7 @@ public abstract class AbstractEfaProvider extends AbstractNetworkProvider
|
||||||
}
|
}
|
||||||
catch (final XmlPullParserException x)
|
catch (final XmlPullParserException x)
|
||||||
{
|
{
|
||||||
throw new ParserException(x);
|
throw new ParserException("cannot parse xml: " + firstChars, x);
|
||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
|
@ -607,9 +613,12 @@ public abstract class AbstractEfaProvider extends AbstractNetworkProvider
|
||||||
// System.out.println(parameters);
|
// System.out.println(parameters);
|
||||||
|
|
||||||
InputStream is = null;
|
InputStream is = null;
|
||||||
|
String firstChars = null;
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
is = ParserUtils.scrapeInputStream(uri.toString(), httpPost ? parameters.substring(1) : null, null, httpReferer, null, 3);
|
is = ParserUtils.scrapeInputStream(uri.toString(), httpPost ? parameters.substring(1) : null, null, httpReferer, null, 3);
|
||||||
|
firstChars = ParserUtils.peekFirstChars(is);
|
||||||
|
|
||||||
final XmlPullParser pp = parserFactory.newPullParser();
|
final XmlPullParser pp = parserFactory.newPullParser();
|
||||||
pp.setInput(is, null);
|
pp.setInput(is, null);
|
||||||
|
@ -654,7 +663,7 @@ public abstract class AbstractEfaProvider extends AbstractNetworkProvider
|
||||||
}
|
}
|
||||||
catch (final XmlPullParserException x)
|
catch (final XmlPullParserException x)
|
||||||
{
|
{
|
||||||
throw new ParserException(x);
|
throw new ParserException("cannot parse xml: " + firstChars, x);
|
||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
|
@ -675,9 +684,12 @@ public abstract class AbstractEfaProvider extends AbstractNetworkProvider
|
||||||
// System.out.println(parameters);
|
// System.out.println(parameters);
|
||||||
|
|
||||||
InputStream is = null;
|
InputStream is = null;
|
||||||
|
String firstChars = null;
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
is = ParserUtils.scrapeInputStream(uri.toString(), httpPost ? parameters.substring(1) : null, null, httpReferer, null, 3);
|
is = ParserUtils.scrapeInputStream(uri.toString(), httpPost ? parameters.substring(1) : null, null, httpReferer, null, 3);
|
||||||
|
firstChars = ParserUtils.peekFirstChars(is);
|
||||||
|
|
||||||
final XmlPullParser pp = parserFactory.newPullParser();
|
final XmlPullParser pp = parserFactory.newPullParser();
|
||||||
pp.setInput(is, null);
|
pp.setInput(is, null);
|
||||||
|
@ -726,7 +738,7 @@ public abstract class AbstractEfaProvider extends AbstractNetworkProvider
|
||||||
}
|
}
|
||||||
catch (final XmlPullParserException x)
|
catch (final XmlPullParserException x)
|
||||||
{
|
{
|
||||||
throw new ParserException(x);
|
throw new ParserException("cannot parse xml: " + firstChars, x);
|
||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
|
@ -949,9 +961,12 @@ public abstract class AbstractEfaProvider extends AbstractNetworkProvider
|
||||||
// System.out.println(parameters);
|
// System.out.println(parameters);
|
||||||
|
|
||||||
InputStream is = null;
|
InputStream is = null;
|
||||||
|
String firstChars = null;
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
is = ParserUtils.scrapeInputStream(uri.toString(), httpPost ? parameters.substring(1) : null, null, httpReferer, "NSC_", 3);
|
is = ParserUtils.scrapeInputStream(uri.toString(), httpPost ? parameters.substring(1) : null, null, httpReferer, "NSC_", 3);
|
||||||
|
firstChars = ParserUtils.peekFirstChars(is);
|
||||||
|
|
||||||
final XmlPullParser pp = parserFactory.newPullParser();
|
final XmlPullParser pp = parserFactory.newPullParser();
|
||||||
pp.setInput(is, null);
|
pp.setInput(is, null);
|
||||||
|
@ -1027,7 +1042,7 @@ public abstract class AbstractEfaProvider extends AbstractNetworkProvider
|
||||||
}
|
}
|
||||||
catch (final XmlPullParserException x)
|
catch (final XmlPullParserException x)
|
||||||
{
|
{
|
||||||
throw new ParserException(x);
|
throw new ParserException("cannot parse xml: " + firstChars, x);
|
||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
|
@ -1473,10 +1488,12 @@ public abstract class AbstractEfaProvider extends AbstractNetworkProvider
|
||||||
// System.out.println(parameters);
|
// System.out.println(parameters);
|
||||||
|
|
||||||
InputStream is = null;
|
InputStream is = null;
|
||||||
|
String firstChars = null;
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
is = ParserUtils.scrapeInputStream(uri.toString(), httpPost ? parameters.substring(1) : null, null, httpReferer, null, 3);
|
is = ParserUtils.scrapeInputStream(uri.toString(), httpPost ? parameters.substring(1) : null, null, httpReferer, null, 3);
|
||||||
final String firstChars = ParserUtils.peekFirstChars(is);
|
firstChars = ParserUtils.peekFirstChars(is);
|
||||||
|
|
||||||
final XmlPullParser pp = parserFactory.newPullParser();
|
final XmlPullParser pp = parserFactory.newPullParser();
|
||||||
pp.setInput(is, null);
|
pp.setInput(is, null);
|
||||||
|
@ -1664,7 +1681,7 @@ public abstract class AbstractEfaProvider extends AbstractNetworkProvider
|
||||||
}
|
}
|
||||||
catch (final XmlPullParserException x)
|
catch (final XmlPullParserException x)
|
||||||
{
|
{
|
||||||
throw new ParserException(x);
|
throw new ParserException("cannot parse xml: " + firstChars, x);
|
||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
|
@ -1685,9 +1702,12 @@ public abstract class AbstractEfaProvider extends AbstractNetworkProvider
|
||||||
// System.out.println(parameters);
|
// System.out.println(parameters);
|
||||||
|
|
||||||
InputStream is = null;
|
InputStream is = null;
|
||||||
|
String firstChars = null;
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
is = ParserUtils.scrapeInputStream(uri.toString(), httpPost ? parameters.substring(1) : null, null, httpReferer, null, 3);
|
is = ParserUtils.scrapeInputStream(uri.toString(), httpPost ? parameters.substring(1) : null, null, httpReferer, null, 3);
|
||||||
|
firstChars = ParserUtils.peekFirstChars(is);
|
||||||
|
|
||||||
final XmlPullParser pp = parserFactory.newPullParser();
|
final XmlPullParser pp = parserFactory.newPullParser();
|
||||||
pp.setInput(is, null);
|
pp.setInput(is, null);
|
||||||
|
@ -1753,7 +1773,7 @@ public abstract class AbstractEfaProvider extends AbstractNetworkProvider
|
||||||
}
|
}
|
||||||
catch (final XmlPullParserException x)
|
catch (final XmlPullParserException x)
|
||||||
{
|
{
|
||||||
throw new ParserException(x);
|
throw new ParserException("cannot parse xml: " + firstChars, x);
|
||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
|
@ -2150,14 +2170,18 @@ public abstract class AbstractEfaProvider extends AbstractNetworkProvider
|
||||||
// System.out.println(parameters);
|
// System.out.println(parameters);
|
||||||
|
|
||||||
InputStream is = null;
|
InputStream is = null;
|
||||||
|
String firstChars = null;
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
is = ParserUtils.scrapeInputStream(uri.toString(), httpPost ? parameters.substring(1) : null, null, httpRefererTrip, "NSC_", 3);
|
is = ParserUtils.scrapeInputStream(uri.toString(), httpPost ? parameters.substring(1) : null, null, httpRefererTrip, "NSC_", 3);
|
||||||
|
firstChars = ParserUtils.peekFirstChars(is);
|
||||||
|
|
||||||
return queryTrips(uri.toString(), is);
|
return queryTrips(uri.toString(), is);
|
||||||
}
|
}
|
||||||
catch (final XmlPullParserException x)
|
catch (final XmlPullParserException x)
|
||||||
{
|
{
|
||||||
throw new ParserException(x);
|
throw new ParserException("cannot parse xml: " + firstChars, x);
|
||||||
}
|
}
|
||||||
catch (final RuntimeException x)
|
catch (final RuntimeException x)
|
||||||
{
|
{
|
||||||
|
@ -2185,14 +2209,18 @@ public abstract class AbstractEfaProvider extends AbstractNetworkProvider
|
||||||
// System.out.println(parameters);
|
// System.out.println(parameters);
|
||||||
|
|
||||||
InputStream is = null;
|
InputStream is = null;
|
||||||
|
String firstChars = null;
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
is = ParserUtils.scrapeInputStream(uri.toString(), httpPost ? parameters.substring(1) : null, null, httpRefererTrip, "NSC_", 3);
|
is = ParserUtils.scrapeInputStream(uri.toString(), httpPost ? parameters.substring(1) : null, null, httpRefererTrip, "NSC_", 3);
|
||||||
|
firstChars = ParserUtils.peekFirstChars(is);
|
||||||
|
|
||||||
return queryTripsMobile(uri.toString(), from, via, to, is);
|
return queryTripsMobile(uri.toString(), from, via, to, is);
|
||||||
}
|
}
|
||||||
catch (final XmlPullParserException x)
|
catch (final XmlPullParserException x)
|
||||||
{
|
{
|
||||||
throw new ParserException(x);
|
throw new ParserException("cannot parse xml: " + firstChars, x);
|
||||||
}
|
}
|
||||||
catch (final RuntimeException x)
|
catch (final RuntimeException x)
|
||||||
{
|
{
|
||||||
|
@ -2215,16 +2243,19 @@ public abstract class AbstractEfaProvider extends AbstractNetworkProvider
|
||||||
uri.append("&command=").append(later ? "tripNext" : "tripPrev");
|
uri.append("&command=").append(later ? "tripNext" : "tripPrev");
|
||||||
|
|
||||||
InputStream is = null;
|
InputStream is = null;
|
||||||
|
String firstChars = null;
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
is = ParserUtils.scrapeInputStream(uri.toString(), null, null, httpRefererTrip, "NSC_", 3);
|
is = ParserUtils.scrapeInputStream(uri.toString(), null, null, httpRefererTrip, "NSC_", 3);
|
||||||
|
firstChars = ParserUtils.peekFirstChars(is);
|
||||||
is.mark(512);
|
is.mark(512);
|
||||||
|
|
||||||
return queryTrips(uri.toString(), is);
|
return queryTrips(uri.toString(), is);
|
||||||
}
|
}
|
||||||
catch (final XmlPullParserException x)
|
catch (final XmlPullParserException x)
|
||||||
{
|
{
|
||||||
throw new ParserException(x);
|
throw new ParserException("cannot parse xml: " + firstChars, x);
|
||||||
}
|
}
|
||||||
catch (final FileNotFoundException x)
|
catch (final FileNotFoundException x)
|
||||||
{
|
{
|
||||||
|
@ -2261,16 +2292,19 @@ public abstract class AbstractEfaProvider extends AbstractNetworkProvider
|
||||||
uri.append("&command=").append(later ? "tripNext" : "tripPrev");
|
uri.append("&command=").append(later ? "tripNext" : "tripPrev");
|
||||||
|
|
||||||
InputStream is = null;
|
InputStream is = null;
|
||||||
|
String firstChars = null;
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
is = ParserUtils.scrapeInputStream(uri.toString(), null, null, httpRefererTrip, "NSC_", 3);
|
is = ParserUtils.scrapeInputStream(uri.toString(), null, null, httpRefererTrip, "NSC_", 3);
|
||||||
|
firstChars = ParserUtils.peekFirstChars(is);
|
||||||
is.mark(512);
|
is.mark(512);
|
||||||
|
|
||||||
return queryTripsMobile(uri.toString(), null, null, null, is);
|
return queryTripsMobile(uri.toString(), null, null, null, is);
|
||||||
}
|
}
|
||||||
catch (final XmlPullParserException x)
|
catch (final XmlPullParserException x)
|
||||||
{
|
{
|
||||||
throw new ParserException(x);
|
throw new ParserException("cannot parse xml: " + firstChars, x);
|
||||||
}
|
}
|
||||||
catch (final ProtocolException x) // must be html content
|
catch (final ProtocolException x) // must be html content
|
||||||
{
|
{
|
||||||
|
|
|
@ -65,6 +65,7 @@ import de.schildbach.pte.dto.ResultHeader;
|
||||||
import de.schildbach.pte.dto.StationDepartures;
|
import de.schildbach.pte.dto.StationDepartures;
|
||||||
import de.schildbach.pte.dto.Stop;
|
import de.schildbach.pte.dto.Stop;
|
||||||
import de.schildbach.pte.dto.Trip;
|
import de.schildbach.pte.dto.Trip;
|
||||||
|
import de.schildbach.pte.exception.ParserException;
|
||||||
import de.schildbach.pte.exception.SessionExpiredException;
|
import de.schildbach.pte.exception.SessionExpiredException;
|
||||||
import de.schildbach.pte.util.LittleEndianDataInputStream;
|
import de.schildbach.pte.util.LittleEndianDataInputStream;
|
||||||
import de.schildbach.pte.util.ParserUtils;
|
import de.schildbach.pte.util.ParserUtils;
|
||||||
|
@ -1007,11 +1008,14 @@ public abstract class AbstractHafasProvider extends AbstractNetworkProvider
|
||||||
// ParserUtils.printXml(ParserUtils.scrape(queryEndpoint, request, null, null));
|
// ParserUtils.printXml(ParserUtils.scrape(queryEndpoint, request, null, null));
|
||||||
|
|
||||||
Reader reader = null;
|
Reader reader = null;
|
||||||
|
String firstChars = null;
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
final String endpoint = extXmlEndpoint != null ? extXmlEndpoint : queryEndpoint;
|
final String endpoint = extXmlEndpoint != null ? extXmlEndpoint : queryEndpoint;
|
||||||
reader = new InputStreamReader(ParserUtils.scrapeInputStream(endpoint, request, null, null, null, 3), ISO_8859_1);
|
final InputStream is = ParserUtils.scrapeInputStream(endpoint, request, null, null, null, 3);
|
||||||
|
firstChars = ParserUtils.peekFirstChars(is);
|
||||||
|
reader = new InputStreamReader(is, ISO_8859_1);
|
||||||
|
|
||||||
final XmlPullParserFactory factory = XmlPullParserFactory.newInstance(System.getProperty(XmlPullParserFactory.PROPERTY_NAME), null);
|
final XmlPullParserFactory factory = XmlPullParserFactory.newInstance(System.getProperty(XmlPullParserFactory.PROPERTY_NAME), null);
|
||||||
final XmlPullParser pp = factory.newPullParser();
|
final XmlPullParser pp = factory.newPullParser();
|
||||||
|
@ -1372,7 +1376,7 @@ public abstract class AbstractHafasProvider extends AbstractNetworkProvider
|
||||||
}
|
}
|
||||||
catch (final XmlPullParserException x)
|
catch (final XmlPullParserException x)
|
||||||
{
|
{
|
||||||
throw new RuntimeException(x);
|
throw new ParserException("cannot parse xml: " + firstChars, x);
|
||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue