本文整理匯總了Java中org.jsoup.HttpStatusException類的典型用法代碼示例。如果您正苦於以下問題:Java HttpStatusException類的具體用法?Java HttpStatusException怎麽用?Java HttpStatusException使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
HttpStatusException類屬於org.jsoup包,在下文中一共展示了HttpStatusException類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: sendConnectionErrorMessage
import org.jsoup.HttpStatusException; //導入依賴的package包/類
public static void sendConnectionErrorMessage(IDiscordClient client, IChannel channel, String command, @Nullable String message, @NotNull HttpStatusException httpe) throws RateLimitException, DiscordException, MissingPermissionsException {
@NotNull String problem = message != null ? message + "\n" : "";
if (httpe.getStatusCode() == HttpStatus.SC_SERVICE_UNAVAILABLE) {
problem += "Service unavailable, please try again latter.";
} else if (httpe.getStatusCode() == HttpStatus.SC_FORBIDDEN) {
problem += "Acess dennied.";
} else if (httpe.getStatusCode() == HttpStatus.SC_NOT_FOUND) {
problem += "Not Found";
} else {
problem += httpe.getStatusCode() + SPACE + httpe.getMessage();
}
new MessageBuilder(client)
.appendContent("Error during HTTP Connection ", MessageBuilder.Styles.BOLD)
.appendContent("\n")
.appendContent(EventManager.MAIN_COMMAND_NAME, MessageBuilder.Styles.BOLD)
.appendContent(SPACE)
.appendContent(command, MessageBuilder.Styles.BOLD)
.appendContent("\n")
.appendContent(problem, MessageBuilder.Styles.BOLD)
.withChannel(channel)
.send();
}
示例2: Wikipedia
import org.jsoup.HttpStatusException; //導入依賴的package包/類
static void Wikipedia(String dico) {
Document significatowikipedia = null;
String cercowikipedia = dico.substring((dico.indexOf("'")) + 1, (dico.lastIndexOf("'")));
try {
significatowikipedia = Jsoup.connect("https://it.wikipedia.org/wiki/" + cercowikipedia.replace(" ", "_")).userAgent("Mozilla").get();
String divs = significatowikipedia.select("p").text();
if (!divs.equals("")) {
new GUI().giveResponse("La ricerca di " + cercowikipedia + " su wikipedia ha restituito il seguente risultato:" + '\n' + divs);
} else {
new GUI().giveResponse("Mi dispiace, non ho trovato informazioni su " + cercowikipedia + " su Wikipedia...");
}
} catch (HttpStatusException e) {
new GUI().giveResponse("Mi dispiace, Wikipedia sembra non avere una voce per '" + cercowikipedia +"'...");
} catch (java.io.IOException f) {
f.printStackTrace();
} catch (StringIndexOutOfBoundsException g) {
new GUI().giveResponse("Ricorda che, perché io cerchi informazioni riguardo a qualcosa, occorre che tu la definisca fra due virgolette!");
}
}
示例3: parse
import org.jsoup.HttpStatusException; //導入依賴的package包/類
@Override
public void parse(String url, DataProcessor dataProcessor) throws Exception {
log.info("Parsing BandListPage - " + url);
try {
Document document = Jsoup.parse(new URL(url), TIMEOUT_MILLIS);
for (Element element : document.select("div#mainarea > a")) {
bandPage.parse(element.attr("href"), dataProcessor);
}
} catch (Exception e) {
if (e instanceof HttpStatusException) {
log.warn("Unable to fetch url - " + url + " - " + ((HttpStatusException)e).getStatusCode());
throw e;
} else {
log.warn("Unable to fetch url - " + url + " - " + e.getMessage());
}
}
}
示例4: parse
import org.jsoup.HttpStatusException; //導入依賴的package包/類
@Override
public void parse(String url, DataProcessor dataProcessor) throws Exception {
log.info("Parsing IndexPage - " + url);
try {
Document document = Jsoup.parse(new URL(url), TIMEOUT_MILLIS);
for (Element element : document.select("div#menu > a")) {
bandListPage.parse(url + "?letter=" + parseQueryString(element.attr("href"), "&").get("letter"), dataProcessor);
}
} catch (Exception e) {
if (e instanceof HttpStatusException) {
log.warn("Unable to fetch url - " + url + " - " + ((HttpStatusException)e).getStatusCode());
throw e;
} else {
log.warn("Unable to fetch url - " + url + " - " + e.getMessage());
}
}
}
示例5: manageSilentlyIOException
import org.jsoup.HttpStatusException; //導入依賴的package包/類
public static void manageSilentlyIOException(Exception e){
ClientConfig.setSentryContext(null, null, null, null);
// First we try parsing the exception message to see if it contains the response code
Matcher exMsgStatusCodeMatcher = Pattern.compile("^Server returned HTTP response code: (\\d+)")
.matcher(e.getMessage());
if(exMsgStatusCodeMatcher.find()) {
int statusCode = Integer.parseInt(exMsgStatusCodeMatcher.group(1));
if (statusCode >= 500 && statusCode < 600)
LOG.warn("manageSilentlyIOException", e);
else
LOG.error("manageSilentlyIOException", e);
} else if (e instanceof UnknownHostException
|| e instanceof SocketTimeoutException
|| e instanceof FileNotFoundException
|| e instanceof HttpStatusException
|| e instanceof NoRouteToHostException)
LOG.warn("manageSilentlyIOException", e);
else
LOG.error("manageSilentlyIOException", e);
}
示例6: parseYahoo
import org.jsoup.HttpStatusException; //導入依賴的package包/類
private List<EarningsCalendar> parseYahoo(String link, Date lastLoadedEarningsCalendarDate) {
List<EarningsCalendar> ret = new ArrayList<EarningsCalendar>();
Document document;
try {
document = downladPage(link);
ret = newParser(lastLoadedEarningsCalendarDate, document);
} catch (MalformedURLException e) {
log.error("Unexpected IO error while getting list of earnings calendars " + link, e);
} catch (IOException e1) {
if (e1 instanceof HttpStatusException) {
HttpStatusException se = (HttpStatusException) e1;
if (se.getStatusCode() == 404) {
throw new RuntimeException(se);
}
}
log.error("Unexpected IO error while getting list of earnings calendars " + link, e1);
} catch (Throwable t) {
log.error("Unexpected error while getting list of earnings calendars " + link, t);
}
return ret;
}
示例7: downloadFinancialData
import org.jsoup.HttpStatusException; //導入依賴的package包/類
/**
*
* @param url = https://query1.finance.yahoo.com/v10/finance/quoteSummary/IQE.L?formatted=true&crumb=lXTeLpxBk2G&lang=en-US®ion=US&modules=incomeStatementHistory%2CcashflowStatementHistory%2CbalanceSheetHistory%2CincomeStatementHistoryQuarterly%2CcashflowStatementHistoryQuarterly%2CbalanceSheetHistoryQuarterly%2Cearnings&corsDomain=finance.yahoo.com
* @returnurl = https://query1.finance.yahoo.com/v10/finance/quoteSummary/AAIF.L?formatted=true&modules=incomeStatementHistory%2CcashflowStatementHistory%2CbalanceSheetHistory%2CincomeStatementHistoryQuarterly%2CcashflowStatementHistoryQuarterly%2CbalanceSheetHistoryQuarterly%2Cearnings
* @throws IOException
* @throws JsonParseException
* @throws JsonMappingException
*/
private YahooFinancialJsonDataModel downloadFinancialData(String url,String ticker) throws IOException, JsonParseException, JsonMappingException {
String json = null;
YahooFinancialJsonDataModel financial = null;
try {
json = Jsoup.connect(url).header("Accept-Encoding", "gzip, deflate")
.userAgent("Mozilla/5.0 (Windows NT 6.1; WOW64; rv:23.0) Gecko/20100101 Firefox/23.0")
.maxBodySize(0).timeout(600000).ignoreContentType(true).execute().body();
} catch (HttpStatusException e) {
String message = "Cannot find data at: "+url;
log.error(message,e);
financial = YahooFinancialJsonDataModel.errorData(ticker, new Date(), message+" due to: "+e.getMessage());
}
if (json != null && financial == null) {
if (json.indexOf("preferred") > 0) {
System.out.println(json);
log.info("\n" + json);
}
ObjectMapper mapper = new ObjectMapper();
financial = mapper.readValue(json, YahooFinancialJsonDataModel.class);
}
return financial;
}
示例8: execute
import org.jsoup.HttpStatusException; //導入依賴的package包/類
public SearchResult execute() throws IOException, ParserConfigurationException, SAXException {
// System.out.println(getResponse().body().string().toString());
Response response = getResponse();
try {
if (response.code() == 200) {
//String str = response.body().string();
SAXParser saxParser = factory.newSAXParser();
ResultHandler handler = new ResultHandler();
try {
saxParser.parse(new InputSource(response.body().byteStream()), handler);
} catch (SAXException e) {
//System.err.println(str);
throw e;
}
return new SearchResult(this, handler.judgments);
} else {
throw new HttpStatusException("Code was not 200 but " + response.code(), response.code(), getRequest().url().toString());
}
} finally {
response.body().close(); // Make sure it's closed
}
}
示例9: call
import org.jsoup.HttpStatusException; //導入依賴的package包/類
@Override
public Object call() throws Exception {
try {
DynamicHTMLExtractor wrapper = new DynamicHTMLExtractor(page, ChromeDriverPath);
document = (Document) wrapper.browser_emulator.getHTMLDocument();
if (tableSelector != null && sfields != null && cfields != null) {
return wrapper.extractTable(tableSelector, cfields, sfields);
} else if (tableSelector != null && sfields != null) {
return wrapper.extractTable(tableSelector, sfields);
} else if (cfields != null && sfields != null) {
return wrapper.extractFields(cfields, sfields);
} else if (sfields != null) {
return wrapper.extractFields(sfields);
}
} catch (HttpStatusException ex) {
return null;
}
return null;
}
示例10: call
import org.jsoup.HttpStatusException; //導入依賴的package包/類
@Override
public Object call() throws URISyntaxException, IOException {
try {
StaticHTMLExtractor wrapper = new StaticHTMLExtractor(page);
document = (Document) wrapper.fetcher.getHTMLDocument();
if (tableSelector != null && sfields != null && cfields != null) {
return wrapper.extractTable(tableSelector, cfields, sfields);
} else if (tableSelector != null && sfields != null) {
return wrapper.extractTable(tableSelector, sfields);
} else if (cfields != null && sfields != null) {
return wrapper.extractFields(cfields, sfields);
} else if (sfields != null) {
return wrapper.extractFields(sfields);
}
} catch (HttpStatusException ex) {
System.out.println(ex.fillInStackTrace());
return null;
}
return null;
}
示例11: httpGet
import org.jsoup.HttpStatusException; //導入依賴的package包/類
protected Document httpGet(Connection conn) {
try {
// TODO: execute network request in a separate thread pool
return conn.get();
} catch (IOException e) {
if(e instanceof HttpStatusException) {
HttpStatusException statusException = (HttpStatusException) e;
// sleep for backoffTime if we're asked to slow down
if(statusException.getStatusCode() == 503) {
try {
Thread.sleep(backoffTime);
} catch (InterruptedException e1) {
throw new RuntimeException(e1);
}
}
}
throw new RuntimeException(e);
}
}
示例12: sendException
import org.jsoup.HttpStatusException; //導入依賴的package包/類
@SuppressLint("DefaultLocale")
public static void sendException(Context c, Exception e, boolean fatal, String additionalData) {
boolean send = true;
if (e instanceof java.net.UnknownHostException || e instanceof NoRouteToHostException) {
fatal = false;
} else if (e instanceof HttpStatusException) {
if (TextUtils.isEmpty(additionalData)) {
additionalData = String.format("%d: %s", ((HttpStatusException) e).getStatusCode(), ((HttpStatusException) e).getUrl());
}
send = (((HttpStatusException) e).getStatusCode() != 503);
} else if (e instanceof SSLException) {
if (!TextUtils.isEmpty(additionalData)) {
additionalData = additionalData + ", ";
} else {
additionalData = "";
}
additionalData = additionalData + getAnalytics().getPsStatus().toString();
}
if (send) {
getAnalytics().sendException(c, e, fatal, additionalData);
}
}
示例13: exe
import org.jsoup.HttpStatusException; //導入依賴的package包/類
@Override
public void exe(MessageEvent event, String cmdName, String[] args) throws Exception
{
String channel = event.getChannel().getName();
if(args.length == 1)
{
try
{
Jsoup.connect("http://www.twitch.tv/" + args[0]).get();
Utilities.sendMessage(channel, "http://www.twitch.tv/" + args[0]);
}
catch(HttpStatusException e)
{
if(e.getStatusCode() == 404)
Utilities.sendMessage(channel, l10n.translate("error", channel));
}
}
else
Utilities.sendHelp(module, event.getUser().getNick(), channel);
}
示例14: exe
import org.jsoup.HttpStatusException; //導入依賴的package包/類
@Override
public void exe(MessageEvent event, String cmdName, String[] args) throws Exception
{
String channel = event.getChannel().getName();
if(args.length == 1)
{
try
{
Jsoup.connect("http://www.youtube.com/" + args[0]).get();
Utilities.sendMessage(channel, "http://www.youtube.com/" + args[0]);
}
catch(HttpStatusException e)
{
if(e.getStatusCode() == 404)
Utilities.sendMessage(channel, l10n.translate("error", channel));
}
}
else
Utilities.sendHelp(module, event.getUser().getNick(), channel);
}
示例15: exe
import org.jsoup.HttpStatusException; //導入依賴的package包/類
@Override
public void exe(MessageEvent event, String cmdName, String[] args) throws Exception
{
String channel = event.getChannel().getName();
if(args.length == 1)
{
try
{
Jsoup.connect("http://www.twitter.com/" + args[0]).get();
Utilities.sendMessage(channel, "http://www.twitter.com/" + args[0]);
}
catch(HttpStatusException e)
{
if(e.getStatusCode() == 404)
Utilities.sendMessage(channel, l10n.translate("error", channel));
}
}
else
Utilities.sendHelp(module, event.getUser().getNick(), channel);
}