Revision 1217
Added by Jing Tao almost 22 years ago
MetaCatServlet.java | ||
---|---|---|
105 | 105 |
|
106 | 106 |
private ServletConfig config = null; |
107 | 107 |
private ServletContext context = null; |
108 |
//private Hashtable connectionPool = new Hashtable(); |
|
109 | 108 |
private String resultStyleURL = null; |
110 | 109 |
private String xmlcatalogfile = null; |
111 | 110 |
private String saxparser = null; |
... | ... | |
115 | 114 |
private String htmlpath = null; |
116 | 115 |
private PropertyResourceBundle options = null; |
117 | 116 |
private MetaCatUtil util = null; |
117 |
private DBConnectionPool connPool = null; |
|
118 | 118 |
|
119 | 119 |
/** |
120 | 120 |
* Initialize the servlet by creating appropriate database connections |
... | ... | |
127 | 127 |
System.out.println("MetaCatServlet Initialize"); |
128 | 128 |
|
129 | 129 |
util = new MetaCatUtil(); |
130 |
|
|
131 |
//initial DBConnection pool |
|
132 |
connPool = DBConnectionPool.getInstance(); |
|
130 | 133 |
|
131 | 134 |
// Get the configuration file information |
132 | 135 |
resultStyleURL = util.getOption("resultStyleURL"); |
... | ... | |
137 | 140 |
servletpath = util.getOption("servletpath"); |
138 | 141 |
htmlpath = util.getOption("htmlpath"); |
139 | 142 |
|
140 |
// MOVED IT TO doGet() & doPost() |
|
141 |
// try { |
|
142 |
// // Open a pool of db connections |
|
143 |
// connectionPool = util.getConnectionPool(); |
|
144 |
// } catch (Exception e) { |
|
145 |
// System.err.println("Error creating pool of database connections"); |
|
146 |
// System.err.println(e.getMessage()); |
|
147 |
// } |
|
143 |
|
|
148 | 144 |
} catch ( ServletException ex ) { |
149 | 145 |
throw ex; |
146 |
} catch (SQLException e) { |
|
147 |
MetaCatUtil.debugMessage("Error in MetacatServlet.init: " |
|
148 |
+e.getMessage(), 20); |
|
150 | 149 |
} |
151 | 150 |
} |
152 | 151 |
|
... | ... | |
154 | 153 |
* Close all db connections from the pool |
155 | 154 |
*/ |
156 | 155 |
public void destroy() { |
157 |
|
|
158 |
if (util != null) { |
|
159 |
util.closeConnections(); |
|
160 |
} |
|
156 |
// Close all db connection |
|
157 |
connPool.release(); |
|
161 | 158 |
} |
162 | 159 |
|
163 | 160 |
/** Handle "GET" method requests from HTTP clients */ |
... | ... | |
187 | 184 |
if ( util == null ) { |
188 | 185 |
util = new MetaCatUtil(); |
189 | 186 |
} |
190 |
util.debugMessage("Connection pool size: "+util.getPoolSize(),1); |
|
191 |
/*if ( connectionPool.isEmpty() ) { |
|
192 |
try { |
|
193 |
|
|
194 |
connectionPool = util.getConnectionPool(); |
|
195 |
} catch (Exception e) { |
|
196 |
System.err.println("Error creating pool of database connections in " + |
|
197 |
" MetaCatServlet.handleGetOrPost"); |
|
198 |
System.err.println(e.getMessage()); |
|
199 |
} |
|
200 |
} */ |
|
201 |
// Get a handle to the output stream back to the client |
|
202 |
//PrintWriter pwout = response.getWriter(); |
|
203 |
//response.setContentType("text/html"); |
|
204 |
|
|
205 |
// Deal with forms that are encoded as "multipart/form-data" differently |
|
206 |
// this is mainly used for uploading non-xml files using that may be binary |
|
187 |
MetaCatUtil.debugMessage("Connection pool size: " |
|
188 |
+connPool.getSizeOfDBConnectionPool(),10); |
|
189 |
MetaCatUtil.debugMessage("Free DBConnection number: " |
|
190 |
+connPool.getFreeDBConnectionNumber(), 10); |
|
191 |
//Debug message to print out the method which have a busy DBConnection |
|
192 |
connPool.printMethodNameHavingBusyDBConnection(); |
|
193 |
|
|
207 | 194 |
String ctype = request.getContentType(); |
208 | 195 |
if (ctype != null && ctype.startsWith("multipart/form-data")) { |
209 | 196 |
handleMultipartForm(request, response); |
... | ... | |
215 | 202 |
String[] docid = new String[3]; |
216 | 203 |
Hashtable params = new Hashtable(); |
217 | 204 |
Enumeration paramlist = request.getParameterNames(); |
205 |
|
|
206 |
|
|
218 | 207 |
while (paramlist.hasMoreElements()) { |
208 |
|
|
219 | 209 |
name = (String)paramlist.nextElement(); |
220 | 210 |
value = request.getParameterValues(name); |
221 | 211 |
|
... | ... | |
232 | 222 |
params.put(name,value); |
233 | 223 |
} |
234 | 224 |
|
225 |
|
|
226 |
//handle param is emptpy |
|
227 |
if (params.isEmpty() || params == null) |
|
228 |
{ |
|
229 |
return; |
|
230 |
} |
|
235 | 231 |
//if the user clicked on the input images, decode which image |
236 | 232 |
//was clicked then set the action. |
237 | 233 |
String action = ((String[])params.get("action"))[0]; |
238 |
util.debugMessage("Line 213: Action is: " + action, 1);
|
|
234 |
util.debugMessage("Line 230: Action is: " + action, 1);
|
|
239 | 235 |
|
240 | 236 |
// This block handles session management for the servlet |
241 | 237 |
// by looking up the current session information for all actions |
... | ... | |
247 | 243 |
|
248 | 244 |
// handle login action |
249 | 245 |
if (action.equals("login")) { |
246 |
PrintWriter out = response.getWriter(); |
|
247 |
handleLoginAction(out, params, request, response); |
|
248 |
out.close(); |
|
250 | 249 |
|
251 |
handleLoginAction(response.getWriter(), params, request, response); |
|
252 |
|
|
253 | 250 |
// handle logout action |
254 | 251 |
} else if (action.equals("logout")) { |
252 |
PrintWriter out = response.getWriter(); |
|
253 |
handleLogoutAction(out, params, request, response); |
|
254 |
out.close(); |
|
255 | 255 |
|
256 |
handleLogoutAction(response.getWriter(), params, request, response); |
|
257 |
|
|
258 | 256 |
// aware of session expiration on every request |
259 | 257 |
} else { |
260 | 258 |
|
... | ... | |
280 | 278 |
// Now that we know the session is valid, we can delegate the request |
281 | 279 |
// to a particular action handler |
282 | 280 |
if(action.equals("query")) { |
283 |
handleQuery(response.getWriter(),params,response,username,groupnames); |
|
281 |
PrintWriter out = response.getWriter(); |
|
282 |
handleQuery(out,params,response,username,groupnames); |
|
283 |
out.close(); |
|
284 | 284 |
} else if(action.equals("squery")) { |
285 |
PrintWriter out = response.getWriter(); |
|
285 | 286 |
if(params.containsKey("query")) { |
286 |
handleSQuery(response.getWriter(),params,response,username,groupnames); |
|
287 |
handleSQuery(out, params,response,username,groupnames); |
|
288 |
out.close(); |
|
287 | 289 |
} else { |
288 |
PrintWriter out = response.getWriter(); |
|
289 | 290 |
out.println("Illegal action squery without \"query\" parameter"); |
291 |
out.close(); |
|
290 | 292 |
} |
291 | 293 |
} else if (action.equals("export")) { |
292 | 294 |
|
... | ... | |
299 | 301 |
handleInsertOrUpdateAction(out,params,response,username,groupnames); |
300 | 302 |
} else { |
301 | 303 |
out.println("Permission denied for " + action); |
302 |
} |
|
304 |
} |
|
305 |
out.close(); |
|
303 | 306 |
} else if (action.equals("delete")) { |
304 | 307 |
PrintWriter out = response.getWriter(); |
305 | 308 |
if ( (username != null) && !username.equals("public") ) { |
306 | 309 |
handleDeleteAction(out, params, response, username, groupnames); |
307 | 310 |
} else { |
308 | 311 |
out.println("Permission denied for " + action); |
309 |
} |
|
312 |
} |
|
313 |
out.close(); |
|
310 | 314 |
} else if (action.equals("validate")) { |
311 | 315 |
PrintWriter out = response.getWriter(); |
312 |
handleValidateAction(out, params, response); |
|
316 |
handleValidateAction(out, params, response); |
|
317 |
out.close(); |
|
313 | 318 |
} else if (action.equals("getaccesscontrol")) { |
314 | 319 |
PrintWriter out = response.getWriter(); |
315 | 320 |
handleGetAccessControlAction(out,params,response,username,groupnames); |
321 |
out.close(); |
|
316 | 322 |
} else if (action.equals("getprincipals")) { |
317 | 323 |
PrintWriter out = response.getWriter(); |
318 |
handleGetPrincipalsAction(out, username, password); |
|
324 |
handleGetPrincipalsAction(out, username, password); |
|
325 |
out.close(); |
|
319 | 326 |
} else if (action.equals("getdoctypes")) { |
320 | 327 |
PrintWriter out = response.getWriter(); |
321 |
handleGetDoctypesAction(out, params, response); |
|
328 |
handleGetDoctypesAction(out, params, response); |
|
329 |
out.close(); |
|
322 | 330 |
} else if (action.equals("getdtdschema")) { |
323 | 331 |
PrintWriter out = response.getWriter(); |
324 |
handleGetDTDSchemaAction(out, params, response); |
|
332 |
handleGetDTDSchemaAction(out, params, response); |
|
333 |
out.close(); |
|
325 | 334 |
} else if (action.equals("getdataguide")) { |
326 | 335 |
PrintWriter out = response.getWriter(); |
327 |
handleGetDataGuideAction(out, params, response); |
|
336 |
handleGetDataGuideAction(out, params, response); |
|
337 |
out.close(); |
|
328 | 338 |
} else if (action.equals("getlastdocid")) { |
329 | 339 |
PrintWriter out = response.getWriter(); |
330 |
handleGetMaxDocidAction(out, params, response); |
|
340 |
handleGetMaxDocidAction(out, params, response); |
|
341 |
out.close(); |
|
331 | 342 |
} else if (action.equals("login") || action.equals("logout")) { |
332 | 343 |
} else if (action.equals("protocoltest")) { |
333 | 344 |
String testURL = "metacat://dev.nceas.ucsb.edu/NCEAS.897766.9"; |
... | ... | |
376 | 387 |
out.println("<error>"); |
377 | 388 |
out.println("Error: action not registered. Please report this error."); |
378 | 389 |
out.println("</error>"); |
390 |
out.close(); |
|
379 | 391 |
} |
380 | 392 |
|
381 |
util.closeConnections(); |
|
393 |
//util.closeConnections();
|
|
382 | 394 |
// Close the stream to the client |
383 |
// out.close();
|
|
395 |
//out.close(); |
|
384 | 396 |
} |
385 | 397 |
} |
386 | 398 |
|
... | ... | |
412 | 424 |
response.setContentType("text/xml"); |
413 | 425 |
out.println(sess.getMessage()); |
414 | 426 |
} else { |
415 |
Connection conn = null; |
|
427 |
|
|
416 | 428 |
try { |
417 |
conn = util.getConnection(); |
|
418 |
DBTransform trans = new DBTransform(conn);
|
|
429 |
|
|
430 |
DBTransform trans = new DBTransform(); |
|
419 | 431 |
response.setContentType("text/html"); |
420 | 432 |
trans.transformXMLDocument(sess.getMessage(), "-//NCEAS//login//EN", |
421 | 433 |
"-//W3C//HTML//EN", qformat, out); |
422 |
util.returnConnection(conn); |
|
434 |
|
|
423 | 435 |
} catch(Exception e) { |
424 |
util.returnConnection(conn); |
|
436 |
|
|
437 |
MetaCatUtil.debugMessage("Error in MetaCatServlet.handleLoginAction: " |
|
438 |
+e.getMessage(), 30); |
|
425 | 439 |
} |
426 | 440 |
|
427 | 441 |
// any output is returned |
... | ... | |
452 | 466 |
response.setContentType("text/xml"); |
453 | 467 |
out.println(output.toString()); |
454 | 468 |
} else { |
455 |
Connection conn = null; |
|
469 |
|
|
456 | 470 |
try { |
457 |
conn = util.getConnection(); |
|
458 |
DBTransform trans = new DBTransform(conn);
|
|
471 |
|
|
472 |
DBTransform trans = new DBTransform(); |
|
459 | 473 |
response.setContentType("text/html"); |
460 | 474 |
trans.transformXMLDocument(output.toString(), "-//NCEAS//login//EN", |
461 | 475 |
"-//W3C//HTML//EN", qformat, out); |
462 |
util.returnConnection(conn); |
|
476 |
|
|
463 | 477 |
} catch(Exception e) { |
464 |
util.returnConnection(conn); |
|
478 |
|
|
479 |
MetaCatUtil.debugMessage("Error in MetaCatServlet.handleLogoutAction" |
|
480 |
+e.getMessage(), 30); |
|
465 | 481 |
} |
466 | 482 |
} |
467 | 483 |
} |
... | ... | |
566 | 582 |
private Hashtable runQuery(String xmlquery, String user, String[] groups) |
567 | 583 |
{ |
568 | 584 |
Hashtable doclist=null; |
569 |
Connection conn = null; |
|
585 |
|
|
570 | 586 |
try |
571 | 587 |
{ |
572 |
conn = util.getConnection(); |
|
573 |
DBQuery queryobj = new DBQuery(conn, saxparser);
|
|
588 |
|
|
589 |
DBQuery queryobj = new DBQuery(saxparser); |
|
574 | 590 |
doclist = queryobj.findDocuments(new StringReader(xmlquery),user,groups); |
575 |
util.returnConnection(conn); |
|
591 |
|
|
576 | 592 |
return doclist; |
577 | 593 |
} |
578 | 594 |
catch (Exception e) |
579 | 595 |
{ |
580 |
util.returnConnection(conn); |
|
581 |
util.debugMessage("Error in MetacatServlet.runQuery: " + e.getMessage()); |
|
596 |
|
|
597 |
MetaCatUtil.debugMessage("Error in MetacatServlet.runQuery: " |
|
598 |
+ e.getMessage(), 30); |
|
582 | 599 |
doclist = null; |
583 | 600 |
return doclist; |
584 | 601 |
} |
... | ... | |
597 | 614 |
HttpServletResponse response, |
598 | 615 |
PrintWriter out, String qformat) |
599 | 616 |
{ |
600 |
Connection conn = null; |
|
617 |
|
|
601 | 618 |
try { |
602 |
conn = util.getConnection(); |
|
603 |
DBTransform trans = new DBTransform(conn);
|
|
619 |
|
|
620 |
DBTransform trans = new DBTransform(); |
|
604 | 621 |
response.setContentType("text/html"); |
605 | 622 |
trans.transformXMLDocument(resultdoc, "-//NCEAS//resultset//EN", |
606 | 623 |
"-//W3C//HTML//EN", qformat, out); |
607 |
util.returnConnection(conn); |
|
624 |
|
|
608 | 625 |
} |
609 | 626 |
catch(Exception e) |
610 | 627 |
{ |
611 |
util.returnConnection(conn); |
|
628 |
|
|
629 |
MetaCatUtil.debugMessage("Error in MetaCatServlet.transformResultset:" |
|
630 |
+e.getMessage(), 30); |
|
612 | 631 |
} |
613 | 632 |
} |
614 | 633 |
|
... | ... | |
662 | 681 |
ZipOutputStream zOut = null; |
663 | 682 |
DocumentImpl docImpls=null; |
664 | 683 |
DBQuery queryObj=null; |
665 |
Connection conn = null; |
|
684 |
|
|
666 | 685 |
String[] docs = new String[10]; |
667 | 686 |
String docId = ""; |
668 | 687 |
|
... | ... | |
673 | 692 |
docs = (String[])params.get("docid"); |
674 | 693 |
} |
675 | 694 |
|
676 |
//get the connection to database |
|
677 |
conn = util.getConnection(); |
|
678 |
queryObj = new DBQuery(conn, saxparser);//"saxparser" have to use though |
|
695 |
|
|
696 |
queryObj = new DBQuery(saxparser);//"saxparser" have to use though |
|
679 | 697 |
//it is not standard |
680 | 698 |
docId=docs[0]; |
681 | 699 |
out = response.getOutputStream(); |
... | ... | |
708 | 726 |
} |
709 | 727 |
catch (IOException ioe) |
710 | 728 |
{ |
711 |
util.debugMessage("Problem with the servlet output " +
|
|
729 |
MetaCatUtil.debugMessage("Problem with the servlet output " +
|
|
712 | 730 |
"in MetacatServlet.handleReadAction: " + |
713 |
ioe.getMessage()); |
|
731 |
ioe.getMessage(), 30);
|
|
714 | 732 |
|
715 | 733 |
|
716 | 734 |
} |
717 | 735 |
|
718 |
util.debugMessage("Error in MetacatServlet.handleReadAction: " +
|
|
719 |
e.getMessage()); |
|
736 |
MetaCatUtil.debugMessage("Error in MetacatServlet.handleReadAction: " +
|
|
737 |
e.getMessage(), 30);
|
|
720 | 738 |
|
721 | 739 |
}//catch |
722 |
finally |
|
723 |
{ |
|
724 |
util.returnConnection(conn); |
|
725 |
} |
|
740 |
|
|
726 | 741 |
|
727 | 742 |
}//handleExportAction |
728 | 743 |
|
... | ... | |
853 | 868 |
throws ClassNotFoundException, IOException, SQLException, |
854 | 869 |
McdbException, Exception |
855 | 870 |
{ |
856 |
Connection conn = null; |
|
871 |
|
|
857 | 872 |
try { |
858 |
conn = util.getConnection(); |
|
859 |
DocumentImpl doc = new DocumentImpl(conn, docid); |
|
873 |
|
|
860 | 874 |
|
875 |
DocumentImpl doc = new DocumentImpl(docid); |
|
876 |
|
|
861 | 877 |
//check the permission for read |
862 |
if (!doc.hasReadPermission(conn, user, groups, docid))
|
|
878 |
if (!doc.hasReadPermission(user, groups, docid)) |
|
863 | 879 |
{ |
864 | 880 |
Exception e = new Exception("User " + user + " does not have permission" |
865 | 881 |
+" to read the document with the docid " + docid); |
866 |
util.returnConnection(conn); |
|
882 |
|
|
867 | 883 |
throw e; |
868 | 884 |
} |
869 | 885 |
|
... | ... | |
915 | 931 |
} else { |
916 | 932 |
// this is metadata doc |
917 | 933 |
if ( qformat.equals("xml") ) { |
934 |
|
|
918 | 935 |
// set content type first |
919 | 936 |
response.setContentType("text/xml"); //MIME type |
920 | 937 |
PrintWriter out = response.getWriter(); |
... | ... | |
926 | 943 |
// Look up the document type |
927 | 944 |
String doctype = doc.getDoctype(); |
928 | 945 |
// Transform the document to the new doctype |
929 |
DBTransform dbt = new DBTransform(conn);
|
|
946 |
DBTransform dbt = new DBTransform(); |
|
930 | 947 |
dbt.transformXMLDocument(doc.toString(), |
931 | 948 |
doctype,"-//W3C//HTML//EN", qformat, out); |
932 | 949 |
} |
933 | 950 |
|
934 | 951 |
} |
935 |
} finally { |
|
936 |
util.returnConnection(conn); |
|
952 |
} catch (Exception except) { |
|
953 |
throw except; |
|
954 |
|
|
937 | 955 |
} |
938 | 956 |
|
939 | 957 |
} |
... | ... | |
1017 | 1035 |
} catch (MalformedURLException mue) { |
1018 | 1036 |
|
1019 | 1037 |
// this is metacat doc (data file or metadata doc) |
1020 |
Connection conn = null; |
|
1038 |
|
|
1021 | 1039 |
try { |
1022 |
conn = util.getConnection(); |
|
1023 |
DocumentImpl doc = new DocumentImpl(conn, docid);
|
|
1040 |
|
|
1041 |
DocumentImpl doc = new DocumentImpl(docid); |
|
1024 | 1042 |
|
1025 | 1043 |
//check the permission for read |
1026 |
if (!doc.hasReadPermission(conn, user, groups, docid))
|
|
1044 |
if (!doc.hasReadPermission(user, groups, docid)) |
|
1027 | 1045 |
{ |
1028 | 1046 |
Exception e = new Exception("User " + user + " does not have " |
1029 | 1047 |
+"permission to read the document with the docid " + docid); |
1030 |
util.returnConnection(conn); |
|
1048 |
|
|
1031 | 1049 |
throw e; |
1032 | 1050 |
} |
1033 | 1051 |
|
... | ... | |
1063 | 1081 |
zout.write(bytestring, 0, bytestring.length); |
1064 | 1082 |
zout.closeEntry(); |
1065 | 1083 |
} |
1066 |
} finally { |
|
1067 |
util.returnConnection(conn); |
|
1084 |
} catch (Exception except) { |
|
1085 |
throw except; |
|
1086 |
|
|
1068 | 1087 |
} |
1069 | 1088 |
|
1070 | 1089 |
} |
... | ... | |
1077 | 1096 |
throws ClassNotFoundException, IOException, SQLException, |
1078 | 1097 |
McdbException, Exception |
1079 | 1098 |
{ |
1080 |
Connection conn = null; |
|
1099 |
|
|
1100 |
PrintWriter out =null; |
|
1081 | 1101 |
try { |
1082 |
conn = util.getConnection(); |
|
1083 |
|
|
1084 |
Object[] abstracts = DBQuery.getNodeContent(abstractpath, docid, conn); |
|
1085 |
|
|
1102 |
|
|
1086 | 1103 |
response.setContentType("text/html"); //MIME type |
1087 |
PrintWriter out = response.getWriter(); |
|
1104 |
out = response.getWriter(); |
|
1105 |
Object[] abstracts = DBQuery.getNodeContent(abstractpath, docid); |
|
1088 | 1106 |
out.println("<html><head><title>Abstract</title></head>"); |
1089 | 1107 |
out.println("<body bgcolor=\"white\"><h1>Abstract</h1>"); |
1090 | 1108 |
for (int i=0; i<abstracts.length; i++) { |
... | ... | |
1092 | 1110 |
} |
1093 | 1111 |
out.println("</body></html>"); |
1094 | 1112 |
|
1095 |
} finally { |
|
1096 |
util.returnConnection(conn); |
|
1113 |
} catch (Exception e) { |
|
1114 |
out.println("<?xml version=\"1.0\"?>"); |
|
1115 |
out.println("<error>"); |
|
1116 |
out.println(e.getMessage()); |
|
1117 |
out.println("</error>"); |
|
1118 |
|
|
1119 |
|
|
1097 | 1120 |
} |
1098 | 1121 |
} |
1099 | 1122 |
// END OF READ SECTION |
... | ... | |
1106 | 1129 |
private void handleInsertOrUpdateAction(PrintWriter out, Hashtable params, |
1107 | 1130 |
HttpServletResponse response, String user, String[] groups) { |
1108 | 1131 |
|
1109 |
Connection conn = null; |
|
1132 |
DBConnection dbConn = null; |
|
1133 |
int serialNumber = -1; |
|
1110 | 1134 |
|
1111 | 1135 |
try { |
1112 | 1136 |
// Get the document indicated |
... | ... | |
1145 | 1169 |
} else if (action[0].equals("update")) { |
1146 | 1170 |
doAction = "UPDATE"; |
1147 | 1171 |
} |
1148 |
|
|
1149 |
try { |
|
1172 |
|
|
1173 |
try |
|
1174 |
{ |
|
1150 | 1175 |
// get a connection from the pool |
1151 |
conn = util.getConnection(); |
|
1152 |
|
|
1176 |
dbConn=DBConnectionPool. |
|
1177 |
getDBConnection("MetaCatServlet.handleInsertOrUpdateAction"); |
|
1178 |
serialNumber=dbConn.getCheckOutSerialNumber(); |
|
1179 |
|
|
1153 | 1180 |
// write the document to the database |
1154 |
try { |
|
1181 |
try |
|
1182 |
{ |
|
1155 | 1183 |
String accNumber = docid[0]; |
1156 |
if (accNumber.equals("")) { |
|
1184 |
if (accNumber.equals("")) |
|
1185 |
{ |
|
1157 | 1186 |
accNumber = null; |
1158 |
} |
|
1159 |
newdocid = DocumentImpl.write(conn, xml, pub, dtd, doAction,
|
|
1187 |
}//if
|
|
1188 |
newdocid = DocumentImpl.write(dbConn, xml, pub, dtd, doAction,
|
|
1160 | 1189 |
accNumber, user, groups, validate); |
1161 |
} catch (NullPointerException npe) { |
|
1162 |
newdocid = DocumentImpl.write(conn, xml, pub, dtd, doAction, |
|
1190 |
|
|
1191 |
}//try |
|
1192 |
catch (NullPointerException npe) |
|
1193 |
{ |
|
1194 |
newdocid = DocumentImpl.write(dbConn, xml, pub, dtd, doAction, |
|
1163 | 1195 |
null, user, groups, validate); |
1164 |
} |
|
1165 |
} finally { |
|
1166 |
util.returnConnection(conn); |
|
1196 |
}//catch |
|
1197 |
}//try |
|
1198 |
finally |
|
1199 |
{ |
|
1200 |
// Return db connection |
|
1201 |
DBConnectionPool.returnDBConnection(dbConn, serialNumber); |
|
1167 | 1202 |
} |
1168 | 1203 |
|
1169 | 1204 |
// set content type and other response header fields first |
... | ... | |
1272 | 1307 |
HttpServletResponse response, String user, String[] groups) { |
1273 | 1308 |
|
1274 | 1309 |
String[] docid = (String[])params.get("docid"); |
1275 |
Connection conn = null; |
|
1276 |
|
|
1310 |
|
|
1277 | 1311 |
// delete the document from the database |
1278 | 1312 |
try { |
1279 |
// get a connection from the pool |
|
1280 |
conn = util.getConnection(); |
|
1313 |
|
|
1281 | 1314 |
// NOTE -- NEED TO TEST HERE |
1282 | 1315 |
// FOR EXISTENCE OF DOCID PARAM |
1283 | 1316 |
// BEFORE ACCESSING ARRAY |
1284 | 1317 |
try { |
1285 |
DocumentImpl.delete(conn, docid[0], user, groups);
|
|
1318 |
DocumentImpl.delete(docid[0], user, groups); |
|
1286 | 1319 |
response.setContentType("text/xml"); |
1287 | 1320 |
out.println("<?xml version=\"1.0\"?>"); |
1288 | 1321 |
out.println("<success>"); |
... | ... | |
1302 | 1335 |
out.println("<error>"); |
1303 | 1336 |
out.println(e.getMessage()); |
1304 | 1337 |
out.println("</error>"); |
1305 |
} finally { |
|
1306 |
util.returnConnection(conn); |
|
1307 |
} |
|
1338 |
} |
|
1308 | 1339 |
} |
1309 | 1340 |
// END OF DELETE SECTION |
1310 | 1341 |
|
... | ... | |
1317 | 1348 |
|
1318 | 1349 |
// Get the document indicated |
1319 | 1350 |
String valtext = null; |
1351 |
DBConnection dbConn = null; |
|
1352 |
int serialNumber = -1; |
|
1320 | 1353 |
|
1321 | 1354 |
try { |
1322 | 1355 |
valtext = ((String[])params.get("valtext"))[0]; |
1323 | 1356 |
} catch (Exception nullpe) { |
1324 | 1357 |
|
1325 |
Connection conn = null; |
|
1358 |
|
|
1326 | 1359 |
String docid = null; |
1327 | 1360 |
try { |
1328 | 1361 |
// Find the document id number |
1329 | 1362 |
docid = ((String[])params.get("docid"))[0]; |
1330 | 1363 |
|
1331 |
// get a connection from the pool |
|
1332 |
conn = util.getConnection(); |
|
1333 |
|
|
1364 |
|
|
1334 | 1365 |
// Get the document indicated from the db |
1335 |
DocumentImpl xmldoc = new DocumentImpl(conn, docid);
|
|
1366 |
DocumentImpl xmldoc = new DocumentImpl(docid); |
|
1336 | 1367 |
valtext = xmldoc.toString(); |
1337 | 1368 |
|
1338 | 1369 |
} catch (NullPointerException npe) { |
1339 | 1370 |
response.setContentType("text/xml"); |
1340 | 1371 |
out.println("<error>Error getting document ID: " + docid + "</error>"); |
1341 |
if ( conn != null ) { util.returnConnection(conn); } |
|
1372 |
//if ( conn != null ) { util.returnConnection(conn); }
|
|
1342 | 1373 |
return; |
1343 | 1374 |
} catch (Exception e) { |
1344 | 1375 |
response.setContentType("text/html"); |
1345 | 1376 |
out.println(e.getMessage()); |
1346 |
} finally { |
|
1347 |
util.returnConnection(conn); |
|
1348 |
} |
|
1377 |
} |
|
1349 | 1378 |
} |
1350 | 1379 |
|
1351 |
Connection conn = null; |
|
1380 |
|
|
1352 | 1381 |
try { |
1353 | 1382 |
// get a connection from the pool |
1354 |
conn = util.getConnection(); |
|
1355 |
DBValidate valobj = new DBValidate(saxparser,conn); |
|
1383 |
dbConn=DBConnectionPool. |
|
1384 |
getDBConnection("MetaCatServlet.handleValidateAction"); |
|
1385 |
serialNumber=dbConn.getCheckOutSerialNumber(); |
|
1386 |
DBValidate valobj = new DBValidate(saxparser,dbConn); |
|
1356 | 1387 |
boolean valid = valobj.validateString(valtext); |
1357 | 1388 |
|
1358 | 1389 |
// set content type and other response header fields first |
... | ... | |
1367 | 1398 |
response.setContentType("text/html"); |
1368 | 1399 |
out.println(e.getMessage()); |
1369 | 1400 |
} finally { |
1370 |
util.returnConnection(conn); |
|
1401 |
// Return db connection |
|
1402 |
DBConnectionPool.returnDBConnection(dbConn, serialNumber); |
|
1371 | 1403 |
} |
1372 | 1404 |
} |
1373 | 1405 |
// END OF VALIDATE SECTION |
... | ... | |
1382 | 1414 |
HttpServletResponse response, |
1383 | 1415 |
String username, String[] groupnames) { |
1384 | 1416 |
|
1385 |
Connection conn = null; |
|
1417 |
DBConnection dbConn = null; |
|
1418 |
int serialNumber = -1; |
|
1386 | 1419 |
String docid = ((String[])params.get("docid"))[0]; |
1387 | 1420 |
|
1388 | 1421 |
try { |
1389 | 1422 |
|
1390 | 1423 |
// get connection from the pool |
1391 |
conn = util.getConnection(); |
|
1392 |
AccessControlList aclobj = new AccessControlList(conn); |
|
1424 |
dbConn=DBConnectionPool. |
|
1425 |
getDBConnection("MetaCatServlet.handleGetAccessControlAction"); |
|
1426 |
serialNumber=dbConn.getCheckOutSerialNumber(); |
|
1427 |
AccessControlList aclobj = new AccessControlList(dbConn); |
|
1393 | 1428 |
String acltext = aclobj.getACL(docid, username, groupnames); |
1394 | 1429 |
out.println(acltext); |
1395 | 1430 |
|
... | ... | |
1399 | 1434 |
out.println(e.getMessage()); |
1400 | 1435 |
out.println("</error>"); |
1401 | 1436 |
} finally { |
1402 |
util.returnConnection(conn); |
|
1437 |
// Retrun db connection to pool |
|
1438 |
DBConnectionPool.returnDBConnection(dbConn, serialNumber); |
|
1403 | 1439 |
} |
1404 | 1440 |
|
1405 | 1441 |
} |
... | ... | |
1411 | 1447 |
private void handleGetPrincipalsAction(PrintWriter out, String user, |
1412 | 1448 |
String password) { |
1413 | 1449 |
|
1414 |
Connection conn = null; |
|
1415 |
|
|
1450 |
|
|
1416 | 1451 |
try { |
1417 | 1452 |
|
1418 |
// get connection from the pool |
|
1453 |
|
|
1419 | 1454 |
AuthSession auth = new AuthSession(); |
1420 | 1455 |
String principals = auth.getPrincipals(user, password); |
1421 | 1456 |
out.println(principals); |
... | ... | |
1425 | 1460 |
out.println("<error>"); |
1426 | 1461 |
out.println(e.getMessage()); |
1427 | 1462 |
out.println("</error>"); |
1428 |
} finally { |
|
1429 |
util.returnConnection(conn); |
|
1430 |
} |
|
1463 |
} |
|
1431 | 1464 |
|
1432 | 1465 |
} |
1433 | 1466 |
|
... | ... | |
1438 | 1471 |
private void handleGetDoctypesAction(PrintWriter out, Hashtable params, |
1439 | 1472 |
HttpServletResponse response) { |
1440 | 1473 |
|
1441 |
Connection conn = null; |
|
1442 |
|
|
1474 |
|
|
1443 | 1475 |
try { |
1444 | 1476 |
|
1445 |
// get connection from the pool |
|
1446 |
conn = util.getConnection(); |
|
1447 |
DBUtil dbutil = new DBUtil(conn); |
|
1477 |
|
|
1478 |
DBUtil dbutil = new DBUtil(); |
|
1448 | 1479 |
String doctypes = dbutil.readDoctypes(); |
1449 | 1480 |
out.println(doctypes); |
1450 | 1481 |
|
... | ... | |
1453 | 1484 |
out.println("<error>"); |
1454 | 1485 |
out.println(e.getMessage()); |
1455 | 1486 |
out.println("</error>"); |
1456 |
} finally { |
|
1457 |
util.returnConnection(conn); |
|
1458 |
} |
|
1487 |
} |
|
1459 | 1488 |
|
1460 | 1489 |
} |
1461 | 1490 |
|
... | ... | |
1466 | 1495 |
private void handleGetDTDSchemaAction(PrintWriter out, Hashtable params, |
1467 | 1496 |
HttpServletResponse response) { |
1468 | 1497 |
|
1469 |
Connection conn = null; |
|
1498 |
|
|
1470 | 1499 |
String doctype = null; |
1471 | 1500 |
String[] doctypeArr = (String[])params.get("doctype"); |
1472 | 1501 |
|
... | ... | |
1478 | 1507 |
|
1479 | 1508 |
try { |
1480 | 1509 |
|
1481 |
// get connection from the pool |
|
1482 |
conn = util.getConnection(); |
|
1483 |
DBUtil dbutil = new DBUtil(conn); |
|
1510 |
|
|
1511 |
DBUtil dbutil = new DBUtil(); |
|
1484 | 1512 |
String dtdschema = dbutil.readDTDSchema(doctype); |
1485 | 1513 |
out.println(dtdschema); |
1486 | 1514 |
|
... | ... | |
1489 | 1517 |
out.println("<error>"); |
1490 | 1518 |
out.println(e.getMessage()); |
1491 | 1519 |
out.println("</error>"); |
1492 |
} finally { |
|
1493 |
util.returnConnection(conn); |
|
1494 |
} |
|
1520 |
} |
|
1495 | 1521 |
|
1496 | 1522 |
} |
1497 | 1523 |
|
... | ... | |
1502 | 1528 |
private void handleGetDataGuideAction(PrintWriter out, Hashtable params, |
1503 | 1529 |
HttpServletResponse response) { |
1504 | 1530 |
|
1505 |
Connection conn = null; |
|
1531 |
|
|
1506 | 1532 |
String doctype = null; |
1507 | 1533 |
String[] doctypeArr = (String[])params.get("doctype"); |
1508 | 1534 |
|
... | ... | |
1514 | 1540 |
|
1515 | 1541 |
try { |
1516 | 1542 |
|
1517 |
// get connection from the pool |
|
1518 |
conn = util.getConnection(); |
|
1519 |
DBUtil dbutil = new DBUtil(conn); |
|
1543 |
|
|
1544 |
DBUtil dbutil = new DBUtil(); |
|
1520 | 1545 |
String dataguide = dbutil.readDataGuide(doctype); |
1521 | 1546 |
out.println(dataguide); |
1522 | 1547 |
|
... | ... | |
1525 | 1550 |
out.println("<error>"); |
1526 | 1551 |
out.println(e.getMessage()); |
1527 | 1552 |
out.println("</error>"); |
1528 |
} finally { |
|
1529 |
util.returnConnection(conn); |
|
1530 |
} |
|
1553 |
} |
|
1531 | 1554 |
|
1532 | 1555 |
} |
1533 | 1556 |
|
... | ... | |
1538 | 1561 |
private void handleGetMaxDocidAction(PrintWriter out, Hashtable params, |
1539 | 1562 |
HttpServletResponse response) { |
1540 | 1563 |
|
1541 |
Connection conn = null; |
|
1564 |
|
|
1542 | 1565 |
String scope = ((String[])params.get("scope"))[0]; |
1543 | 1566 |
if (scope == null) { |
1544 | 1567 |
scope = ((String[])params.get("username"))[0]; |
... | ... | |
1546 | 1569 |
|
1547 | 1570 |
try { |
1548 | 1571 |
|
1549 |
// get connection from the pool |
|
1550 |
conn = util.getConnection(); |
|
1551 |
DBUtil dbutil = new DBUtil(conn); |
|
1572 |
|
|
1573 |
DBUtil dbutil = new DBUtil(); |
|
1552 | 1574 |
String lastDocid = dbutil.getMaxDocid(scope); |
1553 | 1575 |
out.println("<?xml version=\"1.0\"?>"); |
1554 | 1576 |
out.println("<lastDocid>"); |
... | ... | |
1561 | 1583 |
out.println("<error>"); |
1562 | 1584 |
out.println(e.getMessage()); |
1563 | 1585 |
out.println("</error>"); |
1564 |
} finally { |
|
1565 |
util.returnConnection(conn); |
|
1566 |
} |
|
1586 |
} |
|
1567 | 1587 |
|
1568 | 1588 |
} |
1569 | 1589 |
|
... | ... | |
1674 | 1694 |
out.println("Error: action not registered. Please report this error."); |
1675 | 1695 |
out.println("</error>"); |
1676 | 1696 |
} |
1697 |
out.close(); |
|
1677 | 1698 |
} |
1678 | 1699 |
|
1679 | 1700 |
/** |
... | ... | |
1686 | 1707 |
String username, String[] groupnames) |
1687 | 1708 |
{ |
1688 | 1709 |
PrintWriter out = null; |
1689 |
Connection conn = null; |
|
1710 |
//Connection conn = null;
|
|
1690 | 1711 |
String action = null; |
1691 | 1712 |
String docid = null; |
1692 | 1713 |
|
... | ... | |
1734 | 1755 |
// force replcation data file if metacat was configured |
1735 | 1756 |
if (ReplicationHandler.getServerLocation(docid)==1) |
1736 | 1757 |
{//local host document |
1737 |
conn=util.getConnection(); |
|
1758 |
//conn=util.getConnection();
|
|
1738 | 1759 |
ForceReplicationHandler frh = new ForceReplicationHandler |
1739 |
(docid, "insert", false, ReplicationHandler.buildServerList(conn));
|
|
1740 |
conn.close(); |
|
1760 |
(docid, "insert", false, ReplicationHandler.buildServerList()); |
|
1761 |
//conn.close();
|
|
1741 | 1762 |
}//if |
1742 | 1763 |
else |
1743 | 1764 |
{ |
... | ... | |
1745 | 1766 |
if ((util.getOption("hub")).equals("super")) |
1746 | 1767 |
{ |
1747 | 1768 |
ForceReplicationHandler frh = new ForceReplicationHandler |
1748 |
(docid,true, ReplicationHandler.buildServerList(conn));
|
|
1749 |
conn.close(); |
|
1769 |
(docid,true, ReplicationHandler.buildServerList()); |
|
1770 |
//conn.close();
|
|
1750 | 1771 |
}//if |
1751 | 1772 |
else |
1752 | 1773 |
{ |
... | ... | |
1773 | 1794 |
out.println(e.getMessage()); |
1774 | 1795 |
out.println("</error>"); |
1775 | 1796 |
} |
1776 |
finally |
|
1777 |
{ |
|
1778 |
try |
|
1779 |
{ |
|
1780 |
conn.close(); |
|
1781 |
} |
|
1782 |
catch (SQLException ee) |
|
1783 |
{} |
|
1784 |
} |
|
1797 |
|
|
1785 | 1798 |
} |
1786 | 1799 |
else |
1787 | 1800 |
{ |
Also available in: Unified diff
Merge DBConnection branch to head.