44 |
44 |
import java.util.Enumeration;
|
45 |
45 |
import java.util.Hashtable;
|
46 |
46 |
import java.util.Iterator;
|
47 |
|
import java.util.PropertyResourceBundle;
|
|
47 |
import java.util.Timer;
|
48 |
48 |
import java.util.Vector;
|
49 |
49 |
import java.util.zip.ZipEntry;
|
50 |
50 |
import java.util.zip.ZipOutputStream;
|
51 |
|
import java.util.Timer;
|
52 |
51 |
|
53 |
52 |
import javax.servlet.ServletConfig;
|
54 |
53 |
import javax.servlet.ServletContext;
|
... | ... | |
59 |
58 |
import javax.servlet.http.HttpServletResponse;
|
60 |
59 |
import javax.servlet.http.HttpSession;
|
61 |
60 |
|
|
61 |
import org.apache.log4j.Logger;
|
|
62 |
import org.apache.log4j.PropertyConfigurator;
|
62 |
63 |
import org.ecoinformatics.eml.EMLParser;
|
63 |
64 |
|
64 |
65 |
import com.oreilly.servlet.multipart.FilePart;
|
... | ... | |
66 |
67 |
import com.oreilly.servlet.multipart.ParamPart;
|
67 |
68 |
import com.oreilly.servlet.multipart.Part;
|
68 |
69 |
|
69 |
|
import org.apache.log4j.Logger;
|
70 |
|
import org.apache.log4j.PropertyConfigurator;
|
71 |
|
|
72 |
70 |
import edu.ucsb.nceas.utilities.Options;
|
73 |
71 |
|
74 |
72 |
/**
|
... | ... | |
117 |
115 |
*/
|
118 |
116 |
public class MetaCatServlet extends HttpServlet
|
119 |
117 |
{
|
120 |
|
|
121 |
|
private ServletConfig config = null;
|
122 |
|
|
123 |
|
private ServletContext context = null;
|
124 |
|
|
125 |
|
private String resultStyleURL = null;
|
126 |
|
|
127 |
|
private String xmlcatalogfile = null;
|
128 |
|
|
129 |
|
private String saxparser = null;
|
130 |
|
|
131 |
|
private String datafilepath = null;
|
132 |
|
|
133 |
|
private File dataDirectory = null;
|
134 |
|
|
135 |
|
private String servletpath = null;
|
136 |
|
|
137 |
|
private String htmlpath = null;
|
138 |
|
|
139 |
|
private PropertyResourceBundle options = null;
|
140 |
|
|
141 |
|
private MetaCatUtil util = null;
|
142 |
|
|
143 |
|
private DBConnectionPool connPool = null;
|
144 |
|
|
145 |
118 |
private static Hashtable sessionHash = new Hashtable();
|
146 |
|
|
|
119 |
private static Logger logMetacat = Logger.getLogger(MetaCatServlet.class);
|
|
120 |
private Timer timer = null;
|
|
121 |
|
|
122 |
// Constants -- these should be final in a servlet
|
147 |
123 |
private static final String PROLOG = "<?xml version=\"1.0\"?>";
|
148 |
|
|
149 |
124 |
private static final String SUCCESS = "<success>";
|
150 |
|
|
151 |
125 |
private static final String SUCCESSCLOSE = "</success>";
|
152 |
|
|
153 |
126 |
private static final String ERROR = "<error>";
|
154 |
|
|
155 |
127 |
private static final String ERRORCLOSE = "</error>";
|
156 |
|
|
157 |
128 |
public static final String SCHEMALOCATIONKEYWORD = ":schemaLocation";
|
158 |
|
|
159 |
129 |
public static final String NONAMESPACELOCATION = ":noNamespaceSchemaLocation";
|
160 |
|
|
161 |
130 |
public static final String NAMESPACEKEYWORD = "xmlns";
|
162 |
|
|
163 |
131 |
public static final String EML2KEYWORD = ":eml";
|
164 |
|
|
165 |
132 |
public static final String XMLFORMAT = "xml";
|
166 |
|
|
167 |
133 |
private static final String CONFIG_DIR = "WEB-INF";
|
168 |
|
|
169 |
|
private static final String CONFIG_NAME = "metacat.properties";
|
170 |
|
|
171 |
|
private static Logger logMetacat = Logger.getLogger(MetaCatServlet.class);
|
172 |
|
|
173 |
|
private Timer timer = null;
|
|
134 |
private static final String CONFIG_NAME = "metacat.properties";
|
174 |
135 |
|
175 |
136 |
/**
|
176 |
137 |
* Initialize the servlet by creating appropriate database connections
|
... | ... | |
179 |
140 |
{
|
180 |
141 |
try {
|
181 |
142 |
super.init(config);
|
182 |
|
this.config = config;
|
183 |
|
this.context = config.getServletContext();
|
|
143 |
ServletContext context = config.getServletContext();
|
184 |
144 |
|
185 |
145 |
// Initialize the properties file for our options
|
186 |
146 |
String dirPath = context.getRealPath(CONFIG_DIR);
|
... | ... | |
199 |
159 |
+ ioe.getMessage());
|
200 |
160 |
}
|
201 |
161 |
|
202 |
|
util = new MetaCatUtil();
|
|
162 |
MetaCatUtil util = new MetaCatUtil();
|
203 |
163 |
|
204 |
|
//initial DBConnection pool
|
205 |
|
connPool = DBConnectionPool.getInstance();
|
206 |
|
|
207 |
|
// Get the configuration file information
|
208 |
|
resultStyleURL = MetaCatUtil.getOption("resultStyleURL");
|
209 |
|
xmlcatalogfile = MetaCatUtil.getOption("xmlcatalogfile");
|
210 |
|
saxparser = MetaCatUtil.getOption("saxparser");
|
211 |
|
datafilepath = MetaCatUtil.getOption("datafilepath");
|
212 |
|
dataDirectory = new File(datafilepath);
|
213 |
|
servletpath = MetaCatUtil.getOption("servletpath");
|
214 |
|
htmlpath = MetaCatUtil.getOption("htmlpath");
|
215 |
|
|
|
164 |
//initialize DBConnection pool
|
|
165 |
DBConnectionPool connPool = DBConnectionPool.getInstance();
|
|
166 |
|
216 |
167 |
// Index the paths specified in the metacat.properties
|
217 |
168 |
checkIndexPaths();
|
218 |
169 |
|
... | ... | |
403 |
354 |
private void handleGetOrPost(HttpServletRequest request,
|
404 |
355 |
HttpServletResponse response) throws ServletException, IOException
|
405 |
356 |
{
|
406 |
|
|
407 |
|
if (util == null) {
|
408 |
|
util = new MetaCatUtil();
|
409 |
|
}
|
|
357 |
MetaCatUtil util = new MetaCatUtil();
|
|
358 |
|
410 |
359 |
/*
|
411 |
360 |
* logMetacat.info("Connection pool size: "
|
412 |
361 |
* +connPool.getSizeOfDBConnectionPool(),10);
|
... | ... | |
418 |
367 |
DBConnectionPool.shrinkDBConnectionPoolSize();
|
419 |
368 |
|
420 |
369 |
//Debug message to print out the method which have a busy DBConnection
|
421 |
|
connPool.printMethodNameHavingBusyDBConnection();
|
|
370 |
try {
|
|
371 |
DBConnectionPool pool = DBConnectionPool.getInstance();
|
|
372 |
pool.printMethodNameHavingBusyDBConnection();
|
|
373 |
} catch (SQLException e) {
|
|
374 |
logMetacat.error("Error in MetacatServlet.handleGetOrPost: "
|
|
375 |
+ e.getMessage());
|
|
376 |
e.printStackTrace();
|
|
377 |
}
|
422 |
378 |
|
423 |
379 |
String ctype = request.getContentType();
|
424 |
380 |
if (ctype != null && ctype.startsWith("multipart/form-data")) {
|
... | ... | |
893 |
849 |
String sessionid)
|
894 |
850 |
{
|
895 |
851 |
double startTime = System.currentTimeMillis() / 1000;
|
896 |
|
DBQuery queryobj = new DBQuery(saxparser);
|
|
852 |
DBQuery queryobj = new DBQuery();
|
897 |
853 |
queryobj.findDocuments(response, out, params, user, groups, sessionid);
|
898 |
854 |
double outPutTime = System.currentTimeMillis() / 1000;
|
899 |
855 |
logMetacat.warn("Total search time for action 'squery': "
|
... | ... | |
919 |
875 |
queryArray[0] = xmlquery;
|
920 |
876 |
params.put("query", queryArray);
|
921 |
877 |
double startTime = System.currentTimeMillis() / 1000;
|
922 |
|
DBQuery queryobj = new DBQuery(saxparser);
|
|
878 |
DBQuery queryobj = new DBQuery();
|
923 |
879 |
queryobj.findDocuments(response, out, params, user, groups, sessionid);
|
924 |
880 |
double outPutTime = System.currentTimeMillis() / 1000;
|
925 |
881 |
logMetacat.warn("Total search time for action 'query': "
|
... | ... | |
958 |
914 |
docs = (String[]) params.get("docid");
|
959 |
915 |
}
|
960 |
916 |
// Create a DBuery to handle export
|
961 |
|
queryObj = new DBQuery(saxparser);
|
|
917 |
queryObj = new DBQuery();
|
962 |
918 |
// Get the docid
|
963 |
919 |
docId = docs[0];
|
964 |
920 |
// Make sure the client specify docid
|
... | ... | |
2143 |
2099 |
dbConn = DBConnectionPool
|
2144 |
2100 |
.getDBConnection("MetaCatServlet.handleValidateAction");
|
2145 |
2101 |
serialNumber = dbConn.getCheckOutSerialNumber();
|
2146 |
|
DBValidate valobj = new DBValidate(saxparser, dbConn);
|
|
2102 |
DBValidate valobj = new DBValidate(dbConn);
|
2147 |
2103 |
boolean valid = valobj.validateString(valtext);
|
2148 |
2104 |
|
2149 |
2105 |
// set content type and other response header fields first
|
... | ... | |
2648 |
2604 |
//If document get lock data file grant
|
2649 |
2605 |
if (DocumentImpl.getDataFileLockGrant(docid)) {
|
2650 |
2606 |
// Save the data file to disk using "docid" as the name
|
|
2607 |
String datafilepath = MetaCatUtil.getOption("datafilepath");
|
|
2608 |
File dataDirectory = new File(datafilepath);
|
2651 |
2609 |
dataDirectory.mkdirs();
|
2652 |
2610 |
File newFile = null;
|
2653 |
2611 |
long size = 0;
|
Metacat has had problems with threading issues when accessed from ecogrid. These problems may stem from the use of shared global variables within the servlet that are not protected against threading problems. We used a lot of these, which I am eliminating in this commit. Besides final variables used as constants (which are not a problem), now there are only three unprotected variables (sessionHash, logMetacat, and conn) which are harder to eliminate. I will be discussiong this with Sid tomorrow to see how to eliminate them.