mirror of
https://gitlab.com/oeffi/public-transport-enabler.git
synced 2025-07-13 16:20:34 +00:00
Check for internal errors advertised as HTTP status OK.
This commit is contained in:
parent
ca3fb061a6
commit
11a8d9f8fe
2 changed files with 22 additions and 0 deletions
|
@ -170,6 +170,9 @@ public final class ParserUtils
|
|||
if (testExpired(firstChars))
|
||||
throw new SessionExpiredException();
|
||||
|
||||
if (testInternalError(firstChars))
|
||||
throw new InternalErrorException(url, new InputStreamReader(is, requestEncoding));
|
||||
|
||||
if (sessionCookieName != null)
|
||||
{
|
||||
for (final Map.Entry<String, List<String>> entry : connection.getHeaderFields().entrySet())
|
||||
|
@ -299,6 +302,18 @@ public final class ParserUtils
|
|||
return false;
|
||||
}
|
||||
|
||||
private static final Pattern P_INTERNAL_ERROR = Pattern.compile(">\\s*(Internal error in gateway)\\s*<");
|
||||
|
||||
public static boolean testInternalError(final String content)
|
||||
{
|
||||
// check for internal error
|
||||
final Matcher m = P_INTERNAL_ERROR.matcher(content);
|
||||
if (m.find())
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private static final Pattern P_HTML_UNORDERED_LIST = Pattern.compile("<ul>(.*?)</ul>", Pattern.DOTALL | Pattern.CASE_INSENSITIVE);
|
||||
private static final Pattern P_HTML_LIST_ITEM = Pattern.compile("<li>(.*?)</li>", Pattern.DOTALL | Pattern.CASE_INSENSITIVE);
|
||||
private static final Pattern P_HTML_BREAKS = Pattern.compile("(<br\\s*/>)+", Pattern.DOTALL | Pattern.CASE_INSENSITIVE);
|
||||
|
|
|
@ -99,4 +99,11 @@ public class ParserUtilsTest
|
|||
{
|
||||
assertTrue(ParserUtils.testExpired("<h2>Ihre Verbindungskennung ist nicht mehr gültig.</h2>"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void internalError() throws Exception
|
||||
{
|
||||
assertTrue(ParserUtils
|
||||
.testInternalError("<?xml version=\"1.0\"?> <!DOCTYPE html PUBLIC \"-//WAPFORUM//DTD XHTML Mobile 1.0//EN\" \"http://www.wapforum.org/DTD/xhtml-mobile10.dtd\"> <html xmlns=\"http://www.w3.org/1999/xhtml\"> <head> <title> Internal error in gateway </title> </head> <body> <h1> Internal error in gateway </h1> </body> </html>"));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue