Example #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;
 }
Example #2
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);
            }
        }
    }