Revision 8128
Added by Jing Tao over 11 years ago
metacat-index/src/test/java/edu/ucsb/nceas/metacat/index/SolrIndexIT.java | ||
---|---|---|
47 | 47 |
} |
48 | 48 |
|
49 | 49 |
private SolrIndex generateSolrIndex() throws Exception { |
50 |
String springConfigFile = "src/main/resources/index-processor-context.xml";
|
|
50 |
String springConfigFile = "/index-processor-context.xml"; |
|
51 | 51 |
String metacatPropertyFile = null; //in this test, we use the test.properties file rather than metacat.properties file. so set it to be null. |
52 | 52 |
ApplicationController controller = new ApplicationController(springConfigFile, metacatPropertyFile); |
53 | 53 |
controller.initialize(); |
metacat-index/src/main/java/edu/ucsb/nceas/metacat/index/ApplicationController.java | ||
---|---|---|
39 | 39 |
import org.dataone.configuration.Settings; |
40 | 40 |
import org.dataone.service.exceptions.ServiceFailure; |
41 | 41 |
import org.springframework.context.ApplicationContext; |
42 |
import org.springframework.context.support.ClassPathXmlApplicationContext; |
|
42 | 43 |
import org.springframework.context.support.FileSystemXmlApplicationContext; |
43 | 44 |
|
44 | 45 |
import com.ibm.icu.util.Calendar; |
... | ... | |
60 | 61 |
private List<SolrIndex> solrIndexes = null; |
61 | 62 |
private List<SystemMetadataEventListener> sysmetaListeners = new ArrayList<SystemMetadataEventListener>(); |
62 | 63 |
private static ApplicationContext context = null; |
63 |
private String springConfigFile = "src/main/resources/index-processor-context.xml";
|
|
64 |
private String springConfigFileURL = "/index-processor-context.xml";
|
|
64 | 65 |
private String metacatPropertiesFile = null; |
65 | 66 |
private static int waitingTime = IndexGenerator.WAITTIME; |
66 | 67 |
private static int maxAttempts = IndexGenerator.MAXWAITNUMBER; |
... | ... | |
76 | 77 |
}*/ |
77 | 78 |
|
78 | 79 |
/** |
79 |
* Set the Spring configuration file and metacat.properties file |
|
80 |
* Set the Spring configuration file url and metacat.properties file
|
|
80 | 81 |
* @param springConfigFile the path of the Spring configuration file |
81 | 82 |
* @param metacatPropertyFile the path of the metacat.properties file |
82 | 83 |
*/ |
83 |
public ApplicationController(String springConfigFile, String metacatPropertiesFile) throws Exception { |
|
84 |
this.springConfigFile = springConfigFile;
|
|
84 |
public ApplicationController(String springConfigFileURL, String metacatPropertiesFile) throws Exception {
|
|
85 |
this.springConfigFileURL = springConfigFileURL;
|
|
85 | 86 |
this.metacatPropertiesFile = metacatPropertiesFile; |
86 | 87 |
//init(); |
87 | 88 |
} |
... | ... | |
182 | 183 |
*/ |
183 | 184 |
private ApplicationContext getContext() { |
184 | 185 |
if (context == null) { |
185 |
context = new FileSystemXmlApplicationContext(springConfigFile);
|
|
186 |
context = new ClassPathXmlApplicationContext(springConfigFileURL);
|
|
186 | 187 |
} |
187 | 188 |
return context; |
188 | 189 |
} |
... | ... | |
192 | 193 |
* @return the path of the Spring configuration file. |
193 | 194 |
*/ |
194 | 195 |
public String getSpringConfigFile() { |
195 |
return this.springConfigFile; |
|
196 |
return this.springConfigFileURL;
|
|
196 | 197 |
} |
197 | 198 |
|
198 | 199 |
/** |
metacat-index/src/main/java/edu/ucsb/nceas/metacat/index/MetacatIndexServlet.java | ||
---|---|---|
56 | 56 |
|
57 | 57 |
// Use the file prefix to indicate this is a absolute path. |
58 | 58 |
// see http://www.docjar.com/docs/api/org/springframework/context/support/FileSystemXmlApplicationContext.html |
59 |
private static final String FILEPREFIX = "file:"; |
|
59 |
//private static final String FILEPREFIX = "file:";
|
|
60 | 60 |
|
61 | 61 |
private static Log log = LogFactory.getLog(MetacatIndexServlet.class); |
62 | 62 |
|
... | ... | |
67 | 67 |
//System.out.println("++++++++++++++++++++++++------------------- start the servlet"); |
68 | 68 |
//initializeSharedConfiguration(config); |
69 | 69 |
// initialize the application using the configured application-context |
70 |
URL url = getClass().getResource("/index-processor-context.xml"); |
|
70 |
//URL url = getClass().getResource("/index-processor-context.xml");
|
|
71 | 71 |
//find the sibling metacat.properties file |
72 | 72 |
String metacatPropertiesFilePath = config.getServletContext().getInitParameter("metacat.properties.path"); |
73 | 73 |
File contextDeploymentDir = new File(config.getServletContext().getRealPath("/")); |
... | ... | |
77 | 77 |
//System.out.println("the file is "+url.getPath()); |
78 | 78 |
//ApplicationController controller = null; |
79 | 79 |
try { |
80 |
ApplicationController controller = new ApplicationController(FILEPREFIX + url.getFile(), fullMetacatPropertiesFilePath); |
|
80 |
//ApplicationController controller = new ApplicationController(FILEPREFIX + url.getFile(), fullMetacatPropertiesFilePath); |
|
81 |
ApplicationController controller = new ApplicationController("/index-processor-context.xml", fullMetacatPropertiesFilePath); |
|
81 | 82 |
//Start the controller in other thread - SystemmetadataEventListener and to generate indexes for those haven't been indexed in another thread |
82 | 83 |
Thread controllerThread = new Thread(controller); |
83 | 84 |
controllerThread.start(); |
Also available in: Unified diff
Use the class path configuration of spring to replace the file configuration. We can reuse the application context files in the d1_cn_index_processor jar.