forked from Roland-s-Demo-Org/BenchmarkJava
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDataBaseServer.java
More file actions
88 lines (81 loc) · 3.93 KB
/
DataBaseServer.java
File metadata and controls
88 lines (81 loc) · 3.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
/**
* OWASP Benchmark Project
*
* <p>This file is part of the Open Web Application Security Project (OWASP) Benchmark Project For
* details, please see <a
* href="https://owasp.org/www-project-benchmark/">https://owasp.org/www-project-benchmark/</a>.
*
* <p>The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms
* of the GNU General Public License as published by the Free Software Foundation, version 2.
*
* <p>The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
* PURPOSE. See the GNU General Public License for more details
*
* @author Juan Gama
* @created 2015
*/
package org.owasp.benchmark.helpers;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.owasp.benchmark.service.pojo.Person;
import org.owasp.benchmark.service.pojo.XMLMessage;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class DataBaseServer {
@GetMapping(value = "/resetdb")
public ResponseEntity<List<XMLMessage>> getOtherOrder(
@RequestBody Person model, HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
ArrayList<XMLMessage> resp = new ArrayList<XMLMessage>();
resp.add(new XMLMessage("Not Implemented."));
return new ResponseEntity<List<XMLMessage>>(resp, HttpStatus.OK);
}
@PostMapping(value = "/testdb")
public ResponseEntity<List<XMLMessage>> createOrder2(
@RequestBody Person model, HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
List<XMLMessage> resp = new ArrayList<XMLMessage>();
resp.add(new XMLMessage("Not Implemented."));
return new ResponseEntity<List<XMLMessage>>(resp, HttpStatus.OK);
}
@GetMapping(value = "/getall")
public ResponseEntity<List<XMLMessage>> getAll(
HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
List<XMLMessage> resp = new ArrayList<XMLMessage>();
String sql = "SELECT * from USERS";
try {
java.sql.Connection connection =
org.owasp.benchmark.helpers.DatabaseHelper.getSqlConnection();
java.sql.PreparedStatement statement = connection.prepareStatement(sql);
statement.execute();
org.owasp.benchmark.helpers.DatabaseHelper.printResults(statement, sql, resp);
} catch (java.sql.SQLException e) {
if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) {
resp.add(new XMLMessage("Error processing request: " + e.getMessage()));
resp.add(new XMLMessage("Error processing request: " + e.getMessage()));
return new ResponseEntity<List<XMLMessage>>(resp, HttpStatus.OK);
} else throw new ServletException(e);
}
return new ResponseEntity<List<XMLMessage>>(resp, HttpStatus.OK);
}
public static void main(String[] args) {
// This empty main() method is required to be able to start the Database. Otherwise you get
// the error:
/*
[java] Error: Main method not found in class org.owasp.benchmark.helpers.DataBaseServer, please define the main method as:
[java] public static void main(String[] args)
[java] or a JavaFX application class must extend javafx.application.Application
*/
}
}