Revision 204
Added by Matt Jones almost 24 years ago
MetaCatServlet.java | ||
---|---|---|
44 | 44 |
import oracle.xml.parser.v2.XMLDocumentFragment; |
45 | 45 |
import oracle.xml.parser.v2.XSLProcessor; |
46 | 46 |
|
47 |
import org.xml.sax.SAXException; |
|
48 |
|
|
47 | 49 |
/** |
48 | 50 |
* A metadata catalog server implemented as a Java Servlet |
49 | 51 |
* |
... | ... | |
363 | 365 |
private void handleInsertOrUpdateAction(PrintWriter out, Hashtable params, |
364 | 366 |
HttpServletResponse response) { |
365 | 367 |
|
366 |
// Get the document indicated |
|
367 |
String[] doctext = (String[])params.get("doctext"); |
|
368 |
StringReader xml = new StringReader(doctext[0]); |
|
368 |
try { |
|
369 |
// Get the document indicated |
|
370 |
String[] doctext = (String[])params.get("doctext"); |
|
371 |
StringReader xml = null; |
|
372 |
try { |
|
373 |
xml = new StringReader(doctext[0]); |
|
369 | 374 |
|
370 |
String[] action = (String[])params.get("action"); |
|
371 |
String[] docid = (String[])params.get("docid"); |
|
372 |
String newdocid = null; |
|
375 |
String[] action = (String[])params.get("action");
|
|
376 |
String[] docid = (String[])params.get("docid");
|
|
377 |
String newdocid = null;
|
|
373 | 378 |
|
374 |
String doAction = null; |
|
375 |
if (action[0].equals("insert")) { |
|
376 |
doAction = "INSERT"; |
|
377 |
} else if (action[0].equals("update")) { |
|
378 |
doAction = "UPDATE"; |
|
379 |
} |
|
379 |
String doAction = null;
|
|
380 |
if (action[0].equals("insert")) {
|
|
381 |
doAction = "INSERT";
|
|
382 |
} else if (action[0].equals("update")) {
|
|
383 |
doAction = "UPDATE";
|
|
384 |
}
|
|
380 | 385 |
|
381 |
// write the document to the database |
|
382 |
try { |
|
383 |
DBWriter dbw = new DBWriter(conn, saxparser); |
|
384 |
// NOTE -- NEED TO TEST HERE |
|
385 |
// FOR EXISTENCE OF PARAM |
|
386 |
// BEFORE ACCESSING ARRAY |
|
387 |
try { |
|
388 |
String accNumber = docid[0]; |
|
389 |
response.setContentType("text/plain"); |
|
390 |
out.println("Accnumber param is: " + accNumber); |
|
391 |
out.println("doAction param is: " + doAction); |
|
392 |
if (accNumber.equals("")) { |
|
393 |
accNumber = null; |
|
394 |
out.println("AccNumber now set to null."); |
|
386 |
// write the document to the database |
|
387 |
DBWriter dbw = new DBWriter(conn, saxparser); |
|
388 |
|
|
389 |
try { |
|
390 |
String accNumber = docid[0]; |
|
391 |
if (accNumber.equals("")) { |
|
392 |
accNumber = null; |
|
393 |
} |
|
394 |
newdocid = dbw.write(xml, doAction, accNumber); |
|
395 |
} catch (NullPointerException npe) { |
|
396 |
newdocid = dbw.write(xml, doAction, null); |
|
395 | 397 |
} |
396 |
newdocid = dbw.write(xml, doAction, accNumber); |
|
398 |
|
|
399 |
// set content type and other response header fields first |
|
400 |
response.setContentType("text/xml"); |
|
401 |
out.println("<?xml version=\"1.0\"?>"); |
|
402 |
out.println("<success>"); |
|
403 |
out.println("<docid>" + newdocid + "</docid>"); |
|
404 |
out.println("</success>"); |
|
405 |
|
|
397 | 406 |
} catch (NullPointerException npe) { |
398 |
newdocid = dbw.write(xml, doAction, null); |
|
407 |
response.setContentType("text/xml"); |
|
408 |
out.println("<?xml version=\"1.0\"?>"); |
|
409 |
out.println("<error>"); |
|
410 |
out.println(npe.getMessage()); |
|
411 |
out.println("</error>"); |
|
399 | 412 |
} |
400 |
|
|
401 |
} catch (SQLException e1) { |
|
402 |
out.println("Error 1 loading document:\n" + e1.getMessage()); |
|
403 |
}catch (IOException e2) { |
|
404 |
out.println("Error 2 loading document:\n" + e2.getMessage()); |
|
405 |
}catch (ClassNotFoundException e3) { |
|
406 |
out.println("Error 3 loading document:\n" + e3.getMessage()); |
|
407 |
}catch (Exception e4) { |
|
408 |
out.println("Error 4 loading document:\n" + e4.getMessage()); |
|
409 |
e4.printStackTrace(out); |
|
413 |
} catch (Exception e) { |
|
414 |
response.setContentType("text/xml"); |
|
415 |
out.println("<?xml version=\"1.0\"?>"); |
|
416 |
out.println("<error>"); |
|
417 |
out.println(e.getMessage()); |
|
418 |
if (e instanceof SAXException) { |
|
419 |
Exception e2 = ((SAXException)e).getException(); |
|
420 |
out.println("<error>"); |
|
421 |
out.println(e2.getMessage()); |
|
422 |
out.println("</error>"); |
|
423 |
} |
|
424 |
//e.printStackTrace(out); |
|
425 |
out.println("</error>"); |
|
410 | 426 |
} |
411 |
|
|
412 |
// set content type and other response header fields first |
|
413 |
//response.setContentType("text/xml"); |
|
414 |
out.println("<docid>" + newdocid + "</docid>"); |
|
415 | 427 |
} |
416 | 428 |
|
417 | 429 |
/** |
... | ... | |
431 | 443 |
// BEFORE ACCESSING ARRAY |
432 | 444 |
try { |
433 | 445 |
dbw.delete(docid[0]); |
434 |
response.setContentType("text/html"); |
|
446 |
response.setContentType("text/xml"); |
|
447 |
out.println("<?xml version=\"1.0\"?>"); |
|
448 |
out.println("<success>"); |
|
435 | 449 |
out.println("Document deleted."); |
450 |
out.println("</success>"); |
|
436 | 451 |
} catch (AccessionNumberException ane) { |
437 |
response.setContentType("text/html"); |
|
438 |
out.println("ERROR deleting document!!!<br />"); |
|
452 |
response.setContentType("text/xml"); |
|
453 |
out.println("<?xml version=\"1.0\"?>"); |
|
454 |
out.println("<error>"); |
|
455 |
out.println("Error deleting document!!!"); |
|
439 | 456 |
out.println(ane.getMessage()); |
457 |
out.println("</error>"); |
|
440 | 458 |
} |
441 |
} catch (SQLException e1) {
|
|
442 |
out.println("Error 1 loading document:<p>\n" + e1.getMessage());
|
|
443 |
}catch (IOException e2) {
|
|
444 |
out.println("Error 2 loading document:<p>\n" + e2.getMessage());
|
|
445 |
}catch (ClassNotFoundException e3) {
|
|
446 |
out.println("Error 3 loading document:<p>\n" + e3.getMessage());
|
|
459 |
} catch (Exception e) {
|
|
460 |
response.setContentType("text/xml");
|
|
461 |
out.println("<?xml version=\"1.0\"?>");
|
|
462 |
out.println("<error>");
|
|
463 |
out.println(e.getMessage());
|
|
464 |
out.println("</error>");
|
|
447 | 465 |
} |
448 | 466 |
} |
449 | 467 |
|
... | ... | |
556 | 574 |
|
557 | 575 |
/** |
558 | 576 |
* '$Log$ |
577 |
* 'Revision 1.31 2000/06/26 10:35:05 jones |
|
578 |
* 'Merged in substantial changes to DBWriter and associated classes and to |
|
579 |
* 'the MetaCatServlet in order to accomodate the new UPDATE and DELETE |
|
580 |
* 'functions. The command line tools and the parameters for the |
|
581 |
* 'servlet have changed substantially. |
|
582 |
* ' |
|
559 | 583 |
* 'Revision 1.30.2.6 2000/06/26 10:18:06 jones |
560 | 584 |
* 'Partial fix for MetaCatServlet INSERT?UPDATE bug. Only will work on |
561 | 585 |
* 'the first call to the servlet. Subsequent calls fail. Seems to be |
Also available in: Unified diff
Fixed bugs associated with the new UPDATE and DELETE functions of
DBWriter. There were problematic interactions between some static
variables used in DBEntityResolver and the way in which the
Servlet objects are re-used across multiple client invocations.
Generally cleaned up error reporting. Now all errors and success
results are reported as XML documents from MetaCatServlet. Need
to make the command line tools do the same.