[metacat-cvs] metacat/src/edu/ucsb/nceas/metacat MetaCatServlet.java
Matthew Jones
jones at ecoinformatics.org
Thu Nov 17 11:38:24 PST 2005
jones 05/11/17 11:38:24
Modified: src/edu/ucsb/nceas/metacat MetaCatServlet.java
Log:
Changed logMetacat to be a local variable in MetaCatServlet to avoid any potential threading issues.
Revision Changes Path
1.237 +67 -48 metacat/src/edu/ucsb/nceas/metacat/MetaCatServlet.java
Index: MetaCatServlet.java
===================================================================
RCS file: /cvs/metacat/src/edu/ucsb/nceas/metacat/MetaCatServlet.java,v
retrieving revision 1.236
retrieving revision 1.237
diff -u -r1.236 -r1.237
--- MetaCatServlet.java 17 Nov 2005 01:27:26 -0000 1.236
+++ MetaCatServlet.java 17 Nov 2005 19:38:24 -0000 1.237
@@ -7,8 +7,8 @@
* Release: @release@
*
* '$Author: jones $'
- * '$Date: 2005/11/17 01:27:26 $'
- * '$Revision: 1.236 $'
+ * '$Date: 2005/11/17 19:38:24 $'
+ * '$Revision: 1.237 $'
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -116,7 +116,6 @@
public class MetaCatServlet extends HttpServlet
{
private static Hashtable sessionHash = new Hashtable();
- private static Logger logMetacat = Logger.getLogger(MetaCatServlet.class);
private Timer timer = null;
// Constants -- these should be final in a servlet
@@ -155,6 +154,7 @@
MetaCatUtil.printMessage("Options configured: "
+ options.getOption("configured"));
} catch (IOException ioe) {
+ Logger logMetacat = Logger.getLogger(MetaCatServlet.class);
logMetacat.error("Error in loading options: "
+ ioe.getMessage());
}
@@ -184,6 +184,7 @@
} catch (ServletException ex) {
throw ex;
} catch (SQLException e) {
+ Logger logMetacat = Logger.getLogger(MetaCatServlet.class);
logMetacat.error("Error in MetacatServlet.init: "
+ e.getMessage());
}
@@ -221,7 +222,8 @@
/**
* Index the paths specified in the metacat.properties
*/
- private void checkIndexPaths(){
+ private void checkIndexPaths() {
+ Logger logMetacat = Logger.getLogger(MetaCatServlet.class);
MetaCatUtil.pathsForIndexing
= MetaCatUtil.getOptionList(MetaCatUtil.getOption("indexed_paths"));
@@ -236,7 +238,7 @@
ResultSet rs = null;
for (int i = 0; i < MetaCatUtil.pathsForIndexing.size(); i++) {
- logMetacat.info("Checking if '"
+ logMetacat.debug("Checking if '"
+ (String) MetaCatUtil.pathsForIndexing.elementAt(i)
+ "' is indexed.... ");
@@ -255,7 +257,7 @@
rs = pstmt.getResultSet();
if (!rs.next()) {
- logMetacat.info(".....not indexed yet.");
+ logMetacat.debug(".....not indexed yet.");
rs.close();
pstmt.close();
conn.increaseUsageCount(1);
@@ -320,13 +322,13 @@
pstmt.close();
conn.increaseUsageCount(1);
- logMetacat.warn("Indexed " + count
+ logMetacat.info("Indexed " + count
+ " records from xml_nodes for '"
+ (String) MetaCatUtil.pathsForIndexing.elementAt(i)
+ "'");
} else {
- logMetacat.info(".....already indexed.");
+ logMetacat.debug(".....already indexed.");
}
rs.close();
@@ -355,11 +357,12 @@
HttpServletResponse response) throws ServletException, IOException
{
MetaCatUtil util = new MetaCatUtil();
-
+ Logger logMetacat = Logger.getLogger(MetaCatServlet.class);
+
/*
- * logMetacat.info("Connection pool size: "
+ * logMetacat.debug("Connection pool size: "
* +connPool.getSizeOfDBConnectionPool(),10);
- * logMetacat.info("Free DBConnection number: "
+ * logMetacat.debug("Free DBConnection number: "
*/
//If all DBConnection in the pool are free and DBConnection pool
//size is greater than initial value, shrink the connection pool
@@ -422,7 +425,7 @@
}
String action = ((String[]) params.get("action"))[0];
- logMetacat.warn("Action is: " + action);
+ logMetacat.info("Action is: " + action);
// This block handles session management for the servlet
// by looking up the current session information for all actions
@@ -470,12 +473,12 @@
HttpSession sess = request.getSession(true);
if (sess.isNew() && !params.containsKey("sessionid")) {
// session expired or has not been stored b/w user requests
- logMetacat.warn(
+ logMetacat.info(
"The session is new or no sessionid is assigned. The user is public");
username = "public";
sess.setAttribute("username", username);
} else {
- logMetacat.warn("The session is either old or "
+ logMetacat.info("The session is either old or "
+ "has sessionid parameter");
try {
if (params.containsKey("sessionid")) {
@@ -519,7 +522,7 @@
if (username == null || (username.trim().equals(""))) {
username = "public";
}
- logMetacat.warn("The user is : " + username);
+ logMetacat.info("The user is : " + username);
}
// Now that we know the session is valid, we can delegate the
// request
@@ -712,7 +715,7 @@
private void handleLoginAction(PrintWriter out, Hashtable params,
HttpServletRequest request, HttpServletResponse response)
{
-
+ Logger logMetacat = Logger.getLogger(MetaCatServlet.class);
AuthSession sess = null;
if(params.get("username") == null){
@@ -734,7 +737,7 @@
}
String un = ((String[]) params.get("username"))[0];
- logMetacat.warn("user " + un + " is trying to login");
+ logMetacat.info("user " + un + " is trying to login");
String pw = ((String[]) params.get("password"))[0];
String qformat = "xml";
@@ -788,7 +791,7 @@
private void handleLogoutAction(PrintWriter out, Hashtable params,
HttpServletRequest request, HttpServletResponse response)
{
-
+ Logger logMetacat = Logger.getLogger(MetaCatServlet.class);
String qformat = "xml";
if(params.get("qformat") != null){
qformat = ((String[]) params.get("qformat"))[0];
@@ -800,7 +803,7 @@
if (sess != null) {
logMetacat.info("The session id " + sess.getId()
+ " will be invalidate in logout action");
- logMetacat.warn("The session contains user "
+ logMetacat.info("The session contains user "
+ sess.getAttribute("username")
+ " will be invalidate in logout action");
sess.invalidate();
@@ -852,9 +855,9 @@
DBQuery queryobj = new DBQuery();
queryobj.findDocuments(response, out, params, user, groups, sessionid);
double outPutTime = System.currentTimeMillis() / 1000;
- logMetacat.warn("Total search time for action 'squery': "
+ Logger logMetacat = Logger.getLogger(MetaCatServlet.class);
+ logMetacat.info("Total search time for action 'squery': "
+ (outPutTime - startTime));
-
}
/**
@@ -878,7 +881,8 @@
DBQuery queryobj = new DBQuery();
queryobj.findDocuments(response, out, params, user, groups, sessionid);
double outPutTime = System.currentTimeMillis() / 1000;
- logMetacat.warn("Total search time for action 'query': "
+ Logger logMetacat = Logger.getLogger(MetaCatServlet.class);
+ logMetacat.info("Total search time for action 'query': "
+ (outPutTime - startTime));
//handleSQuery(out, params, response,user, groups, sessionid);
@@ -899,6 +903,7 @@
HttpServletResponse response,
String user, String[] groups, String passWord)
{
+ Logger logMetacat = Logger.getLogger(MetaCatServlet.class);
// Output stream
ServletOutputStream out = null;
// Zip output stream
@@ -992,6 +997,7 @@
HttpServletRequest request, HttpServletResponse response,
String user, String passWord, String[] groups)
{
+ Logger logMetacat = Logger.getLogger(MetaCatServlet.class);
String[] docs = new String[10];
String inlineDataId = null;
String docId = "";
@@ -1095,6 +1101,7 @@
private long getInlineDataNodeId(String inLineDataId, String docId)
throws SQLException
{
+ Logger logMetacat = Logger.getLogger(MetaCatServlet.class);
long nodeId = 0;
String INLINE = "inline";
boolean hasRow;
@@ -1135,7 +1142,7 @@
DBConnectionPool.returnDBConnection(conn, serialNumber);
}
}
- logMetacat.info("The nodeid for inlinedataid " + inLineDataId
+ logMetacat.debug("The nodeid for inlinedataid " + inLineDataId
+ " is: " + nodeId);
return nodeId;
}
@@ -1155,6 +1162,7 @@
HttpServletResponse response, String user, String passWord,
String[] groups)
{
+ Logger logMetacat = Logger.getLogger(MetaCatServlet.class);
ServletOutputStream out = null;
ZipOutputStream zout = null;
PrintWriter pw = null;
@@ -1349,7 +1357,7 @@
throws ClassNotFoundException, IOException, SQLException,
McdbException, Exception
{
-
+ Logger logMetacat = Logger.getLogger(MetaCatServlet.class);
try {
// here is hack for handle docid=john.10(in order to tell mike.jim.10.1
@@ -1387,7 +1395,7 @@
ContentTypeProvider provider = new ContentTypeProvider(
docid);
contentType = provider.getContentType();
- logMetacat.warn("Final contenttype is: "
+ logMetacat.info("Final contenttype is: "
+ contentType);
}
@@ -1625,6 +1633,7 @@
HttpServletResponse response, PrintWriter out, Hashtable params,
String user, String[] groups)
{
+ Logger logMetacat = Logger.getLogger(MetaCatServlet.class);
DBConnection dbConn = null;
int serialNumber = -1;
@@ -1735,7 +1744,7 @@
// write the document to the database
try {
String accNumber = docid[0];
- logMetacat.warn("" + doAction + " "
+ logMetacat.debug("" + doAction + " "
+ accNumber + "...");
if (accNumber.equals("")) {
accNumber = null;
@@ -1790,7 +1799,7 @@
private static boolean needDTDValidation(StringReader xmlreader)
throws IOException
{
-
+ Logger logMetacat = Logger.getLogger(MetaCatServlet.class);
StringBuffer cbuff = new StringBuffer();
java.util.Stack st = new java.util.Stack();
boolean validate = false;
@@ -1839,7 +1848,7 @@
}
}
- logMetacat.warn("Validation for dtd is " + validate);
+ logMetacat.info("Validation for dtd is " + validate);
return validate;
}
@@ -1848,6 +1857,7 @@
/* check if the xml string contains key words to specify schema loocation */
private String findNamespace(StringReader xml) throws IOException
{
+ Logger logMetacat = Logger.getLogger(MetaCatServlet.class);
String namespace = null;
String eml2_0_0NameSpace = DocumentImpl.EML2_0_0NAMESPACE;
@@ -1855,7 +1865,7 @@
String eml2_1_0NameSpace = DocumentImpl.EML2_1_0NAMESPACE;
if (xml == null) {
- logMetacat.warn("Validation for schema is "
+ logMetacat.debug("Validation for schema is "
+ namespace);
return namespace;
}
@@ -1876,14 +1886,14 @@
String namespaceWithPrefix = NAMESPACEKEYWORD
+ ":" + prefix;
startIndex = targetLine.indexOf(namespaceWithPrefix);
- logMetacat.info("namespaceWithPrefix is:" + namespaceWithPrefix+":");
- logMetacat.info("startIndex is:" + startIndex);
+ logMetacat.debug("namespaceWithPrefix is:" + namespaceWithPrefix+":");
+ logMetacat.debug("startIndex is:" + startIndex);
} else {
// if prefix not found then look for xmlns
// attribute to find the ns
startIndex = targetLine.indexOf(NAMESPACEKEYWORD);
- logMetacat.info("startIndex is:" + startIndex);
+ logMetacat.debug("startIndex is:" + startIndex);
}
int start = 1;
@@ -1906,15 +1916,15 @@
}
// else: xmlns not found. namespace = null will be returned
- logMetacat.info("targetLine is " + targetLine);
+ logMetacat.debug("targetLine is " + targetLine);
logMetacat.debug("start is " + end);
logMetacat.debug("end is " + end);
if(start < end){
namespaceString = targetLine.substring(start + 1, end);
- logMetacat.info("namespaceString is " + namespaceString);
+ logMetacat.debug("namespaceString is " + namespaceString);
}
- logMetacat.info("namespace in xml is: "
+ logMetacat.debug("namespace in xml is: "
+ namespaceString);
if(namespaceString != null){
if (namespaceString.indexOf(eml2_0_0NameSpace) != -1) {
@@ -1929,7 +1939,7 @@
}
}
- logMetacat.warn("Validation for eml is " + namespace);
+ logMetacat.debug("Validation for eml is " + namespace);
return namespace;
@@ -1937,6 +1947,7 @@
private String getSchemaLine(StringReader xml) throws IOException
{
+ Logger logMetacat = Logger.getLogger(MetaCatServlet.class);
// find the line
String secondLine = null;
int count = 0;
@@ -1981,7 +1992,7 @@
tmp = xml.read();
}
secondLine = buffer.toString();
- logMetacat.info("the second line string is: " + secondLine);
+ logMetacat.debug("the second line string is: " + secondLine);
xml.reset();
return secondLine;
@@ -1989,9 +2000,10 @@
private String getPrefix(String schemaLine)
{
+ Logger logMetacat = Logger.getLogger(MetaCatServlet.class);
String prefix = null;
String rootElement = schemaLine.substring(0, schemaLine.indexOf(" "));
- logMetacat.info("rootElement:" + rootElement);
+ logMetacat.debug("rootElement:" + rootElement);
if(rootElement.indexOf(":") > 0){
prefix = rootElement.substring(rootElement.indexOf(":") + 1,
@@ -2008,7 +2020,7 @@
HttpServletRequest request, HttpServletResponse response,
String user, String[] groups)
{
-
+ Logger logMetacat = Logger.getLogger(MetaCatServlet.class);
String[] docid = (String[]) params.get("docid");
if(docid == null){
@@ -2033,7 +2045,7 @@
out.println("<success>");
out.println("Document deleted.");
out.println("</success>");
- logMetacat.warn("Document deleted.");
+ logMetacat.info("Document deleted.");
}
catch (AccessionNumberException ane) {
response.setContentType("text/xml");
@@ -2305,6 +2317,7 @@
private void handleGetLogAction(Hashtable params, HttpServletRequest request,
HttpServletResponse response, String username, String[] groups)
{
+ Logger logMetacat = Logger.getLogger(MetaCatServlet.class);
try {
response.setContentType("text/xml");
PrintWriter out = response.getWriter();
@@ -2372,6 +2385,8 @@
HttpServletRequest request, HttpServletResponse response,
String username, String[] groups)
{
+ Logger logMetacat = Logger.getLogger(MetaCatServlet.class);
+
// Get all of the parameters in the correct formats
String[] docid = (String[])params.get("docid");
@@ -2449,6 +2464,7 @@
private void handleMultipartForm(HttpServletRequest request,
HttpServletResponse response)
{
+ Logger logMetacat = Logger.getLogger(MetaCatServlet.class);
PrintWriter out = null;
String action = null;
@@ -2460,11 +2476,9 @@
int sizeLimit = (new Integer(MetaCatUtil.getOption("datafilesizelimit")))
.intValue();
logMetacat.info(
- "The limit size of data file is: " + sizeLimit);
+ "The size limit of uploaded data files is: " + sizeLimit);
try {
- // MBJ: need to put filesize limit in Metacat config
- // (metacat.properties)
MultipartParser mp = new MultipartParser(request,
sizeLimit * 1024 * 1024);
Part part;
@@ -2572,6 +2586,7 @@
PrintWriter out, Hashtable params, Hashtable fileList,
String username, String[] groupnames)
{
+ Logger logMetacat = Logger.getLogger(MetaCatServlet.class);
//PrintWriter out = null;
//Connection conn = null;
String action = null;
@@ -2590,11 +2605,11 @@
// Make sure we have a docid and datafile
if (docid != null && fileList.containsKey("datafile")) {
- logMetacat.warn("Uploading data docid: " + docid);
+ logMetacat.info("Uploading data docid: " + docid);
// Get a reference to the file part of the form
FilePart filePart = (FilePart) fileList.get("datafile");
String fileName = filePart.getFileName();
- logMetacat.warn("Uploading filename: " + fileName);
+ logMetacat.info("Uploading filename: " + fileName);
// Check if the right file existed in the uploaded data
if (fileName != null) {
@@ -2679,6 +2694,7 @@
private void handleSetAccessAction(PrintWriter out, Hashtable params,
String username)
{
+ Logger logMetacat = Logger.getLogger(MetaCatServlet.class);
String[] docList = null;
String[] principalList = null;
String[] permissionList = null;
@@ -2736,7 +2752,7 @@
//debug
if (packageSet != null) {
for (int i = 0; i < packageSet.size(); i++) {
- logMetacat.info("doctype in package set: "
+ logMetacat.debug("doctype in package set: "
+ (String) packageSet.elementAt(i));
}
}
@@ -2814,6 +2830,7 @@
private String getFieldValueForDoc(String accessionNumber, String fieldName)
throws Exception
{
+ Logger logMetacat = Logger.getLogger(MetaCatServlet.class);
if (accessionNumber == null || accessionNumber.equals("")
|| fieldName == null || fieldName.equals("")) { throw new Exception(
"Docid or field name was not specified"); }
@@ -2871,6 +2888,7 @@
*/
private Vector getDocumentList() throws SQLException
{
+ Logger logMetacat = Logger.getLogger(MetaCatServlet.class);
Vector docList = new Vector();
PreparedStatement pstmt = null;
ResultSet rs = null;
@@ -2965,6 +2983,7 @@
*/
private static String appendRev(String docid) throws Exception
{
+ Logger logMetacat = Logger.getLogger(MetaCatServlet.class);
String newAccNum = null;
String separator = MetaCatUtil.getOption("accNumSeparator");
int firstIndex = docid.indexOf(separator);
@@ -2988,7 +3007,7 @@
// in other suituation we don't change the docid
newAccNum = docid;
}
- logMetacat.warn("The docid will be read is "+newAccNum);
+ logMetacat.debug("The docid will be read is "+newAccNum);
return newAccNum;
}
}
More information about the Metacat-cvs
mailing list