mirror of
https://gitlab.com/oeffi/public-transport-enabler.git
synced 2025-07-18 00:09:55 +00:00
fixed request encoding when autocompleting hafas
This commit is contained in:
parent
15c7113ce8
commit
194c6295e4
11 changed files with 85 additions and 17 deletions
|
@ -1695,7 +1695,7 @@ public abstract class AbstractEfaProvider extends AbstractNetworkProvider
|
|||
InputStream is = null;
|
||||
try
|
||||
{
|
||||
is = ParserUtils.scrapeInputStream(uri, null, "NSC_", 3);
|
||||
is = ParserUtils.scrapeInputStream(uri, null, null, "NSC_", 3);
|
||||
return queryConnections(uri, is);
|
||||
}
|
||||
catch (final XmlPullParserException x)
|
||||
|
@ -1726,7 +1726,7 @@ public abstract class AbstractEfaProvider extends AbstractNetworkProvider
|
|||
InputStream is = null;
|
||||
try
|
||||
{
|
||||
is = new BufferedInputStream(ParserUtils.scrapeInputStream(uri.toString(), null, "NSC_", 3));
|
||||
is = new BufferedInputStream(ParserUtils.scrapeInputStream(uri.toString(), null, null, "NSC_", 3));
|
||||
is.mark(512);
|
||||
|
||||
return queryConnections(uri.toString(), is);
|
||||
|
|
|
@ -155,9 +155,9 @@ public abstract class AbstractHafasProvider extends AbstractNetworkProvider
|
|||
return new String[] { null, name };
|
||||
}
|
||||
|
||||
private final String wrap(final String request)
|
||||
private final String wrap(final String request, final Charset encoding)
|
||||
{
|
||||
return "<?xml version=\"1.0\" encoding=\"iso-8859-1\"?>" //
|
||||
return "<?xml version=\"1.0\" encoding=\"" + (encoding != null ? encoding.name() : "iso-8859-1") + "\"?>" //
|
||||
+ "<ReqC ver=\"1.1\" prod=\"" + PROD + "\" lang=\"DE\"" + (accessId != null ? " accessId=\"" + accessId + "\"" : "") + ">" //
|
||||
+ request //
|
||||
+ "</ReqC>";
|
||||
|
@ -246,7 +246,7 @@ public abstract class AbstractHafasProvider extends AbstractNetworkProvider
|
|||
|
||||
try
|
||||
{
|
||||
reader = new InputStreamReader(ParserUtils.scrapeInputStream(apiUri, wrap(request), null, 3), ISO_8859_1);
|
||||
reader = new InputStreamReader(ParserUtils.scrapeInputStream(apiUri, wrap(request, null), null, null, 3), ISO_8859_1);
|
||||
|
||||
final List<Location> results = new ArrayList<Location>();
|
||||
|
||||
|
@ -451,14 +451,15 @@ public abstract class AbstractHafasProvider extends AbstractNetworkProvider
|
|||
protected final List<Location> xmlMLcReq(final CharSequence constraint) throws IOException
|
||||
{
|
||||
final String request = "<MLcReq><MLc n=\"" + constraint + "?\" t=\"ALLTYPE\" /></MLcReq>";
|
||||
final String wrappedRequest = wrap(request, xmlMlcResEncoding);
|
||||
|
||||
// ParserUtils.printXml(ParserUtils.scrape(apiUri, true, wrap(request), mlcResEncoding, false));
|
||||
// ParserUtils.printXml(ParserUtils.scrape(apiUri, true, wrappedRequest, xmlMlcResEncoding, null));
|
||||
|
||||
Reader reader = null;
|
||||
|
||||
try
|
||||
{
|
||||
reader = new InputStreamReader(ParserUtils.scrapeInputStream(apiUri, wrap(request), null, 3), xmlMlcResEncoding);
|
||||
reader = new InputStreamReader(ParserUtils.scrapeInputStream(apiUri, wrappedRequest, xmlMlcResEncoding, null, 3), xmlMlcResEncoding);
|
||||
|
||||
final XmlPullParserFactory factory = XmlPullParserFactory.newInstance(System.getProperty(XmlPullParserFactory.PROPERTY_NAME), null);
|
||||
final XmlPullParser pp = factory.newPullParser();
|
||||
|
@ -838,7 +839,7 @@ public abstract class AbstractHafasProvider extends AbstractNetworkProvider
|
|||
|
||||
try
|
||||
{
|
||||
reader = new InputStreamReader(ParserUtils.scrapeInputStream(apiUri, wrap(request), null, 3), ISO_8859_1);
|
||||
reader = new InputStreamReader(ParserUtils.scrapeInputStream(apiUri, wrap(request, null), null, null, 3), ISO_8859_1);
|
||||
|
||||
final XmlPullParserFactory factory = XmlPullParserFactory.newInstance(System.getProperty(XmlPullParserFactory.PROPERTY_NAME), null);
|
||||
final XmlPullParser pp = factory.newPullParser();
|
||||
|
|
|
@ -195,12 +195,15 @@ public final class ParserUtils
|
|||
|
||||
public static final InputStream scrapeInputStream(final String url) throws IOException
|
||||
{
|
||||
return scrapeInputStream(url, null, null, 3);
|
||||
return scrapeInputStream(url, null, null, null, 3);
|
||||
}
|
||||
|
||||
public static final InputStream scrapeInputStream(final String urlStr, final String postRequest, final String sessionCookieName, int tries)
|
||||
throws IOException
|
||||
public static final InputStream scrapeInputStream(final String urlStr, final String postRequest, Charset requestEncoding,
|
||||
final String sessionCookieName, int tries) throws IOException
|
||||
{
|
||||
if (requestEncoding == null)
|
||||
requestEncoding = SCRAPE_DEFAULT_ENCODING;
|
||||
|
||||
while (true)
|
||||
{
|
||||
final URL url = new URL(urlStr);
|
||||
|
@ -224,7 +227,7 @@ public final class ParserUtils
|
|||
connection.addRequestProperty("Content-Type", "application/x-www-form-urlencoded");
|
||||
connection.addRequestProperty("Content-Length", Integer.toString(postRequest.length()));
|
||||
|
||||
final Writer writer = new OutputStreamWriter(connection.getOutputStream(), SCRAPE_DEFAULT_ENCODING);
|
||||
final Writer writer = new OutputStreamWriter(connection.getOutputStream(), requestEncoding);
|
||||
writer.write(postRequest);
|
||||
writer.close();
|
||||
}
|
||||
|
|
|
@ -66,7 +66,7 @@ public class EireannProviderLiveTest extends AbstractProviderLiveTest
|
|||
}
|
||||
|
||||
@Test
|
||||
public void autoComplete() throws Exception
|
||||
public void autocomplete() throws Exception
|
||||
{
|
||||
final List<Location> autocompletes = provider.autocompleteStations("Dublin");
|
||||
|
||||
|
@ -74,7 +74,15 @@ public class EireannProviderLiveTest extends AbstractProviderLiveTest
|
|||
}
|
||||
|
||||
@Test
|
||||
public void autoCompleteAddress() throws Exception
|
||||
public void autocompleteUmlaut() throws Exception
|
||||
{
|
||||
final List<Location> autocompletes = provider.autocompleteStations("Busáras");
|
||||
|
||||
print(autocompletes);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void autocompleteAddress() throws Exception
|
||||
{
|
||||
final List<Location> autocompletes = provider.autocompleteStations("Dorfstrasse 10, Dällikon, Schweiz");
|
||||
|
||||
|
|
|
@ -65,6 +65,14 @@ public class NasaProviderLiveTest extends AbstractProviderLiveTest
|
|||
print(autocompletes);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void autocompleteUmlaut() throws Exception
|
||||
{
|
||||
final List<Location> autocompletes = provider.autocompleteStations("Höhle");
|
||||
|
||||
print(autocompletes);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shortConnection() throws Exception
|
||||
{
|
||||
|
|
|
@ -73,7 +73,7 @@ public class OebbProviderLiveTest extends AbstractProviderLiveTest
|
|||
}
|
||||
|
||||
@Test
|
||||
public void autoComplete() throws Exception
|
||||
public void autocomplete() throws Exception
|
||||
{
|
||||
final List<Location> autocompletes = provider.autocompleteStations("Wien");
|
||||
|
||||
|
@ -81,6 +81,14 @@ public class OebbProviderLiveTest extends AbstractProviderLiveTest
|
|||
assertTrue(autocompletes.size() > 0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void autocompleteUmlaut() throws Exception
|
||||
{
|
||||
final List<Location> autocompletes = provider.autocompleteStations("Obirhöhle");
|
||||
|
||||
print(autocompletes);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shortConnection() throws Exception
|
||||
{
|
||||
|
|
|
@ -73,6 +73,14 @@ public class PlProviderLiveTest extends AbstractProviderLiveTest
|
|||
print(autocompletes);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void autocompleteUmlaut() throws Exception
|
||||
{
|
||||
final List<Location> autocompletes = provider.autocompleteStations("Służewiec");
|
||||
|
||||
print(autocompletes);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shortConnection() throws Exception
|
||||
{
|
||||
|
|
|
@ -73,6 +73,14 @@ public class RmvProviderLiveTest extends AbstractProviderLiveTest
|
|||
print(autocompletes);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void autocompleteUmlaut() throws Exception
|
||||
{
|
||||
final List<Location> autocompletes = provider.autocompleteStations("Wächtersbach");
|
||||
|
||||
print(autocompletes);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shortConnection() throws Exception
|
||||
{
|
||||
|
|
|
@ -66,7 +66,7 @@ public class SbbProviderLiveTest extends AbstractProviderLiveTest
|
|||
}
|
||||
|
||||
@Test
|
||||
public void autoComplete() throws Exception
|
||||
public void autocomplete() throws Exception
|
||||
{
|
||||
final List<Location> autocompletes = provider.autocompleteStations("haupt");
|
||||
|
||||
|
@ -74,7 +74,15 @@ public class SbbProviderLiveTest extends AbstractProviderLiveTest
|
|||
}
|
||||
|
||||
@Test
|
||||
public void autoCompleteAddress() throws Exception
|
||||
public void autocompleteUmlaut() throws Exception
|
||||
{
|
||||
final List<Location> autocompletes = provider.autocompleteStations("Höhle");
|
||||
|
||||
print(autocompletes);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void autocompleteAddress() throws Exception
|
||||
{
|
||||
final List<Location> autocompletes = provider.autocompleteStations("Dorfstrasse 10, Dällikon, Schweiz");
|
||||
|
||||
|
|
|
@ -73,6 +73,14 @@ public class ShProviderLiveTest extends AbstractProviderLiveTest
|
|||
print(autocompletes);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void autocompleteUmlaut() throws Exception
|
||||
{
|
||||
final List<Location> autocompletes = provider.autocompleteStations("Achterüm");
|
||||
|
||||
print(autocompletes);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shortConnection() throws Exception
|
||||
{
|
||||
|
|
|
@ -65,6 +65,14 @@ public class VbbProviderLiveTest extends AbstractProviderLiveTest
|
|||
print(result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void autocompleteUmlaut() throws Exception
|
||||
{
|
||||
final List<Location> autocompletes = provider.autocompleteStations("Hedwigshöhe");
|
||||
|
||||
print(autocompletes);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void autocompleteIncomplete() throws Exception
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue