51
51
import javax .servlet .http .HttpServletResponse ;
52
52
import javax .xml .parsers .DocumentBuilder ;
53
53
import javax .xml .parsers .DocumentBuilderFactory ;
54
- import javax .xml .parsers .ParserConfigurationException ;
55
- import javax .xml .transform .Transformer ;
56
- import javax .xml .transform .TransformerException ;
57
- import javax .xml .transform .TransformerFactory ;
58
- import javax .xml .transform .dom .DOMSource ;
59
- import javax .xml .transform .stream .StreamResult ;
54
+ // import javax.xml.parsers.ParserConfigurationException;
55
+ // import javax.xml.transform.Transformer;
56
+ // import javax.xml.transform.TransformerException;
57
+ // import javax.xml.transform.TransformerFactory;
58
+ // import javax.xml.transform.dom.DOMSource;
59
+ // import javax.xml.transform.stream.StreamResult;
60
60
61
61
import org .apache .http .Header ;
62
62
import org .apache .http .HttpEntity ;
77
77
78
78
import org .owasp .esapi .ESAPI ;
79
79
import org .w3c .dom .Document ;
80
- import org .w3c .dom .Element ;
80
+ // import org.w3c.dom.Element;
81
81
import org .w3c .dom .Node ;
82
82
import org .xml .sax .InputSource ;
83
+ //import org.xml.sax.SAXException;
83
84
84
85
public class Utils {
85
86
@@ -418,51 +419,65 @@ public static boolean deleteFile(String completeName) {
418
419
return result ;
419
420
}
420
421
421
- public static List <AbstractTestCaseRequest > parseHttpFile (InputStream http , List <String > failedTestCases )
422
- throws Exception {
423
- String URL = "" ;
424
-
425
- DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory .newInstance ();
426
- DocumentBuilder docBuilder = docBuilderFactory .newDocumentBuilder ();
427
- InputSource is = new InputSource (http );
428
- Document doc = docBuilder .parse (is );
429
- Node root = doc .getDocumentElement ();
422
+ /**
423
+ * UNUSED METHOD!!! Why was it created?
424
+ * Parses all the XML in the provided InputStream to generate a List of test case requests.
425
+ * If testing that case fails, add its failure to the list of failed test cases. (Not sure about this aspect of
426
+ * what it does.)
427
+ * @param http
428
+ * The inputstream to parse the XML test case request from (e.g., contents of benchmark-crawler(or attack)-http.xml
429
+ * @param failedTestCases
430
+ * A list of error messages, 1 for each test case that failed.
431
+ * @return A List of TestCaseRequest objects based on the file contents.
432
+ * @throws Exception
433
+ */
434
+ /* private static List<AbstractTestCaseRequest> parseHttpFile(InputStream http, List<String> failedTestCases) {
430
435
431
- DocumentBuilderFactory newCrawlerBF = null ;
436
+ Node root = null;
432
437
DocumentBuilder newCrawlerBuilder = null;
433
- Document newCrawlerDoc = null ;
434
- Element newCrawlerRootElement = null ;
435
- newCrawlerBF = DocumentBuilderFactory .newInstance ();
436
- Node newNode ;
437
-
438
438
try {
439
+ DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance();
440
+ DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder();
441
+ InputSource is = new InputSource(http);
442
+ Document doc = docBuilder.parse(is);
443
+ root = doc.getDocumentElement();
444
+
445
+ DocumentBuilderFactory newCrawlerBF = DocumentBuilderFactory.newInstance();
439
446
newCrawlerBuilder = newCrawlerBF.newDocumentBuilder();
440
447
} catch (ParserConfigurationException e) {
441
- System .out .println ("Problem init the Crawler XML file" );
448
+ System.out.println("ERROR: Problem creating new DocumentBuilder");
449
+ e.printStackTrace();
450
+ System.exit(-1);
451
+ } catch (IOException | SAXException e2) {
452
+ System.out.println("ERROR: Parsing XML input file.");
453
+ e2.printStackTrace();
454
+ System.exit(-1);
442
455
}
443
- newCrawlerDoc = newCrawlerBuilder .newDocument ();
444
- newCrawlerRootElement = newCrawlerDoc .createElement ("benchmarkSuite" );
456
+
457
+ Document newCrawlerDoc = newCrawlerBuilder.newDocument();
458
+ Element newCrawlerRootElement = newCrawlerDoc.createElement("benchmarkSuite");
445
459
newCrawlerDoc.appendChild(newCrawlerRootElement);
446
460
447
461
List<AbstractTestCaseRequest> requests = new ArrayList<AbstractTestCaseRequest>();
448
462
List<Node> tests = XMLCrawler.getNamedChildren("benchmarkTest", root);
463
+ // TODO: What does this loop do? Figure out, and document here, and in javadoc for this method.
449
464
for (Node test : tests) {
450
- URL = XMLCrawler .getAttributeValue ("URL" , test ).trim ();
465
+ String URL = XMLCrawler.getAttributeValue("URL", test).trim();
451
466
// ToDo: don't use 18 (instead calculate length of TESTCASE_NAME and # digits
452
467
if (failedTestCases
453
468
.contains(URL.substring(URL.indexOf(BenchmarkScore.TESTCASENAME),
454
469
URL.indexOf(BenchmarkScore.TESTCASENAME) + 18))) {
455
470
requests.add(parseHttpTest(test));
456
- newNode = test .cloneNode (true );
471
+ Node newNode = test.cloneNode(true);
457
472
newCrawlerDoc.adoptNode(newNode);
458
473
newCrawlerDoc.getDocumentElement().appendChild(newNode);
459
474
} else {
460
- /* The test case passed */
475
+ // The test case passed
461
476
}
462
477
}
463
478
479
+ // TODO: What is this delete for??
464
480
String failedTCFile = DATA_DIR + "benchmark-failed-http.xml";
465
-
466
481
File file = new File(failedTCFile);
467
482
if (file.exists()) {
468
483
if (file.delete()) {
@@ -489,7 +504,7 @@ public static List<AbstractTestCaseRequest> parseHttpFile(InputStream http, List
489
504
490
505
return requests;
491
506
}
492
-
507
+ */
493
508
public static String getCrawlerBenchmarkVersion (InputStream http ) throws Exception {
494
509
DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory .newInstance ();
495
510
DocumentBuilder docBuilder = docBuilderFactory .newDocumentBuilder ();
@@ -516,7 +531,7 @@ public static List<AbstractTestCaseRequest> parseHttpFile(InputStream http) thro
516
531
return requests ;
517
532
}
518
533
519
- public static AbstractTestCaseRequest parseHttpTest (Node test ) throws Exception {
534
+ public static AbstractTestCaseRequest parseHttpTest (Node test ) {
520
535
String tcType = XMLCrawler .getAttributeValue ("tcType" , test );
521
536
String fullURL = XMLCrawler .getAttributeValue ("URL" , test );
522
537
String name = BenchmarkScore .TESTCASENAME + XMLCrawler .getAttributeValue ("tname" , test );
0 commit comments