Skip to content

Commit b38d197

Browse files
committed
Comment out unused method and eliminate exception throw for method that isn't needed.
1 parent ef7ec5f commit b38d197

File tree

1 file changed

+46
-31
lines changed
  • src/main/java/org/owasp/benchmark/helpers

1 file changed

+46
-31
lines changed

src/main/java/org/owasp/benchmark/helpers/Utils.java

Lines changed: 46 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,12 @@
5151
import javax.servlet.http.HttpServletResponse;
5252
import javax.xml.parsers.DocumentBuilder;
5353
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;
6060

6161
import org.apache.http.Header;
6262
import org.apache.http.HttpEntity;
@@ -77,9 +77,10 @@
7777

7878
import org.owasp.esapi.ESAPI;
7979
import org.w3c.dom.Document;
80-
import org.w3c.dom.Element;
80+
//import org.w3c.dom.Element;
8181
import org.w3c.dom.Node;
8282
import org.xml.sax.InputSource;
83+
//import org.xml.sax.SAXException;
8384

8485
public class Utils {
8586

@@ -418,51 +419,65 @@ public static boolean deleteFile(String completeName) {
418419
return result;
419420
}
420421

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) {
430435
431-
DocumentBuilderFactory newCrawlerBF = null;
436+
Node root = null;
432437
DocumentBuilder newCrawlerBuilder = null;
433-
Document newCrawlerDoc = null;
434-
Element newCrawlerRootElement = null;
435-
newCrawlerBF = DocumentBuilderFactory.newInstance();
436-
Node newNode;
437-
438438
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();
439446
newCrawlerBuilder = newCrawlerBF.newDocumentBuilder();
440447
} 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);
442455
}
443-
newCrawlerDoc = newCrawlerBuilder.newDocument();
444-
newCrawlerRootElement = newCrawlerDoc.createElement("benchmarkSuite");
456+
457+
Document newCrawlerDoc = newCrawlerBuilder.newDocument();
458+
Element newCrawlerRootElement = newCrawlerDoc.createElement("benchmarkSuite");
445459
newCrawlerDoc.appendChild(newCrawlerRootElement);
446460
447461
List<AbstractTestCaseRequest> requests = new ArrayList<AbstractTestCaseRequest>();
448462
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.
449464
for (Node test : tests) {
450-
URL = XMLCrawler.getAttributeValue("URL", test).trim();
465+
String URL = XMLCrawler.getAttributeValue("URL", test).trim();
451466
// ToDo: don't use 18 (instead calculate length of TESTCASE_NAME and # digits
452467
if (failedTestCases
453468
.contains(URL.substring(URL.indexOf(BenchmarkScore.TESTCASENAME),
454469
URL.indexOf(BenchmarkScore.TESTCASENAME) + 18))) {
455470
requests.add(parseHttpTest(test));
456-
newNode = test.cloneNode(true);
471+
Node newNode = test.cloneNode(true);
457472
newCrawlerDoc.adoptNode(newNode);
458473
newCrawlerDoc.getDocumentElement().appendChild(newNode);
459474
} else {
460-
/* The test case passed */
475+
// The test case passed
461476
}
462477
}
463478
479+
// TODO: What is this delete for??
464480
String failedTCFile = DATA_DIR + "benchmark-failed-http.xml";
465-
466481
File file = new File(failedTCFile);
467482
if (file.exists()) {
468483
if (file.delete()) {
@@ -489,7 +504,7 @@ public static List<AbstractTestCaseRequest> parseHttpFile(InputStream http, List
489504
490505
return requests;
491506
}
492-
507+
*/
493508
public static String getCrawlerBenchmarkVersion(InputStream http) throws Exception {
494509
DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance();
495510
DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder();
@@ -516,7 +531,7 @@ public static List<AbstractTestCaseRequest> parseHttpFile(InputStream http) thro
516531
return requests;
517532
}
518533

519-
public static AbstractTestCaseRequest parseHttpTest(Node test) throws Exception {
534+
public static AbstractTestCaseRequest parseHttpTest(Node test) {
520535
String tcType = XMLCrawler.getAttributeValue("tcType", test);
521536
String fullURL = XMLCrawler.getAttributeValue("URL", test);
522537
String name = BenchmarkScore.TESTCASENAME + XMLCrawler.getAttributeValue("tname", test);

0 commit comments

Comments
 (0)