Changeset 38769 for main/trunk


Ignore:
Timestamp:
2024-02-22T18:59:49+13:00 (4 months ago)
Author:
anupama
Message:

Following Dr Bainbridge's task description and with his fixes: changes to get the Networked Derby Driver that we now use to use the shorter URL to the usersDB of the form jdbc:derby://derbyserver:derbyport/usersDB, instead of the full path to usersDB after the protocol. It needed setting derby.system.home JAVA_OPT when starting up the derby server in build.xml, then the tomcat greenstone3.xml file needed to refer to the shorter URL. Then classes that used to pass the full path need to pass the shorter form. And those classes called from the comandline with full usersDB path, like ModifyUsersDB, needed to now pass the shorter path. So build.xml needed further updating when calling ModifyUsersDB. The full path still works (for example, you can connect to both the original jdbc:derby URL and the shorter URL now from Squirrel SQL Client now), but the code now uses the shorter path.

Location:
main/trunk/greenstone3
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • main/trunk/greenstone3/build.xml

    r37759 r38769  
    455455  <property name="web.writablehome" value="${gsdl3.writablehome}"/>
    456456
     457  <!--
     458       The derby.system.home property can be used to set the same as JAVA_OPT
     459       when launching the derby networked server, so that the usersDB can be set to
     460       a shorter path in greenstone.xml and accessed with that shorter path through
     461       clients like Java code using a Client class, Squirreldb connecting and more.
     462       
     463       https://db.apache.org/derby/docs/10.3/tuning/rtunproper32066.html
     464       https://db.apache.org/derby/docs/10.13/devguide/cdevdvlp40350.html
     465       https://db.apache.org/derby/docs/10.0/manuals/tuning/perf91.html
     466       https://stackoverflow.com/questions/26624031/how-to-manually-specify-the-derby-system-home-property-to-start-a-derby-server
     467       but: https://zetcode.com/db/apachederbytutorial/tomcat/
     468       https://db.apache.org/derby/docs/10.4/adminguide/tadmincbdjhhfd.html
     469  -->
     470  <property name="derby.system.home" value="${web.writablehome}/etc"/>
     471 
    457472  <!-- The following are useful in Java-based config files (.properties,.json,.xml)
    458473       where the 'Unix style' (really URL style of slash, even in a file://...) is used -->
     
    13811396       and we want to be consistent in using the same java throughout. Solution:
    13821397       Refer to the JRE used in executing this ant file, which for installers will always be the bundled one.
    1383        https://stackoverflow.com/questions/17571595/env-java-home-not-found-ant -->
     1398       https://stackoverflow.com/questions/17571595/env-java-home-not-found-ant
     1399       
     1400       We set the derby.system.home so it doesn't default to the dir derby was
     1401       launched from. And then we can set greenstone3.xml to use a shorter URL
     1402       to the usersDB instead of the full GS3 web home path.
     1403       
     1404       Setting JAVA OPTS through an ant exec task:
     1405       https://stackoverflow.com/questions/55706746/set-java-opts-in-ant-task
     1406      -->
    13841407      <exec executable="${java.home}/bin/java" spawn="true"><!-- failonerror="true"-->
     1408    <arg value="-Dderby.system.home=${derby.system.home}"/><!-- Don't put quot-entities around the derby.system.home property! -->
    13851409    <env key="CLASSPATH" path="${derby.server.classpath.prop}"/>
    13861410    <arg value="org.apache.derby.drda.NetworkServerControl"/>
     
    33683392      <classpath refid="compile.classpath"/> <!--for ${web.lib}/gsdl3.jar and supporting files-->
    33693393      <sysproperty key="gsdl3.writablehome" value="${gsdl3.writablehome}" /> <!-- passes -D<syspropKey=syspropVal> to java class ModifyUsersDB. Available in java code as System.getProperty("syspropKey") -->
    3370       <arg file="${web.home}/etc/usersDB"/>
     3394      <arg value="usersDB"/><!--<arg file="${web.home}/etc/usersDB"/>-->
    33713395      <arg value="${user.username}"/>
    33723396      <arg value="password=${user.password}"/>
  • main/trunk/greenstone3/resources/tomcat/greenstone3.xml.svn

    r38768 r38769  
    2525        For more info about why you need the parameter value, see here:
    2626        https://stackoverflow.com/a/41232124
     27
     28        Because the derby networked server is now launched with the
     29        derby.system.home JAVA_OPT property set to the folder containing
     30        usersDB, we don't need url set to the full GS3 path to the usersDB.
    2731    -->
    2832    <Resource
     
    3539        validationQuery="values 1"
    3640        driverClassName="org.apache.derby.jdbc.ClientDriver"
    37         url="jdbc:derby://@derbyserver@:@derbyserverport@/@gsdl3webhome@/etc/usersDB" />
     41        url="jdbc:derby://@derbyserver@:@derbyserverport@/usersDB" />
    3842
    3943    <Realm className="org.apache.catalina.realm.LockOutRealm">
  • main/trunk/greenstone3/src/java/org/greenstone/gsdl3/action/DepositorAction.java

    r36107 r38769  
    110110        }
    111111
    112         DerbyWrapper database = new DerbyWrapper(GlobalProperties.getGSDL3Home() + File.separatorChar + "etc" + File.separatorChar + "usersDB");
     112        DerbyWrapper database = new DerbyWrapper(DerbyWrapper.USERSDB_DIR);
    113113        if (pageNumParseFail)
    114114        {
  • main/trunk/greenstone3/src/java/org/greenstone/gsdl3/service/Authentication.java

    r37517 r38769  
    11011101    {
    11021102        // check the usersDb database, if it isn't existing, check the etc dir, create the etc dir if it isn't existing, then create the  user database and add a "admin" user
    1103         String usersDB_dir = GlobalProperties.getGSDL3Home() + File.separatorChar + "etc" + File.separatorChar + "usersDB";
     1103        String usersDB_dir = DerbyWrapper.USERSDB_DIR;
    11041104        DerbyWrapper derbyWrapper = new DerbyWrapper(usersDB_dir);
    11051105        return derbyWrapper;
  • main/trunk/greenstone3/src/java/org/greenstone/gsdl3/service/UserTracker.java

    r32453 r38769  
    9595        String action = (String) params.get(ACTION_PARAM);
    9696
    97         DerbyWrapper database = new DerbyWrapper(GlobalProperties.getGSDL3Home() + File.separatorChar + "etc" + File.separatorChar + "usersDB");
     97        DerbyWrapper database = new DerbyWrapper(DerbyWrapper.USERSDB_DIR);
    9898        database.addUserAction(username, site, collection, oid, action);
    9999        database.closeDatabase();
     
    121121            String oid = (String) params.get(OID_PARAM);
    122122
    123             DerbyWrapper database = new DerbyWrapper(GlobalProperties.getGSDL3Home() + File.separatorChar + "etc" + File.separatorChar + "usersDB");
     123            DerbyWrapper database = new DerbyWrapper(DerbyWrapper.USERSDB_DIR);
    124124            ArrayList<HashMap<String, String>> userActions = database.getMostRecentUserActions(site, collection, oid);
    125125
  • main/trunk/greenstone3/src/java/org/greenstone/gsdl3/util/DerbyWrapper.java

    r37693 r38769  
    4444    static final String PROTOCOL;   
    4545
     46    static final String DRIVER = "org.apache.derby.jdbc.ClientDriver"; //"org.apache.derby.jdbc.EmbeddedDriver";
     47    static final String USERSDB = "usersDB";
     48    public static final String USERSDB_DIR;
     49   
    4650    // static code block to initialise the above
    4751    static {
     
    7579    PROTOCOL = "jdbc:derby://"+DERBYSERVER+":"+PORT+"/"; // "jdbc:derby://localhost:8327"; // by default
    7680    //System.out.println("@@@ PROTOCOL:" + PROTOCOL); //check in installer
     81
     82    // if embedded derby Driver (UNTESTED BRANCH), use the full path to usersDB,
     83    // else if networked derby server then just append dbname (usersDB) to protocol
     84    if(DRIVER.equals("org.apache.derby.jdbc.EmbeddedDriver")) {
     85        USERSDB_DIR = GlobalProperties.getGSDL3Home() + File.separatorChar + "etc" + File.separatorChar + USERSDB;
     86    } else { // derby network driver, just go direct to usersDB
     87        USERSDB_DIR = USERSDB;
     88    }   
    7789    }
    78    
    79 
    80     static final String DRIVER = "org.apache.derby.jdbc.ClientDriver"; //"org.apache.derby.jdbc.EmbeddedDriver";
    81         static final String USERSDB = "usersDB";
     90
    8291    public static final String USERS = "users";
    8392    public static final String ROLES = "roles";
     
    93102    public static void createDatabaseIfNeeded()
    94103    {
    95         String usersDB_dir = GlobalProperties.getGSDL3Home() + File.separatorChar + "etc" + File.separatorChar + "usersDB";
    96         protocol_str = PROTOCOL + usersDB_dir;
    97         File usersDB_file = new File(usersDB_dir);
     104        protocol_str = PROTOCOL + USERSDB_DIR;
     105        File usersDB_file = new File(USERSDB_DIR);
    98106        if (!usersDB_file.exists())
    99107        {
  • main/trunk/greenstone3/src/java/org/greenstone/gsdl3/util/ModifyUsersDB.java

    r37660 r38769  
    2828    then run:
    2929
    30     java -Dgsdl3.writablehome=/Scratch/ak19/gs3-svn-2Sep2015/web -cp web/WEB-INF/lib/gsdl3.jar:web/WEB-INF/lib/gutil.jar:web/WEB-INF/lib/derby.jar:web/WEB-INF/lib/derbyclient.jar:web/WEB-INF/lib/log4j-1.2.8.jar:web/WEB-INF/lib/commons-codec-1.7.jar:web/WEB-INF/classes org.greenstone.gsdl3.util.ModifyUsersDB web/etc/usersDB/ <username or 'ALL'> [options specifying user fields to change, e.g.: password=me!]
    31    
     30    java -Dgsdl3.writablehome=/Scratch/ak19/gs3-svn-2Sep2015/web -cp web/WEB-INF/lib/gsdl3.jar:web/WEB-INF/lib/gutil.jar:web/WEB-INF/lib/derby.jar:web/WEB-INF/lib/derbyclient.jar:web/WEB-INF/lib/log4j-1.2.8.jar:web/WEB-INF/lib/commons-codec-1.7.jar:web/WEB-INF/classes org.greenstone.gsdl3.util.ModifyUsersDB usersDB <username or 'ALL'> [options specifying user fields to change, e.g.: password=me!]
     31   
     32    Now just pass in "usersDB" for networked derby server, previously web/etc/usersDB/ was needed.
     33
    3234    Don't forget to stop the networked derby server again at the end, if you had started it: ant stop-derby
    3335   [[ OLD METHOD ]]
  • main/trunk/greenstone3/src/java/org/greenstone/gsdl3/util/txt2usersDB.java

    r35298 r38769  
    3131    then run:
    3232
    33     java -Dgsdl3.writablehome=/full/path/to/GS3/web -cp web/WEB-INF/lib/gsdl3.jar:web/WEB-INF/lib/gutil.jar:web/WEB-INF/lib/derby.jar:./web/WEB-INF/lib/derbyclient.jar:./web/WEB-INF/lib/log4j-1.2.8.jar:./web/WEB-INF/classes org.greenstone.gsdl3.util.txt2usersDB <filename>.txt web/etc/usersDB/ [-append]
     33    java -Dgsdl3.writablehome=/full/path/to/GS3/web -cp web/WEB-INF/lib/gsdl3.jar:web/WEB-INF/lib/gutil.jar:web/WEB-INF/lib/derby.jar:./web/WEB-INF/lib/derbyclient.jar:./web/WEB-INF/lib/log4j-1.2.8.jar:./web/WEB-INF/classes org.greenstone.gsdl3.util.txt2usersDB <filename>.txt usersDB [-append]
     34
     35    Now just pass in "usersDB" for networked derby server, previously web/etc/usersDB/ was needed.
    3436
    3537    Don't forget to stop the networked derby server again at the end, if you had started it: ant stop-derby
  • main/trunk/greenstone3/src/java/org/greenstone/gsdl3/util/usersDB2txt.java

    r30196 r38769  
    3333    then run:
    3434 
    35     java -Dgsdl3.writablehome=/full/path/to/GS3/web -cp ./web/WEB-INF/lib/gsdl3.jar:./web/WEB-INF/lib/gutil.jar:./web/WEB-INF/lib/derby.jar:./web/WEB-INF/lib/derbyclient.jar:./web/WEB-INF/lib/log4j-1.2.8.jar:./web/WEB-INF/classes org.greenstone.gsdl3.util.usersDB2txt web/etc/usersDB/
     35    java -Dgsdl3.writablehome=/full/path/to/GS3/web -cp ./web/WEB-INF/lib/gsdl3.jar:./web/WEB-INF/lib/gutil.jar:./web/WEB-INF/lib/derby.jar:./web/WEB-INF/lib/derbyclient.jar:./web/WEB-INF/lib/log4j-1.2.8.jar:./web/WEB-INF/classes org.greenstone.gsdl3.util.usersDB2txt usersDB
     36
     37    Now just pass in "usersDB" for networked derby server, previously web/etc/usersDB/ was needed.
    3638
    3739    if redirecting to a file append ">& filename.txt" to the above command
     
    4749    public static void main(String[] args) throws SQLException{
    4850    if (args.length!=1){
    49         System.out.println("The path of usersDB has to be given!");
     51        System.out.println("Set parameter to \"usersDB\" for a derby networked server or usersDB path if using an embedded derby server");
    5052        System.exit(0);
    5153    }
Note: See TracChangeset for help on using the changeset viewer.