Package com.commafeed.backend.HttpGetter

Examples of com.commafeed.backend.HttpGetter.HttpResult


      return Response.status(Status.FORBIDDEN).build();
    }

    url = FeedUtils.imageProxyDecoder(url);
    try {
      HttpResult result = httpGetter.getBinary(url, 20000);
      return Response.ok(result.getContent()).build();
    } catch (Exception e) {
      return Response.status(Status.SERVICE_UNAVAILABLE).entity(e.getMessage()).build();
    }
  }
View Full Code Here


    String contentType = null;

    try {
      log.debug("Getting Facebook user's icon, {}", url);

      HttpResult iconResult = getter.getBinary(iconUrl, TIMEOUT);
      bytes = iconResult.getContent();
      contentType = iconResult.getContentType();
    } catch (Exception e) {
      log.debug("Failed to retrieve YouTube icon", e);
    }

    if (!isValidIconResponse(bytes, contentType)) {
View Full Code Here

    String contentType = null;

    try {
      url = FeedUtils.removeTrailingSlash(url) + "/favicon.ico";
      log.debug("getting root icon at {}", url);
      HttpResult result = getter.getBinary(url, TIMEOUT);
      bytes = result.getContent();
      contentType = result.getContentType();
    } catch (Exception e) {
      log.debug("Failed to retrieve iconAtRoot for url {}: ", url, e);
    }

    if (!isValidIconResponse(bytes, contentType)) {
View Full Code Here

  private byte[] getIconInPage(String url) {

    Document doc = null;
    try {
      HttpResult result = getter.getBinary(url, TIMEOUT);
      doc = Jsoup.parse(new String(result.getContent()), url);
    } catch (Exception e) {
      log.debug("Failed to retrieve page to find icon", e);
      return null;
    }

    Elements icons = doc.select("link[rel~=(?i)^(shortcut|icon|shortcut icon)$]");

    if (icons.isEmpty()) {
      log.debug("No icon found in page {}", url);
      return null;
    }

    String href = icons.get(0).attr("abs:href");
    if (StringUtils.isBlank(href)) {
      log.debug("No icon found in page");
      return null;
    }

    log.debug("Found unconfirmed iconInPage at {}", href);

    byte[] bytes = null;
    String contentType = null;
    try {
      HttpResult result = getter.getBinary(href, TIMEOUT);
      bytes = result.getContent();
      contentType = result.getContentType();
    } catch (Exception e) {
      log.debug("Failed to retrieve icon found in page {}", href, e);
      return null;
    }
View Full Code Here

    try {
      log.debug("Getting YouTube user's icon, {}", url);

      // initial get to translate username to obscure user thumbnail URL
      HttpResult profileResult = getter.getBinary(profileUrl, TIMEOUT);
      Document doc = Jsoup.parse(new String(profileResult.getContent()), profileUrl);

      Elements thumbnails = doc.select("media|thumbnail");
      if (thumbnails.isEmpty()) {
        return null;
      }
      String thumbnailUrl = thumbnails.get(0).attr("abs:url");

      // final get to actually retrieve the thumbnail
      HttpResult iconResult = getter.getBinary(thumbnailUrl, TIMEOUT);
      bytes = iconResult.getContent();
      contentType = iconResult.getContentType();
    } catch (Exception e) {
      log.debug("Failed to retrieve YouTube icon", e);
    }

    if (!isValidIconResponse(bytes, contentType)) {
View Full Code Here

    log.debug("Fetching feed {}", feedUrl);
    FetchedFeed fetchedFeed = null;

    int timeout = 20000;

    HttpResult result = getter.getBinary(feedUrl, lastModified, eTag, timeout);
    byte[] content = result.getContent();

    try {
      fetchedFeed = parser.parse(feedUrl, content);
    } catch (FeedException e) {
      if (extractFeedUrlFromHtml) {
        String extractedUrl = extractFeedUrl(StringUtils.newStringUtf8(result.getContent()), feedUrl);
        if (org.apache.commons.lang3.StringUtils.isNotBlank(extractedUrl)) {
          feedUrl = extractedUrl;

          result = getter.getBinary(extractedUrl, lastModified, eTag, timeout);
          content = result.getContent();
          fetchedFeed = parser.parse(feedUrl, content);
        } else {
          throw e;
        }
      } else {
        throw e;
      }
    }

    if (content == null) {
      throw new IOException("Feed content is empty.");
    }

    String hash = DigestUtils.sha1Hex(content);
    if (lastContentHash != null && hash != null && lastContentHash.equals(hash)) {
      log.debug("content hash not modified: {}", feedUrl);
      throw new NotModifiedException("content hash not modified");
    }

    if (lastPublishedDate != null && fetchedFeed.getFeed().getLastPublishedDate() != null
        && lastPublishedDate.getTime() == fetchedFeed.getFeed().getLastPublishedDate().getTime()) {
      log.debug("publishedDate not modified: {}", feedUrl);
      throw new NotModifiedException("publishedDate not modified");
    }

    Feed feed = fetchedFeed.getFeed();
    feed.setLastModifiedHeader(result.getLastModifiedSince());
    feed.setEtagHeader(FeedUtils.truncate(result.getETag(), 255));
    feed.setLastContentHash(hash);
    fetchedFeed.setFetchDuration(result.getDuration());
    fetchedFeed.setUrlAfterRedirect(result.getUrlAfterRedirect());
    return fetchedFeed;
  }
View Full Code Here

TOP

Related Classes of com.commafeed.backend.HttpGetter.HttpResult

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.