コード例 #1
0
 /**
  *  Copies the file from temp dir to the news location,
  *  calls checkForUpdates()
  */
 @Override
 public void transferComplete(long alreadyTransferred, long bytesTransferred, long bytesRemaining, String url, String outputFile, boolean notModified) {
     if (_log.shouldLog(Log.INFO))
         _log.info("News fetched from " + url + " with " + (alreadyTransferred+bytesTransferred));
     
     long now = _context.clock().now();
     if (_tempFile.exists()) {
         boolean copied = FileUtil.copy(_tempFile, _newsFile, true, false);
         _tempFile.delete();
         if (copied) {
             String newVer = Long.toString(now);
             _context.router().saveConfig(NewsHelper.PROP_LAST_UPDATED, newVer);
             _mgr.notifyVersionAvailable(this, _currentURI, NEWS, "", HTTP,
                                         null, newVer, "");
             _isNewer = true;
             checkForUpdates();
         } else {
             if (_log.shouldLog(Log.ERROR))
                 _log.error("Failed to copy the news file!");
         }
     } else {
         if (_log.shouldLog(Log.WARN))
             _log.warn("Transfer complete, but no file? - probably 304 Not Modified");
     }
     _success = true;
 }
コード例 #2
0
  /**
   * HEAD the update url, and if the last-mod time is newer than the last update we downloaded, as
   * stored in the properties, then we download it using eepget.
   */
  private boolean fetchUnsignedHead() {
    if (_urls.isEmpty()) return false;
    _currentURI = _urls.get(0);
    String url = _currentURI.toString();
    // assume always proxied for now
    // boolean shouldProxy =
    // Boolean.valueOf(_context.getProperty(ConfigUpdateHandler.PROP_SHOULD_PROXY,
    // ConfigUpdateHandler.DEFAULT_SHOULD_PROXY)).booleanValue();
    String proxyHost =
        _context.getProperty(
            ConfigUpdateHandler.PROP_PROXY_HOST, ConfigUpdateHandler.DEFAULT_PROXY_HOST);
    int proxyPort =
        _context.getProperty(
            ConfigUpdateHandler.PROP_PROXY_PORT, ConfigUpdateHandler.DEFAULT_PROXY_PORT_INT);

    try {
      EepHead get = new EepHead(_context, proxyHost, proxyPort, 0, url);
      if (get.fetch()) {
        String lastmod = get.getLastModified();
        if (lastmod != null) {
          long modtime = RFC822Date.parse822Date(lastmod);
          if (modtime <= 0) return false;
          if (_ms <= 0) return false;
          if (modtime > _ms) {
            _unsignedUpdateAvailable = true;
            _mgr.notifyVersionAvailable(
                this, _urls.get(0), getType(), "", getMethod(), _urls, Long.toString(modtime), "");
          }
        }
        return true;
      }
    } catch (Throwable t) {
      _log.error("Error fetching the unsigned update", t);
    }
    return false;
  }
コード例 #3
0
    public void fetchNews() {
        boolean shouldProxy = _context.getProperty(ConfigUpdateHandler.PROP_SHOULD_PROXY_NEWS, ConfigUpdateHandler.DEFAULT_SHOULD_PROXY_NEWS);
        String proxyHost = _context.getProperty(ConfigUpdateHandler.PROP_PROXY_HOST, ConfigUpdateHandler.DEFAULT_PROXY_HOST);
        int proxyPort = ConfigUpdateHandler.proxyPort(_context);

        for (URI uri : _urls) {
             _currentURI = uri;
             String newsURL = uri.toString();

            if (_tempFile.exists())
                _tempFile.delete();
        
            try {
                EepGet get;
                if (shouldProxy)
                    get = new EepGet(_context, true, proxyHost, proxyPort, 0, _tempFile.getAbsolutePath(), newsURL, true, null, _lastModified);
                else if ("https".equals(uri.getScheme()))
                    // no constructor w/ last mod check
                    get = new SSLEepGet(_context, _tempFile.getAbsolutePath(), newsURL);
                else
                    get = new EepGet(_context, false, null, 0, 0, _tempFile.getAbsolutePath(), newsURL, true, null, _lastModified);
                get.addStatusListener(this);
                long start = _context.clock().now();
                if (get.fetch()) {
                    int status = get.getStatusCode();
                    if (status == 200 || status == 304) {
                        _context.router().saveConfig(NewsHelper.PROP_LAST_CHECKED,
                                                 Long.toString(start));
                        return;
                    }
                }
            } catch (Throwable t) {
                _log.error("Error fetching the news", t);
            }
        }
    }