mirror of
https://gitlab.com/oeffi/public-transport-enabler.git
synced 2025-07-10 21:08:47 +00:00
name of session cookie is set by providers
git-svn-id: https://public-transport-enabler.googlecode.com/svn/trunk@669 0924bc21-9374-b0fa-ee44-9ff1593b38f0
This commit is contained in:
parent
179675506d
commit
cd138e00f4
4 changed files with 23 additions and 24 deletions
|
@ -1396,7 +1396,7 @@ public abstract class AbstractEfaProvider implements NetworkProvider
|
|||
InputStream is = null;
|
||||
try
|
||||
{
|
||||
is = ParserUtils.scrapeInputStream(uri, null, true, 3);
|
||||
is = ParserUtils.scrapeInputStream(uri, null, "HASESSIONID", 3);
|
||||
return queryConnections(uri, is);
|
||||
}
|
||||
catch (final XmlPullParserException x)
|
||||
|
@ -1415,7 +1415,7 @@ public abstract class AbstractEfaProvider implements NetworkProvider
|
|||
InputStream is = null;
|
||||
try
|
||||
{
|
||||
is = ParserUtils.scrapeInputStream(uri, null, true, 3);
|
||||
is = ParserUtils.scrapeInputStream(uri, null, "HASESSIONID", 3);
|
||||
return queryConnections(uri, is);
|
||||
}
|
||||
catch (final XmlPullParserException x)
|
||||
|
|
|
@ -204,7 +204,7 @@ public abstract class AbstractHafasProvider implements NetworkProvider
|
|||
InputStream is = null;
|
||||
try
|
||||
{
|
||||
is = ParserUtils.scrapeInputStream(apiUri, wrap(request), false, 3);
|
||||
is = ParserUtils.scrapeInputStream(apiUri, wrap(request), null, 3);
|
||||
|
||||
final List<Location> results = new ArrayList<Location>();
|
||||
|
||||
|
@ -256,7 +256,7 @@ public abstract class AbstractHafasProvider implements NetworkProvider
|
|||
|
||||
protected final List<Location> jsonGetStops(final String uri) throws IOException
|
||||
{
|
||||
final CharSequence page = ParserUtils.scrape(uri, false, null, jsonEncoding, false);
|
||||
final CharSequence page = ParserUtils.scrape(uri, false, null, jsonEncoding, null);
|
||||
|
||||
final Matcher mJson = P_AJAX_GET_STOPS_JSON.matcher(page);
|
||||
if (mJson.matches())
|
||||
|
@ -342,7 +342,7 @@ public abstract class AbstractHafasProvider implements NetworkProvider
|
|||
|
||||
try
|
||||
{
|
||||
is = ParserUtils.scrapeInputStream(apiUri, wrap(request), false, 3);
|
||||
is = ParserUtils.scrapeInputStream(apiUri, wrap(request), null, 3);
|
||||
|
||||
final XmlPullParserFactory factory = XmlPullParserFactory.newInstance(System.getProperty(XmlPullParserFactory.PROPERTY_NAME), null);
|
||||
final XmlPullParser pp = factory.newPullParser();
|
||||
|
@ -614,7 +614,7 @@ public abstract class AbstractHafasProvider implements NetworkProvider
|
|||
|
||||
try
|
||||
{
|
||||
is = ParserUtils.scrapeInputStream(apiUri, wrap(request), false, 3);
|
||||
is = ParserUtils.scrapeInputStream(apiUri, wrap(request), null, 3);
|
||||
|
||||
final XmlPullParserFactory factory = XmlPullParserFactory.newInstance(System.getProperty(XmlPullParserFactory.PROPERTY_NAME), null);
|
||||
final XmlPullParser pp = factory.newPullParser();
|
||||
|
@ -1080,7 +1080,7 @@ public abstract class AbstractHafasProvider implements NetworkProvider
|
|||
|
||||
protected final NearbyStationsResult jsonNearbyStations(final String uri) throws IOException
|
||||
{
|
||||
final CharSequence page = ParserUtils.scrape(uri, false, null, jsonEncoding, false);
|
||||
final CharSequence page = ParserUtils.scrape(uri, false, null, jsonEncoding, null);
|
||||
|
||||
final List<Location> stations = new ArrayList<Location>();
|
||||
|
||||
|
|
|
@ -230,7 +230,7 @@ public class OebbProvider extends AbstractHafasProvider
|
|||
final String products, final WalkSpeed walkSpeed) throws IOException
|
||||
{
|
||||
// get base url and cookies from form
|
||||
final CharSequence form = ParserUtils.scrape(QUERY_CONNECTIONS_FORM_URL, false, null, null, true);
|
||||
final CharSequence form = ParserUtils.scrape(QUERY_CONNECTIONS_FORM_URL, false, null, null, "NSC_");
|
||||
final Matcher m = P_QUERY_CONNECTIONS_FORM_ACTION.matcher(form);
|
||||
if (!m.find())
|
||||
throw new IllegalStateException("cannot find form: '" + form + "' on " + QUERY_CONNECTIONS_FORM_URL);
|
||||
|
@ -238,7 +238,7 @@ public class OebbProvider extends AbstractHafasProvider
|
|||
|
||||
// query
|
||||
final String query = connectionsQuery(from, via, to, date, dep, products, walkSpeed);
|
||||
final CharSequence page = ParserUtils.scrape(baseUri, true, query, null, true);
|
||||
final CharSequence page = ParserUtils.scrape(baseUri, true, query, null, "NSC_");
|
||||
|
||||
final Matcher mError = P_QUERY_CONNECTIONS_ERROR.matcher(page);
|
||||
if (mError.find())
|
||||
|
@ -289,7 +289,7 @@ public class OebbProvider extends AbstractHafasProvider
|
|||
@Override
|
||||
public QueryConnectionsResult queryMoreConnections(final String uri) throws IOException
|
||||
{
|
||||
final CharSequence page = ParserUtils.scrape(uri, false, null, null, true);
|
||||
final CharSequence page = ParserUtils.scrape(uri, false, null, null, "NSC_");
|
||||
|
||||
final Matcher mError = P_QUERY_CONNECTIONS_ERROR.matcher(page);
|
||||
if (mError.find())
|
||||
|
@ -352,7 +352,7 @@ public class OebbProvider extends AbstractHafasProvider
|
|||
if (!mAllDetailsAction.find())
|
||||
throw new IOException("cannot find all details link in '" + firstPage + "' on " + firstUri);
|
||||
final String allDetailsUri = mAllDetailsAction.group(1);
|
||||
final CharSequence page = ParserUtils.scrape(allDetailsUri, false, null, null, true);
|
||||
final CharSequence page = ParserUtils.scrape(allDetailsUri, false, null, null, "NSC_");
|
||||
|
||||
final Matcher mError = P_QUERY_CONNECTIONS_ERROR.matcher(page);
|
||||
if (mError.find())
|
||||
|
|
|
@ -60,17 +60,17 @@ public final class ParserUtils
|
|||
|
||||
public static final CharSequence scrape(final String url) throws IOException
|
||||
{
|
||||
return scrape(url, false, null, null, false);
|
||||
return scrape(url, false, null, null, null);
|
||||
}
|
||||
|
||||
public static final CharSequence scrape(final String url, final boolean isPost, final String request, String encoding,
|
||||
final boolean cookieHandling) throws IOException
|
||||
final String sessionCookieName) throws IOException
|
||||
{
|
||||
return scrape(url, isPost, request, encoding, cookieHandling, 3);
|
||||
return scrape(url, isPost, request, encoding, sessionCookieName, 3);
|
||||
}
|
||||
|
||||
public static final CharSequence scrape(final String url, final boolean isPost, final String request, String encoding,
|
||||
final boolean cookieHandling, int tries) throws IOException
|
||||
final String sessionCookieName, int tries) throws IOException
|
||||
{
|
||||
if (encoding == null)
|
||||
encoding = SCRAPE_DEFAULT_ENCODING;
|
||||
|
@ -91,7 +91,7 @@ public final class ParserUtils
|
|||
// workaround to disable Vodafone compression
|
||||
connection.addRequestProperty("Cache-Control", "no-cache");
|
||||
|
||||
if (cookieHandling && stateCookie != null)
|
||||
if (sessionCookieName != null && stateCookie != null)
|
||||
connection.addRequestProperty("Cookie", stateCookie);
|
||||
|
||||
if (request != null)
|
||||
|
@ -114,7 +114,7 @@ public final class ParserUtils
|
|||
|
||||
if (buffer.length() > SCRAPE_PAGE_EMPTY_THRESHOLD)
|
||||
{
|
||||
if (cookieHandling)
|
||||
if (sessionCookieName != null)
|
||||
{
|
||||
for (final Map.Entry<String, List<String>> entry : connection.getHeaderFields().entrySet())
|
||||
{
|
||||
|
@ -122,7 +122,7 @@ public final class ParserUtils
|
|||
{
|
||||
for (final String value : entry.getValue())
|
||||
{
|
||||
if (value.startsWith("NSC_") || value.startsWith("HASESSIONID"))
|
||||
if (value.startsWith(sessionCookieName))
|
||||
{
|
||||
stateCookie = value.split(";", 2)[0];
|
||||
}
|
||||
|
@ -167,10 +167,10 @@ public final class ParserUtils
|
|||
|
||||
public static final InputStream scrapeInputStream(final String url) throws IOException
|
||||
{
|
||||
return scrapeInputStream(url, null, false, 3);
|
||||
return scrapeInputStream(url, null, null, 3);
|
||||
}
|
||||
|
||||
public static final InputStream scrapeInputStream(final String url, final String postRequest, final boolean cookieHandling, int tries)
|
||||
public static final InputStream scrapeInputStream(final String url, final String postRequest, final String sessionCookieName, int tries)
|
||||
throws IOException
|
||||
{
|
||||
while (true)
|
||||
|
@ -186,7 +186,7 @@ public final class ParserUtils
|
|||
// workaround to disable Vodafone compression
|
||||
connection.addRequestProperty("Cache-Control", "no-cache");
|
||||
|
||||
if (cookieHandling && stateCookie != null)
|
||||
if (sessionCookieName != null && stateCookie != null)
|
||||
connection.addRequestProperty("Cookie", stateCookie);
|
||||
|
||||
if (postRequest != null)
|
||||
|
@ -206,7 +206,7 @@ public final class ParserUtils
|
|||
final String contentEncoding = connection.getContentEncoding();
|
||||
final InputStream is = connection.getInputStream();
|
||||
|
||||
if (cookieHandling)
|
||||
if (sessionCookieName != null)
|
||||
{
|
||||
for (final Map.Entry<String, List<String>> entry : connection.getHeaderFields().entrySet())
|
||||
{
|
||||
|
@ -214,10 +214,9 @@ public final class ParserUtils
|
|||
{
|
||||
for (final String value : entry.getValue())
|
||||
{
|
||||
if (value.startsWith("NSC_") || value.startsWith("HASESSIONID"))
|
||||
if (value.startsWith(sessionCookieName))
|
||||
{
|
||||
stateCookie = value.split(";", 2)[0];
|
||||
System.out.println(stateCookie);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue