Project

General

Profile

« Previous | Next » 

Revision 2753

Changed logMetacat to be a local variable in MetaCatServlet to avoid any potential threading issues.

View differences:

src/edu/ucsb/nceas/metacat/MetaCatServlet.java
116 116
public class MetaCatServlet extends HttpServlet
117 117
{
118 118
    private static Hashtable sessionHash = new Hashtable();
119
    private static Logger logMetacat = Logger.getLogger(MetaCatServlet.class);
120 119
    private Timer timer = null;
121 120
    
122 121
    // Constants -- these should be final in a servlet
......
155 154
                MetaCatUtil.printMessage("Options configured: "
156 155
                        + options.getOption("configured"));
157 156
            } catch (IOException ioe) {
157
                Logger logMetacat = Logger.getLogger(MetaCatServlet.class);
158 158
                logMetacat.error("Error in loading options: "
159 159
                        + ioe.getMessage());
160 160
            }
......
184 184
        } catch (ServletException ex) {
185 185
            throw ex;
186 186
        } catch (SQLException e) {
187
            Logger logMetacat = Logger.getLogger(MetaCatServlet.class);
187 188
            logMetacat.error("Error in MetacatServlet.init: "
188 189
                    + e.getMessage());
189 190
        }
......
221 222
    /**
222 223
     * Index the paths specified in the metacat.properties
223 224
     */
224
    private void checkIndexPaths(){
225
    private void checkIndexPaths() {
226
        Logger logMetacat = Logger.getLogger(MetaCatServlet.class);
225 227
        MetaCatUtil.pathsForIndexing
226 228
            = MetaCatUtil.getOptionList(MetaCatUtil.getOption("indexed_paths"));
227 229
    
......
236 238
            ResultSet rs = null;
237 239
    
238 240
            for (int i = 0; i < MetaCatUtil.pathsForIndexing.size(); i++) {
239
                logMetacat.info("Checking if '"
241
                logMetacat.debug("Checking if '"
240 242
                           + (String) MetaCatUtil.pathsForIndexing.elementAt(i)
241 243
                           + "' is indexed.... ");
242 244
    
......
255 257
                    rs = pstmt.getResultSet();
256 258
    
257 259
                    if (!rs.next()) {
258
                        logMetacat.info(".....not indexed yet.");
260
                        logMetacat.debug(".....not indexed yet.");
259 261
                        rs.close();
260 262
                        pstmt.close();
261 263
                        conn.increaseUsageCount(1);
......
320 322
                        pstmt.close();
321 323
                        conn.increaseUsageCount(1);
322 324
    
323
                        logMetacat.warn("Indexed " + count
325
                        logMetacat.info("Indexed " + count
324 326
                                + " records from xml_nodes for '"
325 327
                                + (String) MetaCatUtil.pathsForIndexing.elementAt(i)
326 328
                                + "'");
327 329
    
328 330
                    } else {
329
                    	logMetacat.info(".....already indexed.");
331
                    	logMetacat.debug(".....already indexed.");
330 332
                    }
331 333
    
332 334
                    rs.close();
......
355 357
            HttpServletResponse response) throws ServletException, IOException
356 358
    {
357 359
        MetaCatUtil util = new MetaCatUtil();
358
       
360
        Logger logMetacat = Logger.getLogger(MetaCatServlet.class);
361
        
359 362
        /*
360
         * logMetacat.info("Connection pool size: "
363
         * logMetacat.debug("Connection pool size: "
361 364
         * +connPool.getSizeOfDBConnectionPool(),10);
362
         * logMetacat.info("Free DBConnection number: "
365
         * logMetacat.debug("Free DBConnection number: "
363 366
         */
364 367
        //If all DBConnection in the pool are free and DBConnection pool
365 368
        //size is greater than initial value, shrink the connection pool
......
422 425
            }
423 426

  
424 427
            String action = ((String[]) params.get("action"))[0];
425
            logMetacat.warn("Action is: " + action);
428
            logMetacat.info("Action is: " + action);
426 429

  
427 430
            // This block handles session management for the servlet
428 431
            // by looking up the current session information for all actions
......
470 473
                HttpSession sess = request.getSession(true);
471 474
                if (sess.isNew() && !params.containsKey("sessionid")) {
472 475
                    // session expired or has not been stored b/w user requests
473
                    logMetacat.warn(
476
                    logMetacat.info(
474 477
                            "The session is new or no sessionid is assigned. The user is public");
475 478
                    username = "public";
476 479
                    sess.setAttribute("username", username);
477 480
                } else {
478
                    logMetacat.warn("The session is either old or "
481
                    logMetacat.info("The session is either old or "
479 482
                            + "has sessionid parameter");
480 483
                    try {
481 484
                        if (params.containsKey("sessionid")) {
......
519 522
                if (username == null || (username.trim().equals(""))) {
520 523
                    username = "public";
521 524
                }
522
                logMetacat.warn("The user is : " + username);
525
                logMetacat.info("The user is : " + username);
523 526
            }
524 527
            // Now that we know the session is valid, we can delegate the
525 528
            // request
......
712 715
    private void handleLoginAction(PrintWriter out, Hashtable params,
713 716
            HttpServletRequest request, HttpServletResponse response)
714 717
    {
715

  
718
        Logger logMetacat = Logger.getLogger(MetaCatServlet.class);
716 719
        AuthSession sess = null;
717 720

  
718 721
        if(params.get("username") == null){
......
734 737
        }
735 738

  
736 739
        String un = ((String[]) params.get("username"))[0];
737
        logMetacat.warn("user " + un + " is trying to login");
740
        logMetacat.info("user " + un + " is trying to login");
738 741
        String pw = ((String[]) params.get("password"))[0];
739 742

  
740 743
        String qformat = "xml";
......
788 791
    private void handleLogoutAction(PrintWriter out, Hashtable params,
789 792
            HttpServletRequest request, HttpServletResponse response)
790 793
    {
791

  
794
        Logger logMetacat = Logger.getLogger(MetaCatServlet.class);
792 795
        String qformat = "xml";
793 796
        if(params.get("qformat") != null){
794 797
            qformat = ((String[]) params.get("qformat"))[0];
......
800 803
        if (sess != null) {
801 804
            logMetacat.info("The session id " + sess.getId()
802 805
                    + " will be invalidate in logout action");
803
            logMetacat.warn("The session contains user "
806
            logMetacat.info("The session contains user "
804 807
                    + sess.getAttribute("username")
805 808
                    + " will be invalidate in logout action");
806 809
            sess.invalidate();
......
852 855
        DBQuery queryobj = new DBQuery();
853 856
        queryobj.findDocuments(response, out, params, user, groups, sessionid);
854 857
        double outPutTime = System.currentTimeMillis() / 1000;
855
        logMetacat.warn("Total search time for action 'squery': "
858
        Logger logMetacat = Logger.getLogger(MetaCatServlet.class);
859
        logMetacat.info("Total search time for action 'squery': "
856 860
                + (outPutTime - startTime));
857

  
858 861
    }
859 862

  
860 863
    /**
......
878 881
        DBQuery queryobj = new DBQuery();
879 882
        queryobj.findDocuments(response, out, params, user, groups, sessionid);
880 883
        double outPutTime = System.currentTimeMillis() / 1000;
881
        logMetacat.warn("Total search time for action 'query': "
884
        Logger logMetacat = Logger.getLogger(MetaCatServlet.class);
885
        logMetacat.info("Total search time for action 'query': "
882 886
                + (outPutTime - startTime));
883 887

  
884 888
        //handleSQuery(out, params, response,user, groups, sessionid);
......
899 903
            HttpServletResponse response,
900 904
            String user, String[] groups, String passWord)
901 905
    {
906
        Logger logMetacat = Logger.getLogger(MetaCatServlet.class);
902 907
        // Output stream
903 908
        ServletOutputStream out = null;
904 909
        // Zip output stream
......
992 997
            HttpServletRequest request, HttpServletResponse response,
993 998
            String user, String passWord, String[] groups)
994 999
    {
1000
        Logger logMetacat = Logger.getLogger(MetaCatServlet.class);
995 1001
        String[] docs = new String[10];
996 1002
        String inlineDataId = null;
997 1003
        String docId = "";
......
1095 1101
    private long getInlineDataNodeId(String inLineDataId, String docId)
1096 1102
            throws SQLException
1097 1103
    {
1104
        Logger logMetacat = Logger.getLogger(MetaCatServlet.class);
1098 1105
        long nodeId = 0;
1099 1106
        String INLINE = "inline";
1100 1107
        boolean hasRow;
......
1135 1142
                DBConnectionPool.returnDBConnection(conn, serialNumber);
1136 1143
            }
1137 1144
        }
1138
        logMetacat.info("The nodeid for inlinedataid " + inLineDataId
1145
        logMetacat.debug("The nodeid for inlinedataid " + inLineDataId
1139 1146
                + " is: " + nodeId);
1140 1147
        return nodeId;
1141 1148
    }
......
1155 1162
            HttpServletResponse response, String user, String passWord,
1156 1163
            String[] groups)
1157 1164
    {
1165
        Logger logMetacat = Logger.getLogger(MetaCatServlet.class);
1158 1166
        ServletOutputStream out = null;
1159 1167
        ZipOutputStream zout = null;
1160 1168
        PrintWriter pw = null;
......
1349 1357
            throws ClassNotFoundException, IOException, SQLException,
1350 1358
            McdbException, Exception
1351 1359
    {
1352

  
1360
        Logger logMetacat = Logger.getLogger(MetaCatServlet.class);
1353 1361
        try {
1354 1362
            
1355 1363
            // here is hack for handle docid=john.10(in order to tell mike.jim.10.1
......
1387 1395
                    ContentTypeProvider provider = new ContentTypeProvider(
1388 1396
                            docid);
1389 1397
                    contentType = provider.getContentType();
1390
                    logMetacat.warn("Final contenttype is: "
1398
                    logMetacat.info("Final contenttype is: "
1391 1399
                            + contentType);
1392 1400
                }
1393 1401

  
......
1625 1633
            HttpServletResponse response, PrintWriter out, Hashtable params,
1626 1634
            String user, String[] groups)
1627 1635
    {
1636
        Logger logMetacat = Logger.getLogger(MetaCatServlet.class);
1628 1637
        DBConnection dbConn = null;
1629 1638
        int serialNumber = -1;
1630 1639

  
......
1735 1744
                    // write the document to the database
1736 1745
                    try {
1737 1746
                        String accNumber = docid[0];
1738
                        logMetacat.warn("" + doAction + " "
1747
                        logMetacat.debug("" + doAction + " "
1739 1748
                                + accNumber + "...");
1740 1749
                        if (accNumber.equals("")) {
1741 1750
                            accNumber = null;
......
1790 1799
    private static boolean needDTDValidation(StringReader xmlreader)
1791 1800
            throws IOException
1792 1801
    {
1793

  
1802
        Logger logMetacat = Logger.getLogger(MetaCatServlet.class);
1794 1803
        StringBuffer cbuff = new StringBuffer();
1795 1804
        java.util.Stack st = new java.util.Stack();
1796 1805
        boolean validate = false;
......
1839 1848
            }
1840 1849
        }
1841 1850

  
1842
        logMetacat.warn("Validation for dtd is " + validate);
1851
        logMetacat.info("Validation for dtd is " + validate);
1843 1852
        return validate;
1844 1853
    }
1845 1854

  
......
1848 1857
    /* check if the xml string contains key words to specify schema loocation */
1849 1858
    private String findNamespace(StringReader xml) throws IOException
1850 1859
    {
1860
        Logger logMetacat = Logger.getLogger(MetaCatServlet.class);
1851 1861
        String namespace = null;
1852 1862

  
1853 1863
        String eml2_0_0NameSpace = DocumentImpl.EML2_0_0NAMESPACE;
......
1855 1865
        String eml2_1_0NameSpace = DocumentImpl.EML2_1_0NAMESPACE;
1856 1866

  
1857 1867
        if (xml == null) {
1858
            logMetacat.warn("Validation for schema is "
1868
            logMetacat.debug("Validation for schema is "
1859 1869
                    + namespace);
1860 1870
            return namespace;
1861 1871
        }
......
1876 1886
        		String namespaceWithPrefix = NAMESPACEKEYWORD 
1877 1887
        					+ ":" + prefix;
1878 1888
        		startIndex = targetLine.indexOf(namespaceWithPrefix);
1879
            	logMetacat.info("namespaceWithPrefix is:" + namespaceWithPrefix+":");
1880
            	logMetacat.info("startIndex is:" + startIndex);
1889
            	logMetacat.debug("namespaceWithPrefix is:" + namespaceWithPrefix+":");
1890
            	logMetacat.debug("startIndex is:" + startIndex);
1881 1891
        		
1882 1892
        	} else {
1883 1893
        		// if prefix not found then look for xmlns
1884 1894
        		// attribute to find the ns 
1885 1895
        		startIndex = targetLine.indexOf(NAMESPACEKEYWORD);
1886
            	logMetacat.info("startIndex is:" + startIndex);
1896
            	logMetacat.debug("startIndex is:" + startIndex);
1887 1897
        	}
1888 1898
        		
1889 1899
            int start = 1;
......
1906 1916
            } 
1907 1917
            // else: xmlns not found. namespace = null will be returned
1908 1918

  
1909
         	logMetacat.info("targetLine is " + targetLine);
1919
         	logMetacat.debug("targetLine is " + targetLine);
1910 1920
         	logMetacat.debug("start is " + end);
1911 1921
         	logMetacat.debug("end is " + end);
1912 1922
           
1913 1923
            if(start < end){
1914 1924
            	namespaceString = targetLine.substring(start + 1, end);
1915
            	logMetacat.info("namespaceString is " + namespaceString);
1925
            	logMetacat.debug("namespaceString is " + namespaceString);
1916 1926
            }
1917
            logMetacat.info("namespace in xml is: "
1927
            logMetacat.debug("namespace in xml is: "
1918 1928
                    + namespaceString);
1919 1929
            if(namespaceString != null){
1920 1930
            	if (namespaceString.indexOf(eml2_0_0NameSpace) != -1) {
......
1929 1939
            }
1930 1940
        }
1931 1941

  
1932
        logMetacat.warn("Validation for eml is " + namespace);
1942
        logMetacat.debug("Validation for eml is " + namespace);
1933 1943

  
1934 1944
        return namespace;
1935 1945

  
......
1937 1947

  
1938 1948
    private String getSchemaLine(StringReader xml) throws IOException
1939 1949
    {
1950
        Logger logMetacat = Logger.getLogger(MetaCatServlet.class);
1940 1951
        // find the line
1941 1952
        String secondLine = null;
1942 1953
        int count = 0;
......
1981 1992
            tmp = xml.read();
1982 1993
        }
1983 1994
        secondLine = buffer.toString();
1984
        logMetacat.info("the second line string is: " + secondLine);
1995
        logMetacat.debug("the second line string is: " + secondLine);
1985 1996
        
1986 1997
        xml.reset();
1987 1998
        return secondLine;
......
1989 2000

  
1990 2001
    private String getPrefix(String schemaLine)
1991 2002
    {
2003
        Logger logMetacat = Logger.getLogger(MetaCatServlet.class);
1992 2004
    	String prefix = null;
1993 2005
    	String rootElement = schemaLine.substring(0, schemaLine.indexOf(" "));
1994
        logMetacat.info("rootElement:" + rootElement);
2006
        logMetacat.debug("rootElement:" + rootElement);
1995 2007
        
1996 2008
        if(rootElement.indexOf(":") > 0){
1997 2009
        	prefix = rootElement.substring(rootElement.indexOf(":") + 1,
......
2008 2020
            HttpServletRequest request, HttpServletResponse response,
2009 2021
            String user, String[] groups)
2010 2022
    {
2011

  
2023
        Logger logMetacat = Logger.getLogger(MetaCatServlet.class);
2012 2024
        String[] docid = (String[]) params.get("docid");
2013 2025

  
2014 2026
        if(docid == null){
......
2033 2045
                    out.println("<success>");
2034 2046
                    out.println("Document deleted.");
2035 2047
                    out.println("</success>");
2036
                    logMetacat.warn("Document deleted.");
2048
                    logMetacat.info("Document deleted.");
2037 2049
                }
2038 2050
                catch (AccessionNumberException ane) {
2039 2051
                    response.setContentType("text/xml");
......
2305 2317
    private void handleGetLogAction(Hashtable params, HttpServletRequest request,
2306 2318
            HttpServletResponse response, String username, String[] groups)
2307 2319
    {
2320
        Logger logMetacat = Logger.getLogger(MetaCatServlet.class);
2308 2321
        try {
2309 2322
            response.setContentType("text/xml");
2310 2323
            PrintWriter out = response.getWriter();
......
2372 2385
            HttpServletRequest request, HttpServletResponse response,
2373 2386
            String username, String[] groups)
2374 2387
    {
2388
        Logger logMetacat = Logger.getLogger(MetaCatServlet.class);
2389
        
2375 2390
        // Get all of the parameters in the correct formats
2376 2391
        String[] docid = (String[])params.get("docid");
2377 2392

  
......
2449 2464
    private void handleMultipartForm(HttpServletRequest request,
2450 2465
            HttpServletResponse response)
2451 2466
    {
2467
        Logger logMetacat = Logger.getLogger(MetaCatServlet.class);
2452 2468
        PrintWriter out = null;
2453 2469
        String action = null;
2454 2470

  
......
2460 2476
        int sizeLimit = (new Integer(MetaCatUtil.getOption("datafilesizelimit")))
2461 2477
                .intValue();
2462 2478
        logMetacat.info(
2463
                "The limit size of data file is: " + sizeLimit);
2479
                "The size limit of uploaded data files is: " + sizeLimit);
2464 2480

  
2465 2481
        try {
2466
            // MBJ: need to put filesize limit in Metacat config
2467
            // (metacat.properties)
2468 2482
            MultipartParser mp = new MultipartParser(request,
2469 2483
                    sizeLimit * 1024 * 1024);
2470 2484
            Part part;
......
2572 2586
            PrintWriter out, Hashtable params, Hashtable fileList,
2573 2587
            String username, String[] groupnames)
2574 2588
    {
2589
        Logger logMetacat = Logger.getLogger(MetaCatServlet.class);
2575 2590
        //PrintWriter out = null;
2576 2591
        //Connection conn = null;
2577 2592
        String action = null;
......
2590 2605

  
2591 2606
        // Make sure we have a docid and datafile
2592 2607
        if (docid != null && fileList.containsKey("datafile")) {
2593
            logMetacat.warn("Uploading data docid: " + docid);
2608
            logMetacat.info("Uploading data docid: " + docid);
2594 2609
            // Get a reference to the file part of the form
2595 2610
            FilePart filePart = (FilePart) fileList.get("datafile");
2596 2611
            String fileName = filePart.getFileName();
2597
            logMetacat.warn("Uploading filename: " + fileName);
2612
            logMetacat.info("Uploading filename: " + fileName);
2598 2613
            // Check if the right file existed in the uploaded data
2599 2614
            if (fileName != null) {
2600 2615

  
......
2679 2694
    private void handleSetAccessAction(PrintWriter out, Hashtable params,
2680 2695
            String username)
2681 2696
    {
2697
        Logger logMetacat = Logger.getLogger(MetaCatServlet.class);
2682 2698
        String[] docList = null;
2683 2699
        String[] principalList = null;
2684 2700
        String[] permissionList = null;
......
2736 2752
        //debug
2737 2753
        if (packageSet != null) {
2738 2754
            for (int i = 0; i < packageSet.size(); i++) {
2739
                logMetacat.info("doctype in package set: "
2755
                logMetacat.debug("doctype in package set: "
2740 2756
                        + (String) packageSet.elementAt(i));
2741 2757
            }
2742 2758
        }
......
2814 2830
    private String getFieldValueForDoc(String accessionNumber, String fieldName)
2815 2831
            throws Exception
2816 2832
    {
2833
        Logger logMetacat = Logger.getLogger(MetaCatServlet.class);
2817 2834
        if (accessionNumber == null || accessionNumber.equals("")
2818 2835
                || fieldName == null || fieldName.equals("")) { throw new Exception(
2819 2836
                "Docid or field name was not specified"); }
......
2871 2888
     */
2872 2889
    private Vector getDocumentList() throws SQLException
2873 2890
    {
2891
        Logger logMetacat = Logger.getLogger(MetaCatServlet.class);
2874 2892
        Vector docList = new Vector();
2875 2893
        PreparedStatement pstmt = null;
2876 2894
        ResultSet rs = null;
......
2965 2983
     */
2966 2984
    private static String appendRev(String docid) throws Exception
2967 2985
    {
2986
        Logger logMetacat = Logger.getLogger(MetaCatServlet.class);
2968 2987
        String newAccNum = null;
2969 2988
        String separator = MetaCatUtil.getOption("accNumSeparator");
2970 2989
        int firstIndex = docid.indexOf(separator);
......
2988 3007
            // in other suituation we don't change the docid
2989 3008
            newAccNum = docid;
2990 3009
        }
2991
        logMetacat.warn("The docid will be read is "+newAccNum);
3010
        logMetacat.debug("The docid will be read is "+newAccNum);
2992 3011
        return newAccNum;
2993 3012
    }
2994 3013
}

Also available in: Unified diff