Revision 4203
Added by daigle over 16 years ago
src/edu/ucsb/nceas/metacat/MetaCatServlet.java | ||
---|---|---|
138 | 138 |
private static final long serialVersionUID = 1L; |
139 | 139 |
private Timer timer = null; |
140 | 140 |
private static boolean sitemapScheduled; |
141 |
private static boolean fullyInitialized = false; |
|
141 | 142 |
|
142 | 143 |
// Constants -- these should be final in a servlet |
143 | 144 |
private static final String PROLOG = "<?xml version=\"1.0\"?>"; |
... | ... | |
185 | 186 |
// If both are false then stop the initialization |
186 | 187 |
if (!MetaCatUtil.bypassConfiguration() && !MetaCatUtil.isMetacatConfigured()) { |
187 | 188 |
return; |
188 |
}
|
|
189 |
} |
|
189 | 190 |
|
190 |
//initialize DBConnection pool |
|
191 |
DBConnectionPool connPool = DBConnectionPool.getInstance(); |
|
192 |
logMetacat.debug("DBConnection pool initialized: "+ connPool.toString()); |
|
191 |
initSecondHalf(context); |
|
193 | 192 |
|
194 |
//check if eml201 document were corrected or not. if not, correct eml201 documents. |
|
195 |
//Before Metacat 1.8.1, metacat uses tag RELEASE_EML_2_0_1_UPDATE_6 as eml |
|
196 |
//schema, which accidentily points to wrong version of eml-resource.xsd. |
|
197 |
String correctedEML201Doc = PropertyService.getProperty("eml201_document_corrected"); |
|
198 |
if (correctedEML201Doc != null && correctedEML201Doc.equals(FALSE)) |
|
199 |
{ |
|
200 |
logMetacat.info("===Start to correct eml201 documents"); |
|
201 |
EML201DocumentCorrector correct = new EML201DocumentCorrector(); |
|
202 |
boolean success = correct.run(); |
|
203 |
if (success) |
|
204 |
{ |
|
205 |
PropertyService.setProperty("eml201_document_corrected", TRUE); |
|
206 |
} |
|
207 |
logMetacat.info("====Finish to correct eml201 documents"); |
|
208 |
} |
|
209 |
|
|
210 |
|
|
211 |
// Index the paths specified in the metacat.properties |
|
212 |
checkIndexPaths(); |
|
213 |
|
|
214 |
// initiate the indexing Queue |
|
215 |
IndexingQueue.getInstance(); |
|
216 |
|
|
217 |
// start the IndexingThread if indexingTimerTaskTime more than 0. |
|
218 |
// It will index all the documents not yet indexed in the database |
|
219 |
int indexingTimerTaskTime = Integer.parseInt(PropertyService.getProperty("database.indexingTimerTaskTime")); |
|
220 |
int delayTime = Integer.parseInt(PropertyService.getProperty("database.indexingInitialDelay")); |
|
221 |
|
|
222 |
if(indexingTimerTaskTime > 0){ |
|
223 |
timer = new Timer(); |
|
224 |
timer.schedule(new IndexingTimerTask(), delayTime, indexingTimerTaskTime); |
|
225 |
} |
|
226 |
|
|
227 |
// read the config files: |
|
228 |
Vector<String> skins = MetaCatUtil.getOptionList(PropertyService.getProperty("skin.names")); |
|
229 |
String skinName, skinDirPath = null; |
|
230 |
File skinPropertyFile = null; |
|
231 |
|
|
232 |
for (int i = 0; i < skins.size(); i++) { |
|
233 |
skinName = (String) skins.elementAt(i); |
|
234 |
skinDirPath = context.getRealPath(CONFIG_DIR + "/skin.configs/" + skinName); |
|
235 |
skinPropertyFile = new File(skinDirPath, skinName + ".properties"); |
|
236 |
Properties skinOption = null; |
|
237 |
try { |
|
238 |
skinOption = new Properties(); |
|
239 |
FileInputStream fis = new FileInputStream(skinPropertyFile); |
|
240 |
skinOption.load(fis); |
|
241 |
fis.close(); |
|
242 |
} catch (IOException ioe) { |
|
243 |
logMetacat.error("Error in loading properties for skin " + "skinName" +" : " |
|
244 |
+ ioe.getMessage()); |
|
245 |
} |
|
246 |
MetaCatUtil.addSkinConfig(skinName, skinOption); |
|
247 |
//MetaCatUtil.skinconfigs.put(skinName, skinOption); |
|
248 |
} |
|
249 |
|
|
250 |
/* |
|
251 |
* If spatial option is turned on and set to regenerate the |
|
252 |
* spatial cache on restart, trigger the harvester regeneratation method |
|
253 |
*/ |
|
254 |
if ( PropertyService.getProperty("spatial.runSpatialOption").equals("true") && |
|
255 |
PropertyService.getProperty("spatial.regenerateCacheOnRestart").equals("true") ) { |
|
256 |
|
|
257 |
// Begin timer |
|
258 |
long before = System.currentTimeMillis(); |
|
259 |
|
|
260 |
// regenerate the entire spatial cache |
|
261 |
// may be expensive with many documents |
|
262 |
SpatialHarvester sh = new SpatialHarvester(); |
|
263 |
sh.regenerate(); |
|
264 |
sh.destroy(); |
|
265 |
|
|
266 |
// After running the first time, we want to to set regenerateCacheOnRestart to false |
|
267 |
// so that it does not regenerate the cache every time tomcat is restarted |
|
268 |
PropertyService.setProperty("spatial.regenerateCacheOnRestart","false"); |
|
269 |
|
|
270 |
// End timer |
|
271 |
long after = System.currentTimeMillis(); |
|
272 |
logMetacat.info(" ------ Spatial Harvester Time " + (after - before) + "ms"); |
|
273 |
|
|
274 |
} else { |
|
275 |
logMetacat.info(" \n **** Spatial cache is not set to regenerate on restart"); |
|
276 |
} |
|
277 |
|
|
278 |
sitemapScheduled = false; |
|
279 |
|
|
280 |
logMetacat.warn("Metacat (" + MetaCatVersion.getVersionID() |
|
281 |
+ ") initialized."); |
|
282 |
|
|
283 |
} catch (SQLException e) { |
|
193 |
} catch (ServiceException se) { |
|
284 | 194 |
String errorMessage = |
285 |
"SQL problem while intializing MetaCat Servlet: " + e.getMessage(); |
|
286 |
logMetacat.error(errorMessage); |
|
287 |
throw new ServletException(errorMessage); |
|
288 |
} catch (ServiceException se) { |
|
289 |
String errorMessage = |
|
290 | 195 |
"Service problem while intializing MetaCat Servlet: " + se.getMessage(); |
291 | 196 |
logMetacat.error(errorMessage); |
292 | 197 |
throw new ServletException(errorMessage); |
293 |
} catch (IOException ie) { |
|
294 |
String errorMessage = |
|
295 |
"IO problem while intializing MetaCat Servlet: "+ ie.getMessage(); |
|
296 |
logMetacat.error(errorMessage); |
|
297 |
throw new ServletException(errorMessage); |
|
298 |
} catch (GeneralPropertyException gpe) { |
|
299 |
String errorMessage = |
|
300 |
"Could not retrieve property while intializing MetaCat Servlet: " |
|
301 |
+ gpe.getMessage(); |
|
302 |
logMetacat.error(errorMessage); |
|
303 |
throw new ServletException(errorMessage); |
|
304 |
} |
|
198 |
} |
|
305 | 199 |
} |
200 |
|
|
201 |
|
|
202 |
/** |
|
203 |
* Initialize the remainder of the servlet. This is the part that can only |
|
204 |
* be initialized after metacat properties have been configured |
|
205 |
* |
|
206 |
* @param context |
|
207 |
* the servlet context of MetaCatServlet |
|
208 |
*/ |
|
209 |
public void initSecondHalf(ServletContext context) throws ServletException { |
|
210 |
Logger logMetacat = Logger.getLogger(MetaCatServlet.class); |
|
211 |
|
|
212 |
try { |
|
213 |
// initialize DBConnection pool |
|
214 |
DBConnectionPool connPool = DBConnectionPool.getInstance(); |
|
215 |
logMetacat.debug("DBConnection pool initialized: " + connPool.toString()); |
|
216 |
|
|
217 |
// check if eml201 document were corrected or not. if not, correct |
|
218 |
// eml201 documents. |
|
219 |
// Before Metacat 1.8.1, metacat uses tag RELEASE_EML_2_0_1_UPDATE_6 |
|
220 |
// as eml |
|
221 |
// schema, which accidentily points to wrong version of |
|
222 |
// eml-resource.xsd. |
|
223 |
String correctedEML201Doc = PropertyService |
|
224 |
.getProperty("eml201_document_corrected"); |
|
225 |
if (correctedEML201Doc != null && correctedEML201Doc.equals(FALSE)) { |
|
226 |
logMetacat.info("===Start to correct eml201 documents"); |
|
227 |
EML201DocumentCorrector correct = new EML201DocumentCorrector(); |
|
228 |
boolean success = correct.run(); |
|
229 |
if (success) { |
|
230 |
PropertyService.setProperty("eml201_document_corrected", TRUE); |
|
231 |
} |
|
232 |
logMetacat.info("====Finish to correct eml201 documents"); |
|
233 |
} |
|
234 |
|
|
235 |
// Index the paths specified in the metacat.properties |
|
236 |
checkIndexPaths(); |
|
237 |
|
|
238 |
// initiate the indexing Queue |
|
239 |
IndexingQueue.getInstance(); |
|
240 |
|
|
241 |
// start the IndexingThread if indexingTimerTaskTime more than 0. |
|
242 |
// It will index all the documents not yet indexed in the database |
|
243 |
int indexingTimerTaskTime = Integer.parseInt(PropertyService |
|
244 |
.getProperty("database.indexingTimerTaskTime")); |
|
245 |
int delayTime = Integer.parseInt(PropertyService |
|
246 |
.getProperty("database.indexingInitialDelay")); |
|
247 |
|
|
248 |
if (indexingTimerTaskTime > 0) { |
|
249 |
timer = new Timer(); |
|
250 |
timer.schedule(new IndexingTimerTask(), delayTime, indexingTimerTaskTime); |
|
251 |
} |
|
252 |
|
|
253 |
// read the config files: |
|
254 |
Vector<String> skins = MetaCatUtil.getOptionList(PropertyService |
|
255 |
.getProperty("skin.names")); |
|
256 |
String skinName, skinDirPath = null; |
|
257 |
File skinPropertyFile = null; |
|
258 |
|
|
259 |
for (int i = 0; i < skins.size(); i++) { |
|
260 |
skinName = (String) skins.elementAt(i); |
|
261 |
skinDirPath = context.getRealPath(CONFIG_DIR + "/skin.configs/" |
|
262 |
+ skinName); |
|
263 |
skinPropertyFile = new File(skinDirPath, skinName + ".properties"); |
|
264 |
Properties skinOption = null; |
|
265 |
try { |
|
266 |
skinOption = new Properties(); |
|
267 |
FileInputStream fis = new FileInputStream(skinPropertyFile); |
|
268 |
skinOption.load(fis); |
|
269 |
fis.close(); |
|
270 |
} catch (IOException ioe) { |
|
271 |
logMetacat.error("Error in loading properties for skin " + "skinName" |
|
272 |
+ " : " + ioe.getMessage()); |
|
273 |
} |
|
274 |
MetaCatUtil.addSkinConfig(skinName, skinOption); |
|
275 |
// MetaCatUtil.skinconfigs.put(skinName, skinOption); |
|
276 |
} |
|
277 |
|
|
278 |
/* |
|
279 |
* If spatial option is turned on and set to regenerate the spatial |
|
280 |
* cache on restart, trigger the harvester regeneratation method |
|
281 |
*/ |
|
282 |
if (PropertyService.getProperty("spatial.runSpatialOption").equals("true") |
|
283 |
&& PropertyService.getProperty("spatial.regenerateCacheOnRestart").equals("true")) { |
|
284 |
|
|
285 |
// Begin timer |
|
286 |
long before = System.currentTimeMillis(); |
|
287 |
|
|
288 |
// regenerate the entire spatial cache |
|
289 |
// may be expensive with many documents |
|
290 |
SpatialHarvester sh = new SpatialHarvester(); |
|
291 |
sh.regenerate(); |
|
292 |
sh.destroy(); |
|
293 |
|
|
294 |
// After running the first time, we want to to set |
|
295 |
// regenerateCacheOnRestart to false |
|
296 |
// so that it does not regenerate the cache every time tomcat is |
|
297 |
// restarted |
|
298 |
PropertyService.setProperty("spatial.regenerateCacheOnRestart", "false"); |
|
299 |
|
|
300 |
// End timer |
|
301 |
long after = System.currentTimeMillis(); |
|
302 |
logMetacat.info(" ------ Spatial Harvester Time " |
|
303 |
+ (after - before) + "ms"); |
|
304 |
|
|
305 |
} else { |
|
306 |
logMetacat.info(" \n **** Spatial cache is not set to regenerate on restart"); |
|
307 |
} |
|
308 |
|
|
309 |
sitemapScheduled = false; |
|
310 |
|
|
311 |
fullyInitialized = true; |
|
312 |
|
|
313 |
logMetacat.warn("Metacat (" + MetaCatVersion.getVersionID() |
|
314 |
+ ") initialized."); |
|
315 |
|
|
316 |
} catch (SQLException e) { |
|
317 |
String errorMessage = "SQL problem while intializing MetaCat Servlet: " |
|
318 |
+ e.getMessage(); |
|
319 |
logMetacat.error(errorMessage); |
|
320 |
throw new ServletException(errorMessage); |
|
321 |
} catch (IOException ie) { |
|
322 |
String errorMessage = "IO problem while intializing MetaCat Servlet: " |
|
323 |
+ ie.getMessage(); |
|
324 |
logMetacat.error(errorMessage); |
|
325 |
throw new ServletException(errorMessage); |
|
326 |
} catch (GeneralPropertyException gpe) { |
|
327 |
String errorMessage = "Could not retrieve property while intializing MetaCat Servlet: " |
|
328 |
+ gpe.getMessage(); |
|
329 |
logMetacat.error(errorMessage); |
|
330 |
throw new ServletException(errorMessage); |
|
331 |
} |
|
332 |
} |
|
306 | 333 |
|
307 | 334 |
/** |
308 |
* Close all db connections from the pool
|
|
309 |
*/
|
|
335 |
* Close all db connections from the pool
|
|
336 |
*/
|
|
310 | 337 |
public void destroy() { |
311 | 338 |
// Close all db connection |
312 | 339 |
System.out.println("Destroying MetacatServlet"); |
... | ... | |
332 | 359 |
} |
333 | 360 |
|
334 | 361 |
/** |
335 |
* Index the paths specified in the metacat.properties
|
|
336 |
*/
|
|
362 |
* Index the paths specified in the metacat.properties
|
|
363 |
*/
|
|
337 | 364 |
private void checkIndexPaths() { |
338 | 365 |
Logger logMetacat = Logger.getLogger(MetaCatServlet.class); |
339 | 366 |
|
... | ... | |
499 | 526 |
return; |
500 | 527 |
} |
501 | 528 |
|
529 |
// if we get here, metacat is configured. If we have not completed the |
|
530 |
// second half of the intialization, do so now. This allows us to initially |
|
531 |
// configure metacat without a restart. |
|
532 |
// TODO MCD eventually put in more intelligent reinitialization code so we |
|
533 |
// can change (some) properties without restarting metacat. |
|
534 |
if (!fullyInitialized) { |
|
535 |
initSecondHalf(request.getSession().getServletContext()); |
|
536 |
} |
|
537 |
|
|
502 | 538 |
/* |
503 | 539 |
* logMetacat.debug("Connection pool size: " |
504 | 540 |
* +connPool.getSizeOfDBConnectionPool(),10); logMetacat.debug("Free |
... | ... | |
862 | 898 |
* out.println(mue.getMessage()); mue.printStackTrace(out); |
863 | 899 |
* out.close(); } |
864 | 900 |
*/ |
901 |
} else if (action.equals("gohome")) { |
|
902 |
// forward to the default page |
|
903 |
RequestUtil.forwardRequest(request, response, "/"); |
|
865 | 904 |
} else { |
866 | 905 |
PrintWriter out = response.getWriter(); |
867 | 906 |
out.println("<?xml version=\"1.0\"?>"); |
... | ... | |
3608 | 3647 |
} |
3609 | 3648 |
} |
3610 | 3649 |
|
3611 |
// /** |
|
3612 |
// * Method to get session table which store the session info |
|
3613 |
// * @return |
|
3614 |
// */ |
|
3615 |
// public static Hashtable getSessionHash() { |
|
3616 |
// return sessionHash; |
|
3617 |
// } |
|
3618 |
|
|
3619 | 3650 |
/* |
3620 | 3651 |
* If the given docid only have one seperter, we need |
3621 | 3652 |
* append rev for it. The rev come from xml_documents |
... | ... | |
3645 | 3676 |
} |
3646 | 3677 |
|
3647 | 3678 |
/** |
3648 |
* Forward a request that was received by this servlet on to another |
|
3649 |
* JSP page or servlet to continue handling the request. |
|
3650 |
* |
|
3651 |
* @param request to be forwarded |
|
3652 |
* @param response that can be used for writing output to the client |
|
3653 |
* @param destination the context-relative URL to which the request is forwarded |
|
3654 |
*/ |
|
3655 |
private void forwardRequest(HttpServletRequest request, |
|
3656 |
HttpServletResponse response, String destination) { |
|
3657 |
|
|
3658 |
try { |
|
3659 |
getServletConfig().getServletContext().getRequestDispatcher( |
|
3660 |
destination).forward(request, response); |
|
3661 |
} catch (Exception e1) { |
|
3662 |
try { |
|
3663 |
PrintWriter out = response.getWriter(); |
|
3664 |
out.println("Error while forwarding to: " + destination); |
|
3665 |
e1.printStackTrace(out); |
|
3666 |
out.close(); |
|
3667 |
} catch (IOException e) { |
|
3668 |
Logger logMetacat = Logger.getLogger(MetaCatServlet.class); |
|
3669 |
logMetacat.debug("Unable to return error message to servlet."); |
|
3670 |
} |
|
3671 |
} |
|
3672 |
} |
|
3673 |
|
|
3674 |
/** |
|
3675 | 3679 |
* Schedule the sitemap generator to run periodically and update all |
3676 | 3680 |
* of the sitemap files for search indexing engines. |
3677 | 3681 |
* |
... | ... | |
3703 | 3707 |
sitemapScheduled = true; |
3704 | 3708 |
} |
3705 | 3709 |
} |
3710 |
|
|
3711 |
/** |
|
3712 |
* Reports whether the MetaCatServlet has been fully initialized |
|
3713 |
* |
|
3714 |
* @return true if fully intialized, false otherwise |
|
3715 |
*/ |
|
3716 |
public static boolean isFullyInitialized() { |
|
3717 |
return fullyInitialized; |
|
3718 |
} |
|
3706 | 3719 |
} |
Also available in: Unified diff
Separate the init function to pre-confiugured and post-configured methods. the initSecondHalf method allows for the intial configuration of metacat without a restart.