Changeset 2600
- Timestamp:
- 02/21/13 07:33:35 (11 years ago)
- 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 9 9 /** 10 10 * {@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 * 16 17 */ 17 18 public class VloApplication extends WebApplication { 18 19 19 20 private final SearchResultsDao searchResults; 20 21 21 22 // application configuration object 22 23 23 static VloConfig config; 24 24 25 25 // flag indicating whether or not the application object lives in a context 26 27 26 boolean inContext; 28 27 … … 35 34 if (inContext) { 36 35 37 // add the context parameters to the configuration38 36 // get the servlet's context 37 39 38 ServletContext servletContext; 40 39 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 */ 42 56 } 43 57 } … … 46 60 * Web application constructor<br><br> 47 61 * 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. 51 64 */ 52 65 public VloApplication() { … … 58 71 * {@literal init()} method will be invoked. 59 72 */ 60 config = VloConfig.webApp(); 73 String fileName = VloConfig.class.getResource("/VloConfig.xml").getFile(); 74 75 config = VloConfig.readConfig(fileName); 61 76 62 77 // let the {@literal init()} method know that there will be a context … … 72 87 * Web application constructor<br><br> 73 88 * 74 * Introduce the idea of a channel: the environment in which a test75 * 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> 76 91 * 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. 77 103 */ 78 104 public VloApplication(VloConfig testConfig) { -
vlo/branches/vlo-2.13-param/vlo_webapp/src/main/java/eu/clarin/cmdi/vlo/config/ConfigFromFile.java
r2590 r2600 26 26 * @author keeloo 27 27 */ 28 public abstractclass ConfigFromFile {28 public class ConfigFromFile { 29 29 30 30 /** … … 35 35 36 36 /** 37 * Constraint on a deriving class<br><br>38 *39 * Ask a deriving class to implement a method that returns the name of the40 * file the persister object can read from or write to.<br><br>41 *42 * @return the name of an XML file43 */44 public abstract String getFileName();45 46 /**47 37 * Configure by reading from an XML file 38 * 39 * @param fileName 48 40 * 49 41 * @param config the object whose annotated members will be assigned a value … … 52 44 * @return the object with values assigned to annotated members 53 45 */ 54 public static synchronized ConfigFromFile read( ConfigFromFile config) {46 public static synchronized ConfigFromFile read(String fileName, ConfigFromFile config) { 55 47 56 48 ConfigFilePersister persister; 57 49 // config itself might not reference a file name 58 persister = new ConfigFilePersister(config, config.getFileName ());50 persister = new ConfigFilePersister(config, fileName); 59 51 60 52 // assign the members their values … … 68 60 * @param config the object whose annotated members and values will be 69 61 * written to a file in the form of an XML definition. 62 * 63 * @param 70 64 */ 71 public static void write(ConfigFromFile config ) {65 public static void write(ConfigFromFile config, String fileName) { 72 66 73 67 ConfigFilePersister persister; 74 68 // config itself might not reference a file name 75 persister = new ConfigFilePersister(config, config.getFileName ());69 persister = new ConfigFilePersister(config, fileName); 76 70 77 71 // create the definition -
vlo/branches/vlo-2.13-param/vlo_webapp/src/main/java/eu/clarin/cmdi/vlo/config/ImporterConfig.java
r2590 r2600 20 20 public class ImporterConfig extends ConfigFromFile { 21 21 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 33 23 public static synchronized ImporterConfig get() { 34 24 return (ImporterConfig)ImporterConfig.get(); -
vlo/branches/vlo-2.13-param/vlo_webapp/src/main/java/eu/clarin/cmdi/vlo/config/VloConfig.java
r2598 r2600 95 95 96 96 /** 97 * XML File in which the application configuration is stored98 */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 to106 * the superclass. In other words: this method overrides a method in the107 * superclass.108 *109 * @return the name of the application parameter XML file110 */111 @Override112 public String getFileName() {113 /**114 * Check the name of the web application parameter file. May be turn it115 * into a {@literal maven} parameter.116 */117 return CONFIG_FILE;118 }119 120 /**121 97 * Make the configuration statically accessible<br><br> 122 98 * … … 146 122 * 147 123 * WebAppConfig.open().getParameterMember()<br><br> 124 * 125 * @param fileName 148 126 * 149 127 * @return the web application configuration in a new static context 150 128 */ 151 public static VloConfig webApp() {129 public static VloConfig readConfig(String fileName) { 152 130 if (config == null) { 153 131 // the configuration is not there yet; create it now … … 157 135 // get the XML file configuration from the file by invoking the 158 136 159 config = (VloConfig) read( config);137 config = (VloConfig) read(fileName, config); 160 138 161 139 return config; … … 169 147 * be made. 170 148 * 149 * @param fileName 150 * 171 151 * @return 172 152 */ 173 public static VloConfig testWebApp() {153 public static VloConfig readTestConfig(String fileName) { 174 154 if (config == null) { 175 155 // the configuration is not there yet; create it now … … 179 159 // get the XML file configuration from the file by invoking the 180 160 181 config = (VloConfig) read( config);161 config = (VloConfig) read(fileName, config); 182 162 183 163 return config; … … 193 173 } 194 174 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 of199 * 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 anything204 } else {205 // put it away by invoking the superclass write method206 207 write (config);208 209 /**210 * Contrary to web the application parameters, servlet context211 * parameters can not be written back to where they reside, so there212 * is nothing left to do here.213 */214 }215 }216 217 175 /** 218 176 * Web application parameter members<br><br> … … 612 570 * @return the static WebAppConfig member 613 571 */ 614 public static VloConfig addServletContext(VloConfig config,ServletContext context) {572 public static VloConfig switchToExternalConfig(ServletContext context) { 615 573 616 574 // retrieve parameter valies from the servlet context 617 575 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 } 619 584 620 585 return config; -
vlo/branches/vlo-2.13-param/vlo_webapp/src/main/java/eu/clarin/cmdi/vlo/dao/SolrDao.java
r2597 r2600 13 13 import org.slf4j.LoggerFactory; 14 14 15 import eu.clarin.cmdi.vlo.Configuration;16 15 import eu.clarin.cmdi.vlo.config.VloConfig; 17 16 … … 22 21 23 22 public SolrDao() { 24 String solrUrl = VloConfig.get().getSolrUrl(); 23 String solrUrl; 24 solrUrl = VloConfig.get().getSolrUrl(); 25 25 try { 26 26 solrServer = new CommonsHttpSolrServer(solrUrl); -
vlo/branches/vlo-2.13-param/vlo_webapp/src/main/webapp/META-INF/context.xml
r2597 r2600 2 2 <!-- VLO application context file 3 3 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> 4 explain about how the configurtion works 13 5 14 6 --> 15 7 <Context antiJARLocking="true" path="/vlo"> 16 <Parameter name=" solrUrl" value="http://localhost:8084/vlo_solr/"/>8 <Parameter name="externalConfig" value="/Users/keeloo/VloConfig.xml"/> 17 9 </Context> -
vlo/branches/vlo-2.13-param/vlo_webapp/src/test/java/eu/clarin/cmdi/vlo/pages/FacetBoxPanelTest.java
r2598 r2600 1 1 package eu.clarin.cmdi.vlo.pages; 2 2 3 import static org.junit.Assert.assertEquals;4 3 import eu.clarin.cmdi.vlo.VloApplication; 4 import eu.clarin.cmdi.vlo.config.VloConfig; 5 5 import java.util.List; 6 7 6 import org.apache.solr.client.solrj.response.FacetField; 8 7 import org.apache.solr.client.solrj.response.FacetField.Count; 9 8 import org.apache.wicket.util.tester.WicketTester; 9 import static org.junit.Assert.assertEquals; 10 10 import org.junit.Before; 11 11 import org.junit.Test; 12 13 import eu.clarin.cmdi.vlo.VloApplication;14 import eu.clarin.cmdi.vlo.config.VloConfig;15 12 16 13 public class FacetBoxPanelTest { … … 21 18 public void setUp() { 22 19 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 24 26 wicketTester = new WicketTester(new VloApplication(testConfig)); 25 27 }
Note: See TracChangeset
for help on using the changeset viewer.