mirror of
https://gitlab.com/oeffi/public-transport-enabler.git
synced 2025-07-14 08:40:29 +00:00
exception for blocked requests
This commit is contained in:
parent
d7beafd50e
commit
0e7be5280f
2 changed files with 55 additions and 0 deletions
|
@ -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 <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package de.schildbach.pte.exception;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.net.URL;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Andreas Schildbach
|
||||||
|
*/
|
||||||
|
public class BlockedException extends IOException
|
||||||
|
{
|
||||||
|
private final URL url;
|
||||||
|
|
||||||
|
public BlockedException()
|
||||||
|
{
|
||||||
|
this.url = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public BlockedException(final URL url)
|
||||||
|
{
|
||||||
|
super(url.toString());
|
||||||
|
|
||||||
|
this.url = url;
|
||||||
|
}
|
||||||
|
|
||||||
|
public URL getUrl()
|
||||||
|
{
|
||||||
|
return url;
|
||||||
|
}
|
||||||
|
}
|
|
@ -39,6 +39,7 @@ import java.util.regex.Matcher;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
import java.util.zip.GZIPInputStream;
|
import java.util.zip.GZIPInputStream;
|
||||||
|
|
||||||
|
import de.schildbach.pte.exception.BlockedException;
|
||||||
import de.schildbach.pte.exception.UnexpectedRedirectException;
|
import de.schildbach.pte.exception.UnexpectedRedirectException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -191,6 +192,10 @@ public final class ParserUtils
|
||||||
throw new IOException(message + ": " + url);
|
throw new IOException(message + ": " + url);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else if (responseCode == HttpURLConnection.HTTP_FORBIDDEN || responseCode == HttpURLConnection.HTTP_BAD_REQUEST)
|
||||||
|
{
|
||||||
|
throw new BlockedException(url);
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
final String message = "got response: " + responseCode + " " + connection.getResponseMessage();
|
final String message = "got response: " + responseCode + " " + connection.getResponseMessage();
|
||||||
|
@ -336,6 +341,10 @@ public final class ParserUtils
|
||||||
return is;
|
return is;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else if (responseCode == HttpURLConnection.HTTP_FORBIDDEN || responseCode == HttpURLConnection.HTTP_BAD_REQUEST)
|
||||||
|
{
|
||||||
|
throw new BlockedException(url);
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
final String message = "got response: " + responseCode + " " + connection.getResponseMessage();
|
final String message = "got response: " + responseCode + " " + connection.getResponseMessage();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue