Changeset 141

Show
Ignore:
Timestamp:
01/30/06 14:33:45 (4 years ago)
Author:
dsandler
Message:

New, more flexible publisher.conf format, based on JSON.

It's not quite JSON, though: the new JSONPropertyFile class parses strings
that look a whole lot like Java Properties files. The format is almost
JSONObject: the differences are that

  • the outermost curly braces have been removed, and
  • no delimiter is required between key=value clauses.

As for publisher.conf, the feed_urls key has been replaced by
feeds, to allow for future expansion. The argument is no longer a
space-separated list of URLs, but a JSONArray of URLs:

feeds = [

"http://foo.com/bar/",
"http://baz.com/wombat/"

]

This checkin includes the public source for json.org's Java implementation of
core JSON parsing.

See also:

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • feedtree/trunk/build.xml

    r87 r141  
    104104        </jar> 
    105105    </target> 
    106      
     106 
    107107    <!-- command-line proxy JAR file --> 
    108108    <target name="ftproxy.jar" depends="compile" 
     
    141141                <include name="net/feedtree/util/**/*.class"/> 
    142142                <include name="net/feedtree/publisher/*.class"/> 
     143                <include name="org/json/**/*.class"/> 
    143144            </fileset> 
    144145            <include name="build.properties"/> 
  • feedtree/trunk/publisher.conf

    r117 r141  
    22# default configuration file for the FeedTree publisher 
    33# http://feedtree.net/ 
     4# 
     5# File format (version 2): 
     6# key = 12345 
     7# key = "string" 
     8# key = [ "a", "list", "of", "things" ] 
    49 
    5 #### Feed information #### 
    610 
    7 # whitespace-separated list of URLs to be published 
    8 feed_urls = http://dsandler.org/wp/feed/atom/ 
     11###################################################################### 
     12## Feed information 
     13###################################################################### 
    914 
    10 # how often (in seconds) to reload each feed looking for new items (default: 120) 
     15# list of feed URLs to be fetched by the publisher & pushed to FeedTree 
     16feeds = [ 
     17    "http://dsandler.org/wp/feed/atom/" 
     18
     19 
     20# how often (in seconds) to reload each feed looking for new items (default = 120) 
    1121fetch_interval_sec = 120 
    1222 
    13 # how often a heartbeat should be sent in absence of new items (default: 600) 
     23# how often a heartbeat should be sent in absence of new items (default = 600) 
    1424heartbeat_interval_sec = 600 
    1525 
    1626# file to store cached feed data (previously-seen entries) in 
    17 feed_cache_file = publisher_feeds.cache 
     27feed_cache_file = "publisher_feeds.cache" 
    1828 
    1929#### Keystore information #### 
    2030 
    2131# path to a JKS or PKCS#12 keystore file 
    22 keystore          = demokey.jks 
     32keystore = "demokey.jks" 
    2333 
    2434# type of the keystore (e.g. JKS or PKCS12; default JKS) 
    25 keystore_type     = JKS 
     35keystore_type = "JKS" 
    2636 
    27 # password for the keystore (default: blank) 
    28 keystore_password = monkey 
     37# password for the keystore (default = blank) 
     38keystore_password = "monkey" 
    2939 
    30 # identifier of the key to be used for signing (default: "default") 
    31 key_name          = demokey 
     40# identifier of the key to be used for signing (default = "default") 
     41key_name = "demokey" 
    3242 
    33 # password to access <key_name> (default: blank) 
    34 key_password      = monkey 
     43# password to access <key_name> (default = blank) 
     44key_password = "monkey" 
    3545 
    36 #### Common FeedTree/Pastry network parameters #### 
     46 
     47###################################################################### 
     48## Common FeedTree/Pastry network parameters  
     49###################################################################### 
    3750 
    3851# port to run the FeedTree node on (default 29690; this is the port that  
    3952# must be forwarded to the Publisher host in a NAT situation) 
     53# note that this must be changed to something else (e.g, 29691) if 29690 is 
     54# occupied (i.e. by a FeedTree proxy running on the same host) 
    4055node_port = 29691 
    4156 
    42 # port for the Publisher web interface 
    43 web_port = 8502 
     57# port for the Publisher web interface (currently unused) 
     58web_port = 8502 
    4459 
    4560# TODO: add access control for the web interface to this file 
    4661 
    47 #### Less common FeedTree/Pastry network parameters #### 
     62 
     63###################################################################### 
     64## Less common FeedTree/Pastry network parameters 
     65###################################################################### 
    4866 
    4967# host to contact when starting (bootstrap.feedtree.net will boot you into  
    5068# the global FeedTree network) 
    51 bootstrap      = bootstrap.feedtree.net 
     69bootstrap = "bootstrap.feedtree.net" 
    5270 
    5371# port on the bootstrap to contact (29690 is the FeedTree default) 
  • feedtree/trunk/src/net/feedtree/publisher/Publisher.java

    r119 r141  
    5757import java.security.*; 
    5858 
     59import org.json.*; 
     60 
    5961public class Publisher 
    6062    extends Client 
     
    9799    public static final String PROP_WEB_PORT = "web_port"; 
    98100     
    99     /// Whitespace-separated list of URLs to publish (may be  
    100     /// <tt>file:///</tt> URLs) 
    101     public static final String PROP_FEED_URLS = "feed_urls"; 
    102      
     101    /// JSON list (i.e. enclosed in square-brackets) of feed URLs 
     102    /// Example: 
     103    /// feeds = [ 
     104    ///   "http://site.com/feed/atom/", 
     105    ///   "http://site.com/feed/rss2/" 
     106    /// ] 
     107    public static final String PROP_FEEDS = "feeds"; 
     108 
    103109    /// Filename of a local keystore (optional; required for signing entries) 
    104110    public static final String PROP_KEYSTORE = "keystore"; 
     
    124130    protected static ClassLoader g_classLoader; 
    125131    protected static Properties g_buildProperties; 
    126     protected static Properties g_config; 
     132    protected static JSONPropertyFile g_config; 
    127133 
    128134    protected PrivateKey m_key = null; 
     
    602608         
    603609        m_storage = Shelf.open( 
    604             g_config.getProperty(PROP_CACHE_FILE, "publisher_feeds.cache")); 
     610            g_config.optString(PROP_CACHE_FILE, "publisher_feeds.cache")); 
    605611        Integer storageVers = (Integer)m_storage.get("version"); 
    606612        if (storageVers == null || storageVers.intValue() < 1) { 
     
    647653        m_startDate = new Date(); 
    648654         
    649         m_checkInterval = new Long( 
    650             g_config.getProperty(PROP_FETCH_INTERVAL, "120")).longValue() * 1000L; 
    651         m_heartbeatInterval = new Long( 
    652             g_config.getProperty(PROP_HEARTBEAT_INTERVAL, "600")).longValue() * 1000L; 
     655        m_checkInterval =  
     656            g_config.optLong(PROP_FETCH_INTERVAL, 120L) * 1000L; 
     657        m_heartbeatInterval =  
     658            g_config.optLong(PROP_HEARTBEAT_INTERVAL, 600L) * 1000L; 
    653659 
    654660        Logger.global.info("### Scheduling first refresh task for "  
     
    671677    } 
    672678     
    673     protected static final int to_int(String s) { 
    674         return new Integer(s).intValue(); 
    675     } 
    676      
    677679    public static void main(String[] args) { 
    678680        // Disable use of graphics accelerator for Sparklines 
     
    690692        } 
    691693         
    692         g_config = new Properties(); 
    693694        String confFile = DEFAULT_PROPERTIES_FILE; 
    694695         
     
    718719 
    719720        try { 
    720             g_config.load(new FileInputStream(confFile)); 
     721            g_config = new JSONPropertyFile(confFile); 
     722 
     723            //System.out.println("CONFIG:"); 
     724            //System.out.println(g_config.toString()); 
     725        } catch (JSONException exc) { 
     726            Logger.global.severe("error: could not parse publisher configuration from file: " + confFile); 
     727            Logger.global.severe("error: problem was: " + exc.toString()); 
     728            Logger.global.severe("error: Maybe your configuration file has an old format?  Please see http://feedtree.net/project/wiki/FeedTreePublisher to learn about the new JSON-based config file syntax."); 
     729            System.exit(1); 
    721730        } catch (IOException exc) { 
    722731            Logger.global.severe("error: could not load publisher configuration from file: " + confFile); 
     
    724733        } 
    725734         
    726         int myPort = to_int(g_config.getProperty( 
    727             PROP_PASTRY_PORT, new Integer(Client.PASTRY_PORT).toString())); 
    728         int bsPort = to_int(g_config.getProperty( 
    729             PROP_BOOTSTRAP_PORT, new Integer(Client.PASTRY_PORT).toString())); 
    730         String bs = g_config.getProperty( 
     735        int myPort = g_config.optInt(PROP_PASTRY_PORT, Client.PASTRY_PORT); 
     736        int bsPort = g_config.optInt(PROP_BOOTSTRAP_PORT, Client.PASTRY_PORT); 
     737        String bs = g_config.optString( 
    731738            PROP_BOOTSTRAP, DEFAULT_BOOTSTRAP); 
    732739 
    733         int webPort = to_int(g_config.getProperty(PROP_WEB_PORT, "8500")); 
    734         String[] urls = g_config.getProperty(PROP_FEED_URLS,"").split("\\s+"); 
    735         if (urls.length == 0) { 
    736             Logger.global.severe("error: no feed_urls specified in " + confFile); 
     740        int webPort = g_config.optInt(PROP_WEB_PORT, 8500); 
     741 
     742        String[] urls = null; 
     743         
     744        JSONArray urlList = g_config.optJSONArray(PROP_FEEDS); 
     745         
     746        if (urlList == null || urlList.length() == 0) { 
     747            Logger.global.severe("error: no " + PROP_FEEDS + " specified in " + confFile); 
    737748            System.exit(1); 
     749        } else { 
     750            int len = urlList.length(); 
     751            urls = new String[len]; 
     752            try { 
     753                for (int i=0; i<len; i++) { 
     754                    urls[i] = urlList.getString(i); 
     755                } 
     756            } catch (JSONException exc) { 
     757                Logger.global.severe("error: invalid syntax for " + PROP_FEEDS + ": " + exc.toString()); 
     758            } 
    738759        } 
    739760 
    740761        PrivateKey privateKey = null; 
    741         String keystoreFile = g_config.getProperty( 
    742             PROP_KEYSTORE); 
     762        String keystoreFile = g_config.optString(PROP_KEYSTORE, null); 
    743763        if (keystoreFile == null) { 
    744764            Logger.global.info("No keystore; entries will not be signed"); 
    745765        } else { 
    746             String keystoreType = g_config.getProperty
     766            String keystoreType = g_config.optString
    747767                PROP_KEYSTORE_TYPE, "JKS"); 
    748768            try { 
    749769                KeyStore ks = KeyStore.getInstance(keystoreType); 
    750770                ks.load(new FileInputStream(keystoreFile),  
    751                     g_config.getProperty(PROP_KEYSTORE_PASS, "").toCharArray()); 
     771                    g_config.optString(PROP_KEYSTORE_PASS, "").toCharArray()); 
    752772                privateKey = (PrivateKey)ks.getKey( 
    753                     g_config.getProperty(PROP_KEY_NAME, "default"), 
    754                     g_config.getProperty(PROP_KEY_PASS, "").toCharArray()); 
     773                    g_config.optString(PROP_KEY_NAME, "default"), 
     774                    g_config.optString(PROP_KEY_PASS, "").toCharArray()); 
    755775             
    756776            } catch (FileNotFoundException exc) { 
     
    768788        // systemwide default proxy is a FeedTree web proxy application. 
    769789        System.setProperty("http.proxyHost", 
    770                 g_config.getProperty(PROP_HTTP_PROXY, "")); 
     790                g_config.optString(PROP_HTTP_PROXY, "")); 
    771791         
    772792