Changeset 2600


Ignore:
Timestamp:
02/21/13 07:33:35 (11 years ago)
Author:
keeloo
Message:

Instead of retrieving the SolrUrl? from the context of the application, retrieve the location of an external VloConfig? from the context, preferably the file used by the importer. By using the context in this way, the configuration for both the importer and the web application will be one and the same.

Location:
vlo/branches/vlo-2.13-param/vlo_webapp/src
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • vlo/branches/vlo-2.13-param/vlo_webapp/src/main/java/eu/clarin/cmdi/vlo/VloApplication.java

    r2598 r2600  
    99/**
    1010 * {@literal VLO} web application.<br><br>
    11  *
    12  * Because the class extends the WebApplication class, the VLO application
    13  * will normally be deployed on a web server. However, by running the Start
    14  * class, the application outside of a server container.
    15  *
     11 *
     12 * Because the VloApplication class extends WebApplication, a class instance
     13 * will normally reside inside a web server container. By running the Start
     14 * class however, an instance of the application will reside outside a server
     15 * container.
     16 *
    1617 */
    1718public class VloApplication extends WebApplication {
    1819
    1920    private final SearchResultsDao searchResults;
    20    
     21
    2122    // application configuration object
    22    
    2323    static VloConfig config;
    2424   
    2525    // flag indicating whether or not the application object lives in a context
    26    
    2726    boolean inContext;
    2827
     
    3534        if (inContext) {
    3635           
    37             // add the context parameters to the configuration
    38 
     36            // get the servlet's context
     37           
    3938            ServletContext servletContext;
    4039            servletContext = this.getServletContext();
    41             config = VloConfig.addServletContext(config, servletContext);
     40           
     41            /**
     42             * Send the servlet context to the configuration object to enable it
     43             * to read an externel VloConfig.xml configuration file.
     44             */
     45           
     46            config = VloConfig.switchToExternalConfig(servletContext);
     47
     48            /**
     49             * Instead of obtaining the SolrUrl parameter from the context, read
     50             * the name of another instance - preferably the one that the
     51             * importer uses for its configuration - from the context. Once this
     52             * has been done, the whole web application configuration could be
     53             * refreshed. Note: add a method for refreshing the current
     54             * configuration to the VloConfig class.
     55             */
    4256        }
    4357    }
     
    4660     * Web application constructor<br><br>
    4761     *
    48      * Create the application by invoking this constructor, whenever you want it
    49      * to be an application deployed in a web server container, that is: as an
    50      * application living in a web server context.
     62     * Create an application instance configured to be living inside a web
     63     * server container.
    5164     */
    5265    public VloApplication() {
     
    5871         * {@literal init()} method will be invoked.
    5972         */
    60         config = VloConfig.webApp();
     73        String fileName = VloConfig.class.getResource("/VloConfig.xml").getFile();
     74       
     75        config = VloConfig.readConfig(fileName);
    6176
    6277        // let the {@literal init()} method know that there will be a context
     
    7287     * Web application constructor<br><br>
    7388     *
    74      * Introduce the idea of a channel: the environment in which a test
    75      * configuration object is created is in a way connected to this method.
     89     * Create an application instance configured to be living without a web
     90     * server container context.<br><br>
    7691     *
     92     * @param testConfig a configuration that could be different from the
     93     * packaged parameters
     94     *
     95     * An instance like this can for example be used for testing purposes. In
     96     * the case of testing, the constructor is invoked from a class in a test
     97     * package. Within such a class a configuration object can be manipulated
     98     * according to specific needs. <br><br>
     99     *
     100     * Please note that in the case of a test configuration, while the
     101     * application object could reside inside a web server container, the
     102     * context associated with this container will be ignored.
    77103     */
    78104    public VloApplication(VloConfig testConfig) {
  • vlo/branches/vlo-2.13-param/vlo_webapp/src/main/java/eu/clarin/cmdi/vlo/config/ConfigFromFile.java

    r2590 r2600  
    2626 * @author keeloo
    2727 */
    28 public abstract class ConfigFromFile {
     28public class ConfigFromFile {
    2929
    3030    /**
     
    3535
    3636    /**
    37      * Constraint on a deriving class<br><br>
    38      *
    39      * Ask a deriving class to implement a method that returns the name of the
    40      * file the persister object can read from or write to.<br><br>
    41      *
    42      * @return the name of an XML file
    43      */
    44     public abstract String getFileName();
    45 
    46     /**
    4737     * Configure by reading from an XML file
     38     *
     39     * @param fileName
    4840     *
    4941     * @param config the object whose annotated members will be assigned a value
     
    5244     * @return the object with values assigned to annotated members
    5345     */
    54     public static synchronized ConfigFromFile read(ConfigFromFile config) {
     46    public static synchronized ConfigFromFile read(String fileName, ConfigFromFile config) {
    5547
    5648        ConfigFilePersister persister;
    5749        // config itself might not reference a file name
    58         persister = new ConfigFilePersister(config, config.getFileName ());
     50        persister = new ConfigFilePersister(config, fileName);
    5951
    6052        // assign the members their values
     
    6860     * @param config the object whose annotated members and values will be
    6961     * written to a file in the form of an XML definition.
     62     *
     63     * @param
    7064     */
    71      public static void write(ConfigFromFile config) {
     65     public static void write(ConfigFromFile config, String fileName) {
    7266       
    7367        ConfigFilePersister persister;
    7468        // config itself might not reference a file name
    75         persister = new ConfigFilePersister(config, config.getFileName ());
     69        persister = new ConfigFilePersister(config, fileName);
    7670
    7771        // create the definition
  • vlo/branches/vlo-2.13-param/vlo_webapp/src/main/java/eu/clarin/cmdi/vlo/config/ImporterConfig.java

    r2590 r2600  
    2020public class ImporterConfig extends ConfigFromFile {
    2121   
    22     /**
    23      * Definition of the name of the configuration file.
    24      *
    25      * @return
    26      */
    27     @Override
    28     public String getFileName() {
    29         return "ImporterConfig.xml";
    30     }
    31    
    32     // 'override' the base class method
     22
    3323    public static synchronized ImporterConfig get() {
    3424        return (ImporterConfig)ImporterConfig.get();
  • vlo/branches/vlo-2.13-param/vlo_webapp/src/main/java/eu/clarin/cmdi/vlo/config/VloConfig.java

    r2598 r2600  
    9595   
    9696    /**
    97      * XML File in which the application configuration is stored
    98      */
    99     public static final String CONFIG_FILE =
    100             VloConfig.class.getResource("/VloConfig.xml").getFile();
    101 
    102     /**
    103      * Get the name of the XML file.
    104      *
    105      * Represent the filename by a method primarily for making it available to
    106      * the superclass. In other words: this method overrides a method in the
    107      * superclass.
    108      *
    109      * @return the name of the application parameter XML file
    110      */
    111     @Override
    112     public String getFileName() {
    113         /**
    114          * Check the name of the web application parameter file. May be turn it
    115          * into a {@literal maven} parameter.
    116          */
    117         return CONFIG_FILE;
    118     }
    119    
    120     /**
    12197     * Make the configuration statically accessible<br><br>
    12298     *
     
    146122     *
    147123     * WebAppConfig.open().getParameterMember()<br><br>
     124     *
     125     * @param fileName
    148126     *
    149127     * @return the web application configuration in a new static context
    150128     */
    151     public static VloConfig webApp() {
     129    public static VloConfig readConfig(String fileName) {
    152130        if (config == null) {
    153131            // the configuration is not there yet; create it now
     
    157135        // get the XML file configuration from the file by invoking the
    158136
    159         config = (VloConfig) read(config);
     137        config = (VloConfig) read(fileName, config);
    160138
    161139        return config;
     
    169147     * be made.
    170148     *
     149     * @param fileName
     150     *
    171151     * @return
    172152     */
    173     public static VloConfig testWebApp() {
     153    public static VloConfig readTestConfig(String fileName) {
    174154        if (config == null) {
    175155            // the configuration is not there yet; create it now
     
    179159        // get the XML file configuration from the file by invoking the
    180160
    181         config = (VloConfig) read(config);
     161        config = (VloConfig) read(fileName, config);
    182162
    183163        return config;
     
    193173    }
    194174
    195     /**
    196      * Close the static context of WebAppConfig members<br><cr>
    197      *
    198      * As a counterpart to open() the close() method just writes the value of
    199      * the parameters in the XML file back to this file.
    200      */
    201     public void close() {
    202         if (config == null) {
    203             // no configuration is not there yet; no need to do anything
    204         } else {
    205             // put it away by invoking the superclass write method
    206 
    207             write (config);
    208 
    209             /**
    210              * Contrary to web the application parameters, servlet context
    211              * parameters can not be written back to where they reside, so there
    212              * is nothing left to do here.
    213              */
    214         }
    215     }
    216    
    217175    /**
    218176     * Web application parameter members<br><br>
     
    612570     * @return the static WebAppConfig member
    613571     */
    614     public static VloConfig addServletContext(VloConfig config, ServletContext context) {
     572    public static VloConfig switchToExternalConfig(ServletContext context) {
    615573
    616574        // retrieve parameter valies from the servlet context
    617575
    618         config.solrUrl = context.getInitParameter("solrUrl");
     576        String fileName;
     577        fileName = context.getInitParameter("externalConfig");
     578       
     579        if (fileName == null) {
     580            // no external config
     581        } else {
     582            config = (VloConfig) read(fileName, config);
     583        }
    619584
    620585        return config;
  • vlo/branches/vlo-2.13-param/vlo_webapp/src/main/java/eu/clarin/cmdi/vlo/dao/SolrDao.java

    r2597 r2600  
    1313import org.slf4j.LoggerFactory;
    1414
    15 import eu.clarin.cmdi.vlo.Configuration;
    1615import eu.clarin.cmdi.vlo.config.VloConfig;
    1716
     
    2221
    2322    public SolrDao() {
    24         String solrUrl = VloConfig.get().getSolrUrl();
     23        String solrUrl;
     24        solrUrl = VloConfig.get().getSolrUrl();
    2525        try {
    2626            solrServer = new CommonsHttpSolrServer(solrUrl);
  • vlo/branches/vlo-2.13-param/vlo_webapp/src/main/webapp/META-INF/context.xml

    r2597 r2600  
    22<!-- VLO application context file
    33
    4 solrURL : URL through which the Solr server should be reached<br><br>
    5 
    6 Note that the VLO importer needs to know about this URL to. Because the
    7 importer is not a web application, the value of the parameter should
    8 be defined in the ImporterConfig.xml<br><br>
    9 
    10 as<br><br>
    11 
    12 <solrUrl>http://localhost:8084/vlo_solr/</solrUrl><br><br>
     4explain about how the configurtion works
    135
    146-->
    157<Context antiJARLocking="true" path="/vlo">
    16   <Parameter name="solrUrl" value="http://localhost:8084/vlo_solr/"/>
     8  <Parameter name="externalConfig" value="/Users/keeloo/VloConfig.xml"/>
    179</Context>
  • vlo/branches/vlo-2.13-param/vlo_webapp/src/test/java/eu/clarin/cmdi/vlo/pages/FacetBoxPanelTest.java

    r2598 r2600  
    11package eu.clarin.cmdi.vlo.pages;
    22
    3 import static org.junit.Assert.assertEquals;
    4 
     3import eu.clarin.cmdi.vlo.VloApplication;
     4import eu.clarin.cmdi.vlo.config.VloConfig;
    55import java.util.List;
    6 
    76import org.apache.solr.client.solrj.response.FacetField;
    87import org.apache.solr.client.solrj.response.FacetField.Count;
    98import org.apache.wicket.util.tester.WicketTester;
     9import static org.junit.Assert.assertEquals;
    1010import org.junit.Before;
    1111import org.junit.Test;
    12 
    13 import eu.clarin.cmdi.vlo.VloApplication;
    14 import eu.clarin.cmdi.vlo.config.VloConfig;
    1512
    1613public class FacetBoxPanelTest {
     
    2118    public void setUp() {
    2219        WicketTester wicketTester;
    23         testConfig = VloConfig.testWebApp();
     20        String fileName = VloConfig.class.getResource("/VloConfig.xml").getFile();
     21       
     22        testConfig = VloConfig.readTestConfig(fileName);
     23       
     24        // optionally, modify the test configuration here
     25       
    2426        wicketTester = new WicketTester(new VloApplication(testConfig));
    2527    }
Note: See TracChangeset for help on using the changeset viewer.