Project

General

Profile

1
/**
2
 *  '$RCSfile$'
3
 *    Purpose: A Class that implements a metadata catalog as a java Servlet
4
 *  Copyright: 2006 Regents of the University of California and the
5
 *             National Center for Ecological Analysis and Synthesis
6
 *    Authors: Matt Jones, Dan Higgins, Jivka Bojilova, Chad Berkley, Matthew Perry
7
 *
8
 *   '$Author: leinfelder $'
9
 *     '$Date: 2013-09-23 15:54:55 -0700 (Mon, 23 Sep 2013) $'
10
 * '$Revision: 8265 $'
11
 *
12
 * This program is free software; you can redistribute it and/or modify
13
 * it under the terms of the GNU General Public License as published by
14
 * the Free Software Foundation; either version 2 of the License, or
15
 * (at your option) any later version.
16
 *
17
 * This program is distributed in the hope that it will be useful,
18
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20
 * GNU General Public License for more details.
21
 *
22
 * You should have received a copy of the GNU General Public License
23
 * along with this program; if not, write to the Free Software
24
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
25
 */
26

    
27
package edu.ucsb.nceas.metacat;
28

    
29
import java.io.IOException;
30
import java.io.OutputStreamWriter;
31
import java.io.PrintWriter;
32
import java.io.Writer;
33
import java.sql.PreparedStatement;
34
import java.sql.ResultSet;
35
import java.sql.SQLException;
36
import java.sql.Timestamp;
37
import java.util.Enumeration;
38
import java.util.Hashtable;
39
import java.util.Timer;
40
import java.util.Vector;
41

    
42
import javax.servlet.ServletConfig;
43
import javax.servlet.ServletContext;
44
import javax.servlet.ServletException;
45
import javax.servlet.ServletOutputStream;
46
import javax.servlet.http.HttpServlet;
47
import javax.servlet.http.HttpServletRequest;
48
import javax.servlet.http.HttpServletResponse;
49
import javax.servlet.http.HttpSession;
50

    
51
import org.apache.log4j.Logger;
52
import org.apache.log4j.PropertyConfigurator;
53

    
54
import edu.ucsb.nceas.metacat.database.DBConnection;
55
import edu.ucsb.nceas.metacat.database.DBConnectionPool;
56
import edu.ucsb.nceas.metacat.database.DatabaseService;
57
import edu.ucsb.nceas.metacat.dataone.hazelcast.HazelcastService;
58
import edu.ucsb.nceas.metacat.plugin.MetacatHandlerPlugin;
59
import edu.ucsb.nceas.metacat.plugin.MetacatHandlerPluginManager;
60
import edu.ucsb.nceas.metacat.properties.PropertyService;
61
import edu.ucsb.nceas.metacat.properties.SkinPropertyService;
62
import edu.ucsb.nceas.metacat.replication.ReplicationService;
63
import edu.ucsb.nceas.metacat.service.ServiceService;
64
import edu.ucsb.nceas.metacat.service.SessionService;
65
import edu.ucsb.nceas.metacat.service.XMLSchemaService;
66
import edu.ucsb.nceas.metacat.shared.BaseException;
67
import edu.ucsb.nceas.metacat.shared.HandlerException;
68
import edu.ucsb.nceas.metacat.shared.MetacatUtilException;
69
import edu.ucsb.nceas.metacat.shared.ServiceException;
70
import edu.ucsb.nceas.metacat.spatial.SpatialHarvester;
71
import edu.ucsb.nceas.metacat.util.AuthUtil;
72
import edu.ucsb.nceas.metacat.util.ConfigurationUtil;
73
import edu.ucsb.nceas.metacat.util.DocumentUtil;
74
import edu.ucsb.nceas.metacat.util.ErrorSendingErrorException;
75
import edu.ucsb.nceas.metacat.util.RequestUtil;
76
import edu.ucsb.nceas.metacat.util.ResponseUtil;
77
import edu.ucsb.nceas.metacat.util.SessionData;
78
import edu.ucsb.nceas.metacat.util.SystemUtil;
79
import edu.ucsb.nceas.metacat.workflow.WorkflowSchedulerClient;
80
import edu.ucsb.nceas.utilities.FileUtil;
81
import edu.ucsb.nceas.utilities.GeneralPropertyException;
82
import edu.ucsb.nceas.utilities.PropertyNotFoundException;
83
import edu.ucsb.nceas.utilities.UtilException;
84

    
85
/**
86
 * A metadata catalog server implemented as a Java Servlet
87
 *
88
 * Valid actions are:
89
 * 
90
 * action=login
91
 *     username
92
 *     password
93
 *     qformat
94
 * action=logout
95
 *     qformat
96
 * action=query -- query the values of all elements and attributes and return a result set of nodes
97
 *     meta_file_id --
98
 *     returndoctype --
99
 *     filterdoctype --
100
 *     returnfield --
101
 *     owner --
102
 *     site --
103
 *     operator --
104
 *     casesensitive --
105
 *     searchmode --
106
 *     anyfield --
107
 * action=spatial_query -- run a spatial query.  these queries may include any of the
108
 *                         queries supported by the WFS / WMS standards
109
 *     xmax --
110
 *     ymax --
111
 *     xmin --
112
 *     ymin --
113
 *     skin --
114
 *     pagesize --
115
 *     pagestart --
116
 * action=squery -- structured query (see pathquery.dtd)
117
 *     query --
118
 *     pagesize --
119
 *     pagestart --
120
 * action=export -- export a zip format for data packadge
121
 *     docid -- 
122
 * action=read -- read any metadata/data file from Metacat and from Internet
123
 *     archiveEntryName --
124
 *     docid --
125
 *     qformat --
126
 *     metadatadocid --
127
 * action=readinlinedata -- read inline data only
128
 *     inlinedataid
129
 * action=insert -- insert an XML document into the database store
130
 *     qformat -- 
131
 *     docid --
132
 *     doctext --
133
 *     dtdtext --
134
 * action=insertmultipart -- insert an xml document into the database using multipart encoding
135
 *     qformat -- 
136
 *     docid --
137
 * action=update -- update an XML document that is in the database store
138
 *     qformat -- 
139
 *     docid --
140
 *     doctext --
141
 *     dtdtext --
142
 * action=delete -- delete an XML document from the database store
143
 *     docid --
144
 * action=validate -- validate the xml contained in valtext
145
 *     valtext --
146
 *     docid --
147
 * action=setaccess -- change access permissions for a user on a document.
148
 *     docid --
149
 *     principal --
150
 *     permission --
151
 *     permType --
152
 *     permOrder --
153
 * action=getaccesscontrol -- retrieve acl info for Metacat document
154
 *     docid -- 
155
 * action=getprincipals -- retrieve a list of principals in XML
156
 * action=getalldocids -- retrieves a list of all docids registered with the system
157
 *     scope --
158
 * action=getlastdocid --
159
 *     scope --
160
 *     username --
161
 * action=isregistered -- checks to see if the provided docid is registered
162
 *     docid --
163
 * action=getrevisionanddoctype -- get a document's revision and doctype from database 
164
 *     docid --
165
 * action=getversion -- 
166
 * action=getdoctypes -- retrieve all doctypes (publicID) 
167
 * action=getdtdschema -- retrieve a DTD or Schema file
168
 *     doctype --
169
 * action=getlog -- get a report of events that have occurred in the system
170
 *     ipAddress --  filter on one or more IP addresses>
171
 *     principal -- filter on one or more principals (LDAP DN syntax)
172
 *     docid -- filter on one or more document identifiers (with revision)
173
 *     event -- filter on event type (e.g., read, insert, update, delete)
174
 *     start -- filter out events before the start date-time
175
 *     end -- filter out events before the end date-time
176
 * action=getloggedinuserinfo -- get user info for the currently logged in user
177
 *     ipAddress --  filter on one or more IP addresses>
178
 *     principal -- filter on one or more principals (LDAP DN syntax)
179
 *     docid -- filter on one or more document identifiers (with revision)
180
 *     event -- filter on event type (e.g., read, insert, update, delete)
181
 *     start -- filter out events before the start date-time
182
 *     end -- filter out events before the end date-time
183
 * action=shrink -- Shrink the database connection pool size if it has grown and 
184
 *                  extra connections are no longer being used.
185
 * action=buildindex --
186
 *     docid --
187
 * action=refreshServices --
188
 * action=scheduleWorkflow -- Schedule a workflow to be run.  Scheduling a workflow 
189
 *                            registers it with the scheduling engine and creates a row
190
 *                            in the scheduled_job table.  Note that this may be 
191
 *                            extracted into a separate servlet.
192
 *     delay -- The amount of time from now before the workflow should be run.  The 
193
 *              delay can be expressed in number of seconds, minutes, hours and days, 
194
 *              for instance 30s, 2h, etc.
195
 *     starttime -- The time that the workflow should first run.  If both are provided
196
 *                  this takes precedence over delay.  The time should be expressed as: 
197
 *                  MM/dd/yyyy HH:mm:ss with the timezone assumed to be that of the OS.
198
 *     endtime -- The time when the workflow should end. The time should be expressed as: 
199
 *                  MM/dd/yyyy HH:mm:ss with the timezone assumed to be that of the OS.
200
 *     intervalvalue -- The numeric value of the interval between runs
201
 *     intervalunit -- The unit of the interval between runs.  Can be s, m, h, d for 
202
 *                     seconds, minutes, hours and days respectively
203
 *     workflowid -- The lsid of the workflow that we want to schedule.  This workflow
204
 *                   must already exist in the database.
205
 *     karid -- The karid for the workflow that we want to schedule.
206
 *     workflowname -- The name of the workflow.
207
 *     forwardto -- If provided, forward to this page when processing is done.
208
 *     qformat -- If provided, render results using the stylesheets associated with
209
 *                this skin.  Default is xml.
210
 * action=unscheduleWorkflow -- Unschedule a workflow.  Unscheduling a workflow 
211
 *                            removes it from the scheduling engine and changes the 
212
 *                            status in the scheduled_job table to " unscheduled.  Note 
213
 *                            that this may be extracted into a separate servlet.
214
 *     workflowjobname -- The job ID for the workflow run that we want to unschedule.  This
215
 *                      is held in the database as scheduled_job.name
216
 *     forwardto -- If provided, forward to this page when processing is done.
217
 *     qformat -- If provided, render results using the stylesheets associated with
218
 *                this skin.  Default is xml.
219
 * action=rescheduleWorkflow -- Unschedule a workflow.  Rescheduling a workflow 
220
 *                            registers it with the scheduling engine and changes the 
221
 *                            status in the scheduled_job table to " scheduled.  Note 
222
 *                            that this may be extracted into a separate servlet.
223
 *     workflowjobname -- The job ID for the workflow run that we want to reschedule.  This
224
 *                      is held in the database as scheduled_job.name
225
 *     forwardto -- If provided, forward to this page when processing is done.
226
 *     qformat -- If provided, render results using the stylesheets associated with
227
 *                this skin.  Default is xml.
228
 * action=deleteScheduledWorkflow -- Delete a workflow.  Deleting a workflow 
229
 *                            removes it from the scheduling engine and changes the 
230
 *                            status in the scheduled_job table to " deleted.  Note 
231
 *                            that this may be extracted into a separate servlet.
232
 *     workflowjobname -- The job ID for the workflow run that we want to delete.  This
233
 *                      is held in the database as scheduled_job.name
234
 *     forwardto -- If provided, forward to this page when processing is done.
235
 *     qformat -- If provided, render results using the stylesheets associated with
236
 *                this skin.  Default is xml.
237
 *     
238
 *     
239
 * Here are some of the common parameters for actions
240
 *     doctype -- document type list returned by the query (publicID) 
241
 *     qformat=xml -- display resultset from query in XML 
242
 *     qformat=html -- display resultset from query in HTML 
243
 *     qformat=zip -- zip resultset from query
244
 *     docid=34 -- display the document with the document ID number 34 
245
 *     doctext -- XML text of the document to load into the database 
246
 *     acltext -- XML access text for a document to load into the database 
247
 *     dtdtext -- XML DTD text for a new DTD to load into Metacat XML Catalog 
248
 *     query -- actual query text (to go with 'action=query' or 'action=squery')
249
 *     valtext -- XML text to be validated 
250
 *     scope --can limit the query by the scope of the id
251
 *     docid --the docid to check
252
 *     datadoc -- data document name (id)
253
 */
254
public class MetaCatServlet extends HttpServlet {
255

    
256
	private static final long serialVersionUID = 1L;
257
	private Timer timer = null;
258
    private static boolean _firstHalfInitialized = false;
259
    private static boolean _fullyInitialized = false;
260
    private MetacatHandler handler = null;
261
    
262
    // Constants -- these should be final in a servlet
263
    public static final String SCHEMALOCATIONKEYWORD = ":schemaLocation";
264
    public static final String NONAMESPACELOCATION = ":noNamespaceSchemaLocation";
265
    public static final String EML2KEYWORD = ":eml";
266
    private static final String FALSE = "false";
267
    private static final String TRUE  = "true";
268
    private static String LOG_CONFIG_NAME = null;
269
    public static final String APPLICATION_NAME = "metacat";
270
	public static final String DEFAULT_ENCODING = "UTF-8";
271
    
272
    /**
273
     * Initialize the servlet by creating appropriate database connections
274
     */
275
    public void init(ServletConfig config) throws ServletException {
276
    	Logger logMetacat = Logger.getLogger(MetaCatServlet.class);
277
    	try {
278
    		if(_firstHalfInitialized) {
279
    			return;
280
    		}
281
    		
282
            super.init(config);
283
            
284
            ServletContext context = config.getServletContext();
285
            context.setAttribute("APPLICATION_NAME", APPLICATION_NAME);
286
            
287
            ServiceService serviceService = ServiceService.getInstance(context);
288
            logMetacat.debug("MetaCatServlet.init - ServiceService singleton created " + serviceService);
289
            
290
            // Initialize the properties file
291
            String dirPath = ServiceService.getRealConfigDir();
292
            
293
            LOG_CONFIG_NAME = dirPath + "/log4j.properties";
294
            PropertyConfigurator.configureAndWatch(LOG_CONFIG_NAME);
295
            
296
            // Register preliminary services
297
            ServiceService.registerService("PropertyService", PropertyService.getInstance(context));         
298
            ServiceService.registerService("SkinPropertyService", SkinPropertyService.getInstance());
299
            ServiceService.registerService("SessionService", SessionService.getInstance()); 
300
    		
301
            // Check to see if the user has requested to bypass configuration 
302
            // (dev option) and check see if metacat has been configured.
303
    		// If both are false then stop the initialization
304
            if (!ConfigurationUtil.bypassConfiguration() && !ConfigurationUtil.isMetacatConfigured()) {
305
            	return;
306
            }  
307
            
308
            _firstHalfInitialized = true;
309
            
310
            initSecondHalf(context);
311
            
312
    	} catch (ServiceException se) {
313
        	String errorMessage = 
314
        		"Service problem while intializing MetaCat Servlet: " + se.getMessage();
315
            logMetacat.error("MetaCatServlet.init - " + errorMessage);
316
            throw new ServletException(errorMessage);
317
        } catch (MetacatUtilException mue) {
318
        	String errorMessage = "Metacat utility problem while intializing MetaCat Servlet: " 
319
        		+ mue.getMessage();
320
            logMetacat.error("MetaCatServlet.init - " + errorMessage);
321
            throw new ServletException(errorMessage);
322
        } 
323
    }
324

    
325
            
326
	/**
327
	 * Initialize the remainder of the servlet. This is the part that can only
328
	 * be initialized after metacat properties have been configured
329
	 * 
330
	 * @param context
331
	 *            the servlet context of MetaCatServlet
332
	 */
333
	public void initSecondHalf(ServletContext context) throws ServletException {
334
		
335
		Logger logMetacat = Logger.getLogger(MetaCatServlet.class);
336

    
337
		try {			
338
			ServiceService.registerService("DatabaseService", DatabaseService.getInstance());
339
			
340
			// initialize DBConnection pool
341
			DBConnectionPool connPool = DBConnectionPool.getInstance();
342
			logMetacat.debug("MetaCatServlet.initSecondHalf - DBConnection pool initialized: " + connPool.toString());
343
			
344
			// register the XML schema service
345
			ServiceService.registerService("XMLSchemaService", XMLSchemaService.getInstance());
346
			
347
			// check if eml201 document were corrected or not. if not, correct eml201 documents.
348
			// Before Metacat 1.8.1, metacat uses tag RELEASE_EML_2_0_1_UPDATE_6 as eml
349
			// schema, which accidentily points to wrong version of eml-resource.xsd.
350
			String correctedEML201Doc = PropertyService.getProperty("document.eml201DocumentCorrected");
351
			if (correctedEML201Doc != null && correctedEML201Doc.equals(FALSE)) {
352
				logMetacat.info("MetaCatServlet.initSecondHalf - Start to correct eml201 documents");
353
				EML201DocumentCorrector correct = new EML201DocumentCorrector();
354
				boolean success = correct.run();
355
				if (success) {
356
					PropertyService.setProperty("document.eml201DocumentCorrected", TRUE);
357
				}
358
				logMetacat.info("MetaCatServlet.initSecondHalf - Finish to correct eml201 documents");
359
			}
360

    
361
			// Index the paths specified in the metacat.properties
362
			checkIndexPaths();
363

    
364
			// initiate the indexing Queue
365
			IndexingQueue.getInstance();
366

    
367
			// start the IndexingThread if indexingTimerTaskTime more than 0.
368
			// It will index all the documents not yet indexed in the database
369
			int indexingTimerTaskTime = Integer.parseInt(PropertyService
370
					.getProperty("database.indexingTimerTaskTime"));
371
			int delayTime = Integer.parseInt(PropertyService
372
					.getProperty("database.indexingInitialDelay"));
373

    
374
			if (indexingTimerTaskTime > 0) {
375
				timer = new Timer();
376
				timer.schedule(new IndexingTimerTask(), delayTime, indexingTimerTaskTime);
377
			}
378
			
379
			/*
380
			 * If spatial option is turned on and set to regenerate the spatial
381
			 * cache on restart, trigger the harvester regeneratation method
382
			 */
383
			if (PropertyService.getProperty("spatial.runSpatialOption").equals("true") && 
384
					PropertyService.getProperty("spatial.regenerateCacheOnRestart").equals("true")) {
385

    
386
				// Begin timer
387
				long before = System.currentTimeMillis();
388

    
389
				// if either the point or polygon shape files do not exist, then regenerate the entire spatial cache
390
				// this may be expensive with many documents		
391
				SpatialHarvester sh = new SpatialHarvester();
392
				sh.regenerate();
393
				sh.destroy();
394

    
395
				// After running the first time, we want to to set
396
				// regenerateCacheOnRestart to false
397
				// so that it does not regenerate the cache every time tomcat is
398
				// restarted
399
				PropertyService.setProperty("spatial.regenerateCacheOnRestart", "false");
400

    
401
				// End timer
402
				long after = System.currentTimeMillis();
403
				logMetacat.info("MetaCatServlet.initSecondHalf - Spatial Harvester Time  " 
404
						+ (after - before) + "ms");
405

    
406
			} else {
407
				logMetacat.info("MetaCatServlet.initSecondHalf - Spatial cache is not set to regenerate on restart");
408
			}
409
		
410
			// Set up the replication log file by setting the "replication.logfile.name" 
411
			// system property and reconfiguring the log4j property configurator.
412
			String replicationLogPath = PropertyService.getProperty("replication.logdir") 
413
				+ FileUtil.getFS() + ReplicationService.REPLICATION_LOG_FILE_NAME;				
414
			
415
			if (FileUtil.getFileStatus(replicationLogPath) == FileUtil.DOES_NOT_EXIST) {
416
				FileUtil.createFile(replicationLogPath);
417
			}
418

    
419
			if (FileUtil.getFileStatus(replicationLogPath) < FileUtil.EXISTS_READ_WRITABLE) {
420
				logMetacat.error("MetaCatServlet.initSecondHalf - Replication log file: " + replicationLogPath 
421
						+ " does not exist read/writable.");
422
			}
423
			
424
			System.setProperty("replication.logfile.name", replicationLogPath);			
425
			PropertyConfigurator.configureAndWatch(LOG_CONFIG_NAME);
426
			
427
			SessionService.getInstance().unRegisterAllSessions();
428
			
429
	         //Initialize Metacat Handler
430
            handler = new MetacatHandler(timer);
431

    
432
			handler.set_sitemapScheduled(false);
433
			
434
			// initialize the plugins
435
			MetacatHandlerPluginManager.getInstance();
436
			
437
			// initialize the HazelcastService
438
			ServiceService.registerService("HazelcastService", HazelcastService.getInstance());
439

    
440
			_fullyInitialized = true;
441
			
442
			logMetacat.warn("MetaCatServlet.initSecondHalf - Metacat (" + MetacatVersion.getVersionID()
443
					+ ") initialized.");
444
			
445
		} catch (SQLException e) {
446
			String errorMessage = "SQL problem while intializing MetaCat Servlet: "
447
					+ e.getMessage();
448
			logMetacat.error("MetaCatServlet.initSecondHalf - " + errorMessage);
449
			throw new ServletException(errorMessage);
450
		} catch (IOException ie) {
451
			String errorMessage = "IO problem while intializing MetaCat Servlet: "
452
					+ ie.getMessage();
453
			logMetacat.error("MetaCatServlet.initSecondHalf - " + errorMessage);
454
			throw new ServletException(errorMessage);
455
		} catch (GeneralPropertyException gpe) {
456
			String errorMessage = "Could not retrieve property while intializing MetaCat Servlet: "
457
					+ gpe.getMessage();
458
			logMetacat.error("MetaCatServlet.initSecondHalf - " + errorMessage);
459
			throw new ServletException(errorMessage);
460
		} catch (ServiceException se) {
461
			String errorMessage = "Service problem while intializing MetaCat Servlet: "
462
				+ se.getMessage();
463
			logMetacat.error("MetaCatServlet.initSecondHalf - " + errorMessage);
464
			throw new ServletException(errorMessage);
465
		} catch (UtilException ue) {
466
        	String errorMessage = "Utility problem while intializing MetaCat Servlet: " 
467
        		+ ue.getMessage();
468
            logMetacat.error("MetaCatServlet.initSecondHalf - " + errorMessage);
469
            throw new ServletException(errorMessage);
470
        } 
471
	}
472
    
473
    /**
474
	 * Close all db connections from the pool
475
	 */
476
    public void destroy() {
477
    	Logger logMetacat = Logger.getLogger(MetaCatServlet.class);
478
    	
479
    	ServiceService.stopAllServices();
480
    	
481
        // Close all db connection
482
        logMetacat.warn("MetaCatServlet.destroy - Destroying MetacatServlet");
483
        timer.cancel();
484
        IndexingQueue.getInstance().setMetacatRunning(false);
485
        DBConnectionPool.release();
486
    }
487
    
488
    /** Handle "GET" method requests from HTTP clients */
489
    public void doGet(HttpServletRequest request, HttpServletResponse response)
490
    throws ServletException, IOException {
491
        
492
        // Process the data and send back the response
493
        handleGetOrPost(request, response);
494
    }
495
    
496
    /** Handle "POST" method requests from HTTP clients */
497
    public void doPost(HttpServletRequest request, HttpServletResponse response)
498
    throws ServletException, IOException {
499
        
500
        // Process the data and send back the response
501
        handleGetOrPost(request, response);
502
    }
503
    
504
    /**
505
	 * Index the paths specified in the metacat.properties
506
	 */
507
    private void checkIndexPaths() {
508
        Logger logMetacat = Logger.getLogger(MetaCatServlet.class);
509

    
510
        Vector<String> pathsForIndexing = null;
511
        try {  
512
        	pathsForIndexing = SystemUtil.getPathsForIndexing();
513
        }
514
        catch (MetacatUtilException ue) {
515
        	pathsForIndexing = null;
516
            logMetacat.error("MetaCatServlet.checkIndexPaths - not find index paths.  Setting " 
517
            		+ "pathsForIndexing to null: " + ue.getMessage());
518
        }
519
        
520
        if (pathsForIndexing != null && !pathsForIndexing.isEmpty()) {
521
            
522
            logMetacat.debug("MetaCatServlet.checkIndexPaths - Indexing paths specified in metacat.properties....");
523
            
524
            DBConnection conn = null;
525
            int serialNumber = -1;
526
            PreparedStatement pstmt = null;
527
            PreparedStatement pstmt1 = null;
528
            ResultSet rs = null;
529
            
530
            for (String pathIndex : pathsForIndexing) {
531
                logMetacat.debug("MetaCatServlet.checkIndexPaths - Checking if '" + pathIndex  + "' is indexed.... ");
532
                
533
                try {
534
                    //check out DBConnection
535
                    conn = DBConnectionPool.
536
                            getDBConnection("MetaCatServlet.checkIndexPaths");
537
                    serialNumber = conn.getCheckOutSerialNumber();
538
                    
539
                    pstmt = conn.prepareStatement(
540
                            "SELECT * FROM xml_path_index " + "WHERE path = ?");
541
                    pstmt.setString(1, pathIndex);
542
                    
543
                    pstmt.execute();
544
                    rs = pstmt.getResultSet();
545
                    
546
                    if (!rs.next()) {
547
                        logMetacat.debug("MetaCatServlet.checkIndexPaths - not indexed yet.");
548
                        rs.close();
549
                        pstmt.close();
550
                        conn.increaseUsageCount(1);
551
                        
552
                        logMetacat.debug("MetaCatServlet.checkIndexPaths - Inserting following path in xml_path_index: "
553
                                + pathIndex);
554
                        if(pathIndex.indexOf("@")<0){
555
                            pstmt = conn.prepareStatement("SELECT DISTINCT n.docid, "
556
                                    + "n.nodedata, n.nodedatanumerical, n.nodedatadate, n.parentnodeid"
557
                                    + " FROM xml_nodes n, xml_index i WHERE"
558
                                    + " i.path = ? and n.parentnodeid=i.nodeid and"
559
                                    + " n.nodetype LIKE 'TEXT' order by n.parentnodeid");
560
                        } else {
561
                            pstmt = conn.prepareStatement("SELECT DISTINCT n.docid, "
562
                                    + "n.nodedata, n.nodedatanumerical, n.nodedatadate, n.parentnodeid"
563
                                    + " FROM xml_nodes n, xml_index i WHERE"
564
                                    + " i.path = ? and n.nodeid=i.nodeid and"
565
                                    + " n.nodetype LIKE 'ATTRIBUTE' order by n.parentnodeid");
566
                        }
567
                        pstmt.setString(1, pathIndex);
568
                        pstmt.execute();
569
                        rs = pstmt.getResultSet();
570
                        
571
                        int count = 0;
572
                        logMetacat.debug("MetaCatServlet.checkIndexPaths - Executed the select statement for: "
573
                                + pathIndex);
574
                        
575
                        try {
576
                            while (rs.next()) {
577
                                
578
                                String docid = rs.getString(1);
579
                                String nodedata = rs.getString(2);
580
                                float nodedatanumerical = rs.getFloat(3);
581
                                Timestamp nodedatadate = rs.getTimestamp(4);
582
                                int parentnodeid = rs.getInt(5);
583
                                
584
                                if (!nodedata.trim().equals("")) {
585
                                    pstmt1 = conn.prepareStatement(
586
                                            "INSERT INTO xml_path_index"
587
                                            + " (docid, path, nodedata, "
588
                                            + "nodedatanumerical, nodedatadate, parentnodeid)"
589
                                            + " VALUES (?, ?, ?, ?, ?, ?)");
590
                                    
591
                                    pstmt1.setString(1, docid);
592
                                    pstmt1.setString(2, pathIndex);
593
                                    pstmt1.setString(3, nodedata);
594
                                    pstmt1.setFloat(4, nodedatanumerical);
595
                                    pstmt1.setTimestamp(5, nodedatadate);
596
                                    pstmt1.setInt(6, parentnodeid);
597
                                    
598
                                    pstmt1.execute();
599
                                    pstmt1.close();
600
                                    
601
                                    count++;
602
                                    
603
                                }
604
                            }
605
                        } catch (Exception e) {
606
                            logMetacat.error("MetaCatServlet.checkIndexPaths - Exception:" + e.getMessage());
607
                            e.printStackTrace();
608
                        }
609
                        
610
                        rs.close();
611
                        pstmt.close();
612
                        conn.increaseUsageCount(1);
613
                        
614
                        logMetacat.info("MetaCatServlet.checkIndexPaths - Indexed " + count + " records from xml_nodes for '"
615
                                + pathIndex + "'");
616
                        
617
                    } else {
618
                        logMetacat.debug("MetaCatServlet.checkIndexPaths - already indexed.");
619
                    }
620
                    
621
                    rs.close();
622
                    pstmt.close();
623
                    conn.increaseUsageCount(1);
624
                    
625
                } catch (Exception e) {
626
                    logMetacat.error("MetaCatServlet.checkIndexPaths - Error in MetaCatServlet.checkIndexPaths: "
627
                            + e.getMessage());
628
                }finally {
629
                    //check in DBonnection
630
                    DBConnectionPool.returnDBConnection(conn, serialNumber);
631
                }
632
                
633
                
634
            }
635
            
636
            logMetacat.debug("MetaCatServlet.checkIndexPaths - Path Indexing Completed");
637
        }
638
    }
639
    
640
    /**
641
	 * Control servlet response depending on the action parameter specified
642
	 */
643
	@SuppressWarnings("unchecked")
644
	private void handleGetOrPost(HttpServletRequest request,
645
			HttpServletResponse response) throws ServletException, IOException {
646
		Logger logMetacat = Logger.getLogger(MetaCatServlet.class);
647

    
648
		String requestEncoding = request.getCharacterEncoding();
649
		if (requestEncoding == null) {
650
			logMetacat.debug("null requestEncoding, setting to application default: " + DEFAULT_ENCODING);
651
			request.setCharacterEncoding(DEFAULT_ENCODING);
652
		}
653
		logMetacat.debug("requestEncoding: " + requestEncoding);
654
		
655
		// Update the last update time for this user if they are not new
656
		HttpSession httpSession = request.getSession(false);
657
		if (httpSession != null) {
658
		    SessionService.getInstance().touchSession(httpSession.getId());
659
		}
660
		
661
		// Each time metacat is called, check to see if metacat has been 
662
		// configured. If not then forward to the administration servlet
663
		if (!ConfigurationUtil.isMetacatConfigured()) {
664
			try {
665
				RequestUtil.forwardRequest(request, response, "/admin?action=configure", null);
666
				return;
667
			} catch (MetacatUtilException mue) {
668
				logMetacat.error("MetacatServlet.handleGetOrPost - utility error when forwarding to " + 
669
						"configuration screen: " + mue.getMessage());
670
				throw new ServletException("MetacatServlet.handleGetOrPost - utility error when forwarding to " + 
671
						"configuration screen: " + mue.getMessage());
672
			}
673
		}
674

    
675
		// if we get here, metacat is configured.  If we have not completed the 
676
		// second half of the initialization, do so now.  This allows us to initially
677
		// configure metacat without a restart.
678
		if (!_fullyInitialized) {
679
			initSecondHalf(request.getSession().getServletContext());
680
		}
681
		
682
		/*
683
		 * logMetacat.debug("Connection pool size: "
684
		 * +connPool.getSizeOfDBConnectionPool(),10); logMetacat.debug("Free
685
		 * DBConnection number: "
686
		 */
687
		// If all DBConnection in the pool are free and DBConnection pool
688
		// size is greater than initial value, shrink the connection pool
689
		// size to initial value
690
		DBConnectionPool.shrinkDBConnectionPoolSize();
691

    
692
		// Debug message to print out the method which have a busy DBConnection
693
		try {
694
			@SuppressWarnings("unused")
695
			DBConnectionPool pool = DBConnectionPool.getInstance();
696
//			pool.printMethodNameHavingBusyDBConnection();
697
		} catch (SQLException e) {
698
			logMetacat.error("MetaCatServlet.handleGetOrPost - Error in MetacatServlet.handleGetOrPost: " + e.getMessage());
699
			e.printStackTrace();
700
		}
701

    
702
		try {
703
			String ctype = request.getContentType();
704
			
705
			if (ctype != null && ctype.startsWith("multipart/form-data")) {
706
				handler.handleMultipartForm(request, response);
707
				return;
708
			} 
709

    
710
			String name = null;
711
			String[] value = null;
712
			String[] docid = new String[3];
713
			Hashtable<String, String[]> params = new Hashtable<String, String[]>();
714

    
715
			// Check if this is a simple read request that doesn't use the
716
			// "action" syntax
717
			// These URLs are of the form:
718
			// http://localhost:8180/metacat/metacat/docid/skinname
719
			// e.g., http://localhost:8180/metacat/metacat/test.1.1/knb
720
			String pathInfo = request.getPathInfo();
721
			if (pathInfo != null) {
722
				String[] path = pathInfo.split("/");
723
				if (path.length > 1) {
724
					String docidToRead = path[1];
725
					String docs[] = new String[1];
726
					docs[0] = docidToRead;
727
					logMetacat.debug("MetaCatServlet.handleGetOrPost - READING DOCID FROM PATHINFO: " + docs[0]);
728
					params.put("docid", docs);
729
					String skin = null;
730
					if (path.length > 2) {
731
						skin = path[2];
732
						String skins[] = new String[1];
733
						skins[0] = skin;
734
						params.put("qformat", skins);
735
					}
736
					handler.handleReadAction(params, request, response, "public", null, null);
737
					return;
738
				}
739
			}
740

    
741
			Enumeration<String> paramlist = 
742
				(Enumeration<String>) request.getParameterNames();
743
			while (paramlist.hasMoreElements()) {
744

    
745
				name = paramlist.nextElement();
746
				value = request.getParameterValues(name);
747

    
748
				// Decode the docid and mouse click information
749
				// THIS IS OBSOLETE -- I THINK -- REMOVE THIS BLOCK
750
				// 4/12/2007d
751
				// MBJ
752
				if (name.endsWith(".y")) {
753
					docid[0] = name.substring(0, name.length() - 2);
754
					params.put("docid", docid);
755
					name = "ypos";
756
				}
757
				if (name.endsWith(".x")) {
758
					name = "xpos";
759
				}
760

    
761
				params.put(name, value);
762
			}
763

    
764
			// handle param is emptpy
765
			if (params.isEmpty() || params == null) {
766
				return;
767
			}
768

    
769
			// if the user clicked on the input images, decode which image
770
			// was clicked then set the action.
771
			if (params.get("action") == null) {
772
				PrintWriter out = response.getWriter();
773
				response.setContentType("text/xml");
774
				out.println("<?xml version=\"1.0\"?>");
775
				out.println("<error>");
776
				out.println("Action not specified");
777
				out.println("</error>");
778
				out.close();
779
				return;
780
			}
781

    
782
			String action = (params.get("action"))[0];
783
			logMetacat.info("MetaCatServlet.handleGetOrPost - Action is: " + action);
784

    
785
			// This block handles session management for the servlet
786
			// by looking up the current session information for all actions
787
			// other than "login" and "logout"
788
			String userName = null;
789
			String password = null;
790
			String[] groupNames = null;
791
			String sessionId = null;
792
			name = null;
793

    
794
			// handle login action
795
			if (action.equals("login")) {
796
				PrintWriter out = response.getWriter();
797
				handler.handleLoginAction(out, params, request, response);
798
				out.close();
799

    
800
				// handle logout action
801
			} else if (action.equals("logout")) {
802
				PrintWriter out = response.getWriter();
803
				handler.handleLogoutAction(out, params, request, response);
804
				out.close();
805

    
806
				// handle shrink DBConnection request
807
			} else if (action.equals("validatesession")) {
808
				PrintWriter out = response.getWriter();
809
				String idToValidate = null;
810
				String idsToValidate[] = params.get("sessionid");
811
				if (idsToValidate != null) {
812
					idToValidate = idsToValidate[0];
813
				} else {
814
					// use the sessionid from the cookie
815
					SessionData sessionData = RequestUtil.getSessionData(request);
816
					if (sessionData != null) {
817
						idToValidate = sessionData.getId();
818
					}
819
				}
820
				SessionService.getInstance().validateSession(out, response, idToValidate);
821
				out.close();
822

    
823
				// handle shrink DBConnection request
824
			} else if (action.equals("shrink")) {
825
				PrintWriter out = response.getWriter();
826
				boolean success = false;
827
				// If all DBConnection in the pool are free and DBConnection
828
				// pool
829
				// size is greater than initial value, shrink the connection
830
				// pool
831
				// size to initial value
832
				success = DBConnectionPool.shrinkConnectionPoolSize();
833
				if (success) {
834
					// if successfully shrink the pool size to initial value
835
					out.println("DBConnection Pool shrunk successfully.");
836
				}// if
837
				else {
838
					out.println("DBConnection pool not shrunk successfully.");
839
				}
840
				// close out put
841
				out.close();
842

    
843
				// aware of session expiration on every request
844
			} else {
845
				SessionData sessionData = RequestUtil.getSessionData(request);
846
				
847
				if (sessionData != null) {
848
					userName = sessionData.getUserName();
849
					password = sessionData.getPassword();
850
					groupNames = sessionData.getGroupNames();
851
					sessionId = sessionData.getId();
852
				}
853

    
854
				logMetacat.info("MetaCatServlet.handleGetOrPost - The user is : " + userName);
855
			}
856
			// Now that we know the session is valid, we can delegate the
857
			// request to a particular action handler
858
			if (action.equals("query")) {
859
		        Writer out = new OutputStreamWriter(response.getOutputStream(), DEFAULT_ENCODING);
860
				handler.handleQuery(out, params, response, userName, groupNames, sessionId);
861
				out.close();
862
			} else if (action.equals("squery")) {
863
				Writer out = new OutputStreamWriter(response.getOutputStream(), DEFAULT_ENCODING);
864
				if (params.containsKey("query")) {
865
					handler.handleSQuery(out, params, response, userName, groupNames, sessionId);
866
					out.close();
867
				} else {
868
					out.write("Illegal action squery without \"query\" parameter");
869
					out.close();
870
				}
871
			} else if (action.trim().equals("spatial_query")) {
872

    
873
				logMetacat
874
						.debug("MetaCatServlet.handleGetOrPost - ******************* SPATIAL QUERY ********************");
875
				Writer out = new OutputStreamWriter(response.getOutputStream(), DEFAULT_ENCODING);
876
				handler.handleSpatialQuery(out, params, response, userName, groupNames, sessionId);
877
				out.close();
878

    
879
			} else if (action.trim().equals("dataquery")) {
880

    
881
				logMetacat.debug("MetaCatServlet.handleGetOrPost - ******************* DATA QUERY ********************");
882
				handler.handleDataquery(params, response, sessionId);
883
			} else if (action.trim().equals("editcart")) {
884
				logMetacat.debug("MetaCatServlet.handleGetOrPost - ******************* EDIT CART ********************");
885
				handler.handleEditCart(params, response, sessionId);
886
			} else if (action.equals("export")) {
887

    
888
				handler.handleExportAction(params, response, userName, groupNames, password);
889
			} else if (action.equals("read")) {
890
				if (params.get("archiveEntryName") != null) {
891
					ArchiveHandler.getInstance().readArchiveEntry(params, request,
892
							response, userName, password, groupNames);
893
				} else {
894
					handler.handleReadAction(params, request, response, userName, password,
895
							groupNames);
896
				}
897
			} else if (action.equals("readinlinedata")) {
898
				handler.handleReadInlineDataAction(params, request, response, userName, password,
899
						groupNames);
900
			} else if (action.equals("insert") || action.equals("update")) {
901
				PrintWriter out = response.getWriter();
902
				if ((userName != null) && !userName.equals("public")) {
903
					handler.handleInsertOrUpdateAction(request.getRemoteAddr(), request.getHeader("User-Agent"), response, out, params, userName,
904
							groupNames, true, true);
905
				} else {
906
					response.setContentType("text/xml");
907
					out.println("<?xml version=\"1.0\"?>");
908
					out.println("<error>");
909
					out.println("Permission denied for user " + userName + " " + action);
910
					out.println("</error>");
911
				}
912
				out.close();
913
			} else if (action.equals("delete")) {
914
				PrintWriter out = response.getWriter();
915
				if ((userName != null) && !userName.equals("public")) {
916
					handler.handleDeleteAction(out, params, request, response, userName,
917
							groupNames);
918
				} else {
919
					response.setContentType("text/xml");
920
					out.println("<?xml version=\"1.0\"?>");
921
					out.println("<error>");
922
					out.println("Permission denied for " + action);
923
					out.println("</error>");
924
				}
925
				out.close();
926
			} else if (action.equals("validate")) {
927
				PrintWriter out = response.getWriter();
928
				handler.handleValidateAction(out, params);
929
				out.close();
930
			} else if (action.equals("setaccess")) {
931
				PrintWriter out = response.getWriter();
932
				handler.handleSetAccessAction(out, params, userName, request, response);
933
				out.close();
934
			} else if (action.equals("getaccesscontrol")) {
935
				PrintWriter out = response.getWriter();
936
				handler.handleGetAccessControlAction(out, params, response, userName, groupNames);
937
				out.close();
938
			} else if (action.equals("isauthorized")) {
939
				PrintWriter out = response.getWriter();
940
				DocumentUtil.isAuthorized(out, params, request, response);
941
				out.close();
942
			} else if (action.equals("getprincipals")) {
943
				PrintWriter out = response.getWriter();
944
				handler.handleGetPrincipalsAction(out, userName, password);
945
				out.close();
946
			} else if (action.equals("getdoctypes")) {
947
				PrintWriter out = response.getWriter();
948
				handler.handleGetDoctypesAction(out, params, response);
949
				out.close();
950
			} else if (action.equals("getdtdschema")) {
951
				PrintWriter out = response.getWriter();
952
				handler.handleGetDTDSchemaAction(out, params, response);
953
				out.close();
954
			} else if (action.equals("getdocid")) {
955
				handler.handleGetDocid(params, response);
956
			} else if (action.equals("getlastdocid")) {
957
				PrintWriter out = response.getWriter();
958
				handler.handleGetMaxDocidAction(out, params, response);
959
				out.close();
960
			} else if (action.equals("getalldocids")) {
961
				PrintWriter out = response.getWriter();
962
				handler.handleGetAllDocidsAction(out, params, response);
963
				out.close();
964
			} else if (action.equals("isregistered")) {
965
				PrintWriter out = response.getWriter();
966
				handler.handleIdIsRegisteredAction(out, params, response);
967
				out.close();
968
			} else if (action.equals("getrevisionanddoctype")) {
969
				PrintWriter out = response.getWriter();
970
				handler.handleGetRevisionAndDocTypeAction(out, params);
971
				out.close();
972
			} else if (action.equals("getversion")) {
973
				response.setContentType("text/xml");
974
				PrintWriter out = response.getWriter();
975
				out.println(MetacatVersion.getVersionAsXml());
976
				out.close();
977
			} else if (action.equals("getlog")) {
978
				handler.handleGetLogAction(params, request, response, userName, groupNames, sessionId);
979
			} else if (action.equals("getloggedinuserinfo")) {
980
				PrintWriter out = response.getWriter();
981
				response.setContentType("text/xml");
982
				out.println("<?xml version=\"1.0\"?>");
983
				out.println("\n<user>\n");
984
				out.println("\n<username>\n");
985
				out.println(userName);
986
				out.println("\n</username>\n");
987
				if (name != null) {
988
					out.println("\n<name>\n");
989
					out.println(name);
990
					out.println("\n</name>\n");
991
				}
992
				if (AuthUtil.isAdministrator(userName, groupNames)) {
993
					out.println("<isAdministrator></isAdministrator>\n");
994
				}
995
				if (AuthUtil.isModerator(userName, groupNames)) {
996
					out.println("<isModerator></isModerator>\n");
997
				}
998
				out.println("\n</user>\n");
999
				out.close();
1000
			} else if (action.equals("buildindex")) {
1001
				handler.handleBuildIndexAction(params, request, response, userName, groupNames);
1002
			} else if (action.equals("reindex")) {
1003
				handler.handleReindexAction(params, request, response, userName, groupNames);
1004
			} else if (action.equals("login") || action.equals("logout")) {
1005
				/*
1006
				 * } else if (action.equals("protocoltest")) { String testURL =
1007
				 * "metacat://dev.nceas.ucsb.edu/NCEAS.897766.9"; try { testURL =
1008
				 * ((String[]) params.get("url"))[0]; } catch (Throwable t) { }
1009
				 * String phandler = System
1010
				 * .getProperty("java.protocol.handler.pkgs");
1011
				 * response.setContentType("text/html"); PrintWriter out =
1012
				 * response.getWriter(); out.println("<body
1013
				 * bgcolor=\"white\">"); out.println("<p>Handler property:
1014
				 * <code>" + phandler + "</code></p>"); out.println("<p>Starting
1015
				 * test for:<br>"); out.println(" " + testURL + "</p>"); try {
1016
				 * URL u = new URL(testURL); out.println("<pre>");
1017
				 * out.println("Protocol: " + u.getProtocol()); out.println("
1018
				 * Host: " + u.getHost()); out.println(" Port: " + u.getPort());
1019
				 * out.println(" Path: " + u.getPath()); out.println(" Ref: " +
1020
				 * u.getRef()); String pquery = u.getQuery(); out.println("
1021
				 * Query: " + pquery); out.println(" Params: "); if (pquery !=
1022
				 * null) { Hashtable qparams =
1023
				 * MetacatUtil.parseQuery(u.getQuery()); for (Enumeration en =
1024
				 * qparams.keys(); en .hasMoreElements();) { String pname =
1025
				 * (String) en.nextElement(); String pvalue = (String)
1026
				 * qparams.get(pname); out.println(" " + pname + ": " + pvalue); } }
1027
				 * out.println("</pre>"); out.println("</body>");
1028
				 * out.close(); } catch (MalformedURLException mue) {
1029
				 * System.out.println( "bad url from
1030
				 * MetacatServlet.handleGetOrPost");
1031
				 * out.println(mue.getMessage()); mue.printStackTrace(out);
1032
				 * out.close(); }
1033
				 */
1034
			} else if (action.equals("refreshServices")) {
1035
				// TODO MCD this interface is for testing. It should go through
1036
				// a ServiceService class and only work for an admin user. Move 
1037
				// to the MetacatAdminServlet
1038
				ServiceService.refreshService("XMLSchemaService");
1039
				return;
1040
			} else if (action.equals("scheduleWorkflow")) {
1041
				try {
1042
					WorkflowSchedulerClient.getInstance().scheduleJob(request, response,
1043
							params, userName, groupNames);
1044
					return;
1045
				} catch (BaseException be) {
1046
					ResponseUtil.sendErrorXML(response,
1047
							ResponseUtil.SCHEDULE_WORKFLOW_ERROR, be);
1048
					return;
1049
				}
1050
			} else if (action.equals("unscheduleWorkflow")) {
1051
				try {
1052
					WorkflowSchedulerClient.getInstance().unScheduleJob(request,
1053
							response, params, userName, groupNames);
1054
					return;
1055
				} catch (BaseException be) {
1056
					ResponseUtil.sendErrorXML(response,
1057
							ResponseUtil.UNSCHEDULE_WORKFLOW_ERROR, be);
1058
					return;
1059
				}
1060
			} else if (action.equals("rescheduleWorkflow")) {
1061
				try {
1062
					WorkflowSchedulerClient.getInstance().reScheduleJob(request,
1063
							response, params, userName, groupNames);
1064
					return;
1065
				} catch (BaseException be) {
1066
					ResponseUtil.sendErrorXML(response,
1067
							ResponseUtil.RESCHEDULE_WORKFLOW_ERROR, be);
1068
					return;
1069
				}
1070
			} else if (action.equals("getScheduledWorkflow")) {
1071
				try {
1072
					WorkflowSchedulerClient.getInstance().getJobs(request, response,
1073
							params, userName, groupNames);
1074
					return;
1075
				} catch (BaseException be) {
1076
					ResponseUtil.sendErrorXML(response,
1077
							ResponseUtil.GET_SCHEDULED_WORKFLOW_ERROR, be);
1078
					return;
1079
				}
1080
			} else if (action.equals("deleteScheduledWorkflow")) {
1081
				try {
1082
					WorkflowSchedulerClient.getInstance().deleteJob(request, response,
1083
							params, userName, groupNames);
1084
					return;
1085
				} catch (BaseException be) {
1086
					ResponseUtil.sendErrorXML(response,
1087
							ResponseUtil.DELETE_SCHEDULED_WORKFLOW_ERROR, be);
1088
					return;
1089
				}
1090

    
1091
			} else {
1092
				//try the plugin handler if it has an entry for handling this action
1093
				MetacatHandlerPlugin handlerPlugin = MetacatHandlerPluginManager.getInstance().getHandler(action);
1094
				if (handlerPlugin != null) {
1095
					handlerPlugin.handleAction(action, params, request, response, userName, groupNames, sessionId);
1096
				} 
1097
				else {
1098
					PrintWriter out = response.getWriter();
1099
					out.println("<?xml version=\"1.0\"?>");
1100
					out.println("<error>");
1101
					out.println("Error: action: " + action + " not registered.  Please report this error.");
1102
					out.println("</error>");
1103
					out.close();
1104
				}
1105
			}
1106

    
1107
			// Schedule the sitemap generator to run periodically
1108
			handler.scheduleSitemapGeneration(request);
1109

    
1110

    
1111
		} catch (PropertyNotFoundException pnfe) {
1112
			String errorString = "Critical property not found: " + pnfe.getMessage();
1113
			logMetacat.error("MetaCatServlet.handleGetOrPost - " + errorString);
1114
			throw new ServletException(errorString);
1115
		} catch (MetacatUtilException ue) {
1116
			String errorString = "Utility error: " + ue.getMessage();
1117
			logMetacat.error("MetaCatServlet.handleGetOrPost - " + errorString);
1118
			throw new ServletException(errorString);
1119
		} catch (ServiceException ue) {
1120
			String errorString = "Service error: " + ue.getMessage();
1121
			logMetacat.error("MetaCatServlet.handleGetOrPost - " + errorString);
1122
			throw new ServletException(errorString);
1123
		} catch (HandlerException he) {
1124
			String errorString = "Handler error: " + he.getMessage();
1125
			logMetacat.error("MetaCatServlet.handleGetOrPost - " + errorString);
1126
			throw new ServletException(errorString);
1127
		} catch (ErrorSendingErrorException esee) {
1128
			String errorString = "Error sending error message: " + esee.getMessage();
1129
			logMetacat.error("MetaCatServlet.handleGetOrPost - " + errorString);
1130
			throw new ServletException(errorString);
1131
		} catch (ErrorHandledException ehe) {
1132
			// Nothing to do here.  We assume if we get here, the error has been 
1133
			// written to ouput.  Continue on and let it display.
1134
		} 
1135
	}
1136
    
1137
    /**
1138
     * Reports whether the MetaCatServlet has been fully initialized
1139
     * 
1140
     * @return true if fully intialized, false otherwise
1141
     */
1142
    public static boolean isFullyInitialized() {
1143
    	return _fullyInitialized;
1144
    }
1145
}
(41-41/63)