Changeset 4542


Ignore:
Timestamp:
Feb 7, 2014, 12:48:31 PM (10 years ago)
Author:
olle
Message:

Refs #823. First version of support for reading connection properties from a properties file:

  1. New connection properties template file conf/connection.properties.in in client/servlet/ added. It contains settings for accessing files using SSL (Secure Sockets Layer) connection, and redirects for local cache when accessing files via URL.
  2. Outermost Ant build file build.xml updated to include files connection.properties* when copying files from client/servlet/conf/ to www/WEB-INF/classes/ in distribution directory.
  3. New class/file ConnectionPropertiesFile.java in api/core/ added. It loads connection.properties file and gives access to the settings in the latter.
  4. Class/file core/Application.java in api/core/ updated:
    a. Private static method void createSSLFactory() updated to call new private static method String fetchProperty(Properties pf, String property, boolean replaceEmptyStringWithNull) to obtain property values.
    b, New private static method String fetchProperty(Properties pf, String property, boolean replaceEmptyStringWithNull) added. It fetches a property value from the properties file, if existing, otherwise from system properties. Optional replacement of empty string with null, when property value is returned.
    c. New private static method String fetchProperty(Properties pf, String property) added. It calls new private static method String fetchProperty(Properties pf, String property, boolean replaceEmptyStringWithNull) with argument replaceEmptyStringWithNull set to false, to obtain the vallue to return.
Location:
trunk
Files:
2 added
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/api/core/src/org/proteios/core/Application.java

    r4373 r4542  
    2525package org.proteios.core;
    2626
     27import org.proteios.ConnectionPropertiesFile;
    2728import org.proteios.core.authentication.Authenticator;
    2829import org.proteios.core.data.ClientData;
     
    4748import java.util.List;
    4849import java.util.Map;
     50import java.util.Properties;
    4951import java.util.Random;
    5052import java.util.Timer;
     
    886888  private static void createSSLFactory()
    887889  {
    888     String keyStoreFileName = System.getProperty("javax.net.ssl.keyStore");
    889     String keyStorePassword = System
    890       .getProperty("javax.net.ssl.keyStorePassword");
    891     String alias = System.getProperty("cert.alias");
    892     String passfile = System.getProperty("cert.passFile");
     890    ConnectionPropertiesFile pf = new ConnectionPropertiesFile();
     891    boolean replaceEmptyStringWithNull = true;
     892    String keyStoreFileName = fetchProperty(pf, "javax.net.ssl.keyStore", replaceEmptyStringWithNull);
     893    String keyStorePassword = fetchProperty(pf, "javax.net.ssl.keyStorePassword", replaceEmptyStringWithNull);
     894    String alias = fetchProperty(pf, "cert.alias", replaceEmptyStringWithNull);
     895    String passfile = fetchProperty(pf, "cert.passFile", replaceEmptyStringWithNull);
    893896    if (keyStorePassword==null && passfile!=null)
    894897    {
     
    909912      }
    910913    }
    911     String trustStoreFileName = System
    912       .getProperty("javax.net.ssl.trustStore");
    913     String trustStorePassword = System
    914       .getProperty("javax.net.ssl.trustStorePassword");
     914    String trustStoreFileName = fetchProperty(pf, "javax.net.ssl.trustStore", replaceEmptyStringWithNull);
     915    String trustStorePassword = fetchProperty(pf, "javax.net.ssl.trustStorePassword", replaceEmptyStringWithNull);
    915916    if (keyStoreFileName != null && trustStoreFileName != null)
    916917    {
     
    951952      }
    952953    }
     954  }
     955
     956
     957  /**
     958   * Fetch property value from properties file, if existing,
     959   * otherwise from system properties.
     960   *
     961   * @param pf Properties Properties file to use.
     962   * @param property String Property to get value for.
     963   * @return String The found property value.
     964   */
     965  private static String fetchProperty(Properties pf, String property)
     966  {
     967    boolean replaceEmptyStringWithNull = false;
     968    return fetchProperty(pf, property, replaceEmptyStringWithNull);
     969  }
     970
     971
     972  /**
     973   * Fetch property value from properties file, if existing,
     974   * otherwise from system properties. Optional replacement
     975   * of empty string with `null`, when property value is returned.
     976   *
     977   * @param pf Properties Properties file to use.
     978   * @param property String Property to get value for.
     979   * @param replaceEmptyStringWithNull boolean Flag indicating that `null` should be returned instead of an empty string.
     980   * @return String The found property value.
     981   */
     982  private static String fetchProperty(Properties pf, String property, boolean replaceEmptyStringWithNull)
     983  {
     984    String value = null;
     985    if (property != null && !property.equals(""))
     986    {
     987      if (pf != null)
     988      {
     989        // Get property value from properties file
     990        value = pf.getProperty(property);
     991        // Note: The output below is printed when running update.sh during installation
     992        log.debug("Property " + property + " fetched from properties file.");
     993      }
     994      else
     995      {
     996        // Get property value from system properties
     997        value = System.getProperty(property);
     998        // Note: The output below is printed when running update.sh during installation
     999        log.debug("Property " + property + " fetched from system properties.");
     1000      }
     1001      // Optional replacement of empty string with null
     1002      if (replaceEmptyStringWithNull)
     1003      {
     1004        if (value != null && value.equals(""))
     1005        {
     1006          value = null;
     1007        }
     1008      }
     1009    }
     1010    return value;
    9531011  }
    9541012
  • trunk/build.xml

    r4529 r4542  
    213213      </fileset>
    214214      <fileset dir="client/servlet/conf">
     215        <include name="connection.properties*" />
    215216        <include name="log4j.properties*" />
    216217        <include name="proteios.config*" />
Note: See TracChangeset for help on using the changeset viewer.