当前位置: 首页>>代码示例>>Java>>正文


Java HttpStatusException类代码示例

本文整理汇总了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();
}
 
开发者ID:ViniciusArnhold,项目名称:ProjectAltaria,代码行数:24,代码来源:EventUtils.java

示例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!");
    }
}
 
开发者ID:emiliodallatorre,项目名称:Linda-AI,代码行数:20,代码来源:Act.java

示例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());
		}
	}
}
 
开发者ID:mpcontracting,项目名称:rpmjukebox,代码行数:21,代码来源:BandListPage.java

示例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());
		}
	}
}
 
开发者ID:mpcontracting,项目名称:rpmjukebox,代码行数:21,代码来源:IndexPage.java

示例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);

}
 
开发者ID:Kaysoro,项目名称:KaellyBot,代码行数:22,代码来源:ExceptionManager.java

示例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;
	}
 
开发者ID:charcode,项目名称:StockScreener,代码行数:26,代码来源:EarningsCalendarYahooWebDao.java

示例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&region=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;
}
 
开发者ID:charcode,项目名称:StockScreener,代码行数:32,代码来源:YahooJsonFinancialDataDao.java

示例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
        }
    }
 
开发者ID:digitalheir,项目名称:java-rechtspraak-library,代码行数:27,代码来源:SearchRequest.java

示例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;
}
 
开发者ID:MKLab-ITI,项目名称:easIE,代码行数:20,代码来源:SingleDynamicPageExtractor.java

示例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;
}
 
开发者ID:MKLab-ITI,项目名称:easIE,代码行数:21,代码来源:SingleStaticPageExtractor.java

示例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);
    }
}
 
开发者ID:jherwitz,项目名称:curiosity-maps,代码行数:20,代码来源:WebCrawler.java

示例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);
    }
}
 
开发者ID:marunjar,项目名称:anewjkuapp,代码行数:24,代码来源:Analytics.java

示例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);
}
 
开发者ID:bl4ckscor3,项目名称:bl4ckb0t,代码行数:22,代码来源:Twitch.java

示例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);
}
 
开发者ID:bl4ckscor3,项目名称:bl4ckb0t,代码行数:22,代码来源:YouTube.java

示例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);
}
 
开发者ID:bl4ckscor3,项目名称:bl4ckb0t,代码行数:22,代码来源:Twitter.java


注:本文中的org.jsoup.HttpStatusException类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。