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


Java HttpStatusException.getStatusCode方法代码示例

本文整理汇总了Java中org.jsoup.HttpStatusException.getStatusCode方法的典型用法代码示例。如果您正苦于以下问题:Java HttpStatusException.getStatusCode方法的具体用法?Java HttpStatusException.getStatusCode怎么用?Java HttpStatusException.getStatusCode使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.jsoup.HttpStatusException的用法示例。


在下文中一共展示了HttpStatusException.getStatusCode方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: 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

示例3: 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

示例4: 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

示例5: 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

示例6: 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

示例7: onCommand

import org.jsoup.HttpStatusException; //导入方法依赖的package包/类
@Override
public void onCommand(String command, User user, PircBotX network, String prefix, Channel channel, boolean isPrivate, int userPermLevel, String... args) throws Exception {
    if(command.equalsIgnoreCase("showerthought")){
        args = new String[1];
        args[0] = "showerthoughts";
    }
    try {
        JsonArray results = GeneralUtils.getJsonObject("https://api.reddit.com/r/" + args[0] + "/?limit=25").get("data").getAsJsonObject().get("children").getAsJsonArray();
        if (results.size() < 1) {
            IRCUtils.sendError(user, network, channel, "Search returned no results", prefix);
        } else {
            JsonObject result = results.get(new Random().nextInt(results.size() - 1)).getAsJsonObject().get("data").getAsJsonObject();
            IRCUtils.sendMessage(user, network, channel, result.get("title").getAsString() + " - by " + IRCUtils.noPing(result.get("author").getAsString()) + " - " + GeneralUtils.shortenURL(result.get("url").getAsString()), prefix);
        }
    }catch(HttpStatusException e){
        if(e.getStatusCode() == 403){
            IRCUtils.sendError(user,network,channel, "Private Subreddit!", prefix);
        }
    }

}
 
开发者ID:TechCavern,项目名称:WaveTact,代码行数:22,代码来源:Reddit.java

示例8: onCommand

import org.jsoup.HttpStatusException; //导入方法依赖的package包/类
@Override
public void onCommand(String command, User user, PircBotX network, String prefix, Channel channel, boolean isPrivate, int userPermLevel, String... args) throws Exception {
    if (!args[0].startsWith(".")) {
        args[0] = "." + args[0];
    }
    try {
        Document doc = Jsoup.connect("http://www.iana.org/domains/root/db/" + args[0]).userAgent(Registry.USER_AGENT).get();
        Elements titles = doc.select("#main_right").select("h2");
        Elements names = doc.select("#main_right").select("b");
        String[] organization = doc.select("#main_right").after("br").html().split("\n");
        Set<String> results = new HashSet<>();
        results.add("Sponsoring Organization: "+ names.get(0).text());
        results.add("Administrative Contact: " + names.get(1).text()  + ", " +  GeneralUtils.stripHTML(organization[10]));
        results.add("Technical Contact: " + names.get(5).text() + ", " + GeneralUtils.stripHTML(organization[23]));
        IRCUtils.sendMessage(user, network, channel, StringUtils.join(results, " - "), prefix);
    }catch(HttpStatusException e){
        if(e.getStatusCode() == 404){
            IRCUtils.sendError(user, network, channel, "Invalid TLD", prefix);
        }else{
            IRCUtils.sendError(user, network, channel, "Failed to execute command, please make sure you are using the correct syntax (" + getSyntax() + ")", prefix);

        }
    }

}
 
开发者ID:TechCavern,项目名称:WaveTact,代码行数:26,代码来源:TLDInfo.java

示例9: performAction

import org.jsoup.HttpStatusException; //导入方法依赖的package包/类
@Override
public void performAction() throws IOException {
    try {
        document = Jsoup.connect(uRLString).get();
    } catch (HttpStatusException e) {
        e.printStackTrace();
        if (e.getStatusCode() == 404) {
            document = null;
        } else {
            throw e;
        }
    }
}
 
开发者ID:thangbn,项目名称:Direct-File-Downloader,代码行数:14,代码来源:SearchController.java

示例10: getContent

import org.jsoup.HttpStatusException; //导入方法依赖的package包/类
public static String getContent(String url) {
    LOGGER.debug("url:" + url);
    Connection conn = Jsoup.connect(url)
            .header("Accept", ACCEPT)
            .header("Accept-Encoding", ENCODING)
            .header("Accept-Language", LANGUAGE)
            .header("Connection", CONNECTION)
            .header("Referer", REFERER)
            .header("Host", HOST)
            .header("User-Agent", USER_AGENTS.get(uac.incrementAndGet() % USER_AGENTS.size()))
            .header("X-Forwarded-For", getRandomIp())
            .header("Proxy-Client-IP", getRandomIp())
            .header("WL-Proxy-Client-IP", getRandomIp())
            .ignoreContentType(true);
    String html = "";
    try {
        html = conn.post().html();
    }catch (Exception e){
        if(e instanceof  HttpStatusException) {
            HttpStatusException ex = (HttpStatusException) e;
            LOGGER.error("error code:"+ex.getStatusCode());
            if(ex.getStatusCode()==404){
                return "404";
            }
        }
        LOGGER.error("获取URL:"+url+" 页面出错", e);
    }
    return html;
}
 
开发者ID:ysc,项目名称:superword,代码行数:30,代码来源:ChineseSynonymAntonymExtractor.java

示例11: processResearcher

import org.jsoup.HttpStatusException; //导入方法依赖的package包/类
public OutputType processResearcher() throws Exception {
	if (allowSkip() && workVerifiedDT != null && workVerifiedDT.getTimeInMillis() > new DateTime().minusDays(daysConsideredOld).getMillis()) {
		return OutputType.SKIPPED;
	}
	else {
		Researcher researcher = createResearcher();
		researcher.setAffiliation(affiliation);

		try {
			reader.getPageItems(researcher);
		}
		catch (HttpStatusException e) {
			if (404 == e.getStatusCode()) {
				message = e.toString();
				deleteResearcher();
				return OutputType.DELETED;
			}
			else {
				throw e;
			}
		}

		List<String> preStatements = new ArrayList<String>();
		preStatements.add(String.format(DELETE_RESEARCHER_THUMBNAIL, getResearcherURI()));
		if (generateThumbnail(researcher)) {
			// just drop the triple, not the image or thumbnail
			preStatements.addAll(Arrays.asList(String.format(REMOVE_EXISTING_IMAGES, getResearcherURI()), 
				String.format(ADD_THUMBNAIL, getResearcherURI(), researcher.getThumbnailURL())));
		}
		
		store.startTransaction();
		store.execute(preStatements);
		store.execute(String.format(DELETE_PRIOR_PROCESS_LOG, getResearcherURI(), getCrawler().getURI()));
		store.update(researcher);
		store.endTransaction();
		
		return OutputType.PROCESSED;
	}
}
 
开发者ID:CTSIatUCSF,项目名称:Crosslinks,代码行数:40,代码来源:PageItemProcessor.java

示例12: parseUrl

import org.jsoup.HttpStatusException; //导入方法依赖的package包/类
@Override
protected UpdaterStatus parseUrl(
	String url
) {
	try {
		Document doc = Jsoup.connect(url).get();

		for (int i = 0; i < 20; i++) {
			// Get the url for the first app returned
			Elements elements =  doc.getElementsByClass("cardlink_1_" + i);
			if (elements.size() < 1) {
				return UpdaterStatus.STATUS_UPDATE_NOT_FOUND;
			}
			String app_url = elements.get(0).attr("href");

			// Get package name from app url
			Document doc2 = Jsoup.connect(app_url).get();
			elements = doc2.getElementsByClass("packagename");
			if (elements.size() < 1) {
				return UpdaterStatus.STATUS_UPDATE_NOT_FOUND;
			}
			String pname = elements.get(0).getElementsByClass("right").get(0).html();

			// Check if it's the same app
			if (!pname.equals(mPname)) {
				continue;
			}

			// Get version
			String version = doc2.getElementsByAttributeValue("itemprop", "softwareVersion").get(0).html();

			// Compare versions
			if (compareVersions(mCurrentVersion, version) == -1) {
				mResultUrl = app_url;
				mResultVersion = version;
				return UpdaterStatus.STATUS_UPDATE_FOUND;
			}
		}

		return UpdaterStatus.STATUS_UPDATE_NOT_FOUND;
	} catch (HttpStatusException status) {
		if (status.getStatusCode() == 404 || status.getStatusCode() == 403) {
			return UpdaterStatus.STATUS_UPDATE_NOT_FOUND;
		} else {
			mError = addCommonInfoToError(status);
			return UpdaterStatus.STATUS_ERROR;
		}
	} catch (Exception e) {
		mError = addCommonInfoToError(e);
		return UpdaterStatus.STATUS_ERROR;
	}
}
 
开发者ID:rumboalla,项目名称:apkupdater,代码行数:53,代码来源:UpdaterUptodown.java


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