當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。