6a67f9ad by Adam Heath

Issue #BF-5728: Move parameter parsing logic out of the 2 separate

conditions, and instead do it at the beginning for all 3.
1 parent 5bd83859
......@@ -135,14 +135,7 @@ public class DirectControlServlet extends HttpServlet {
// Load context
Map<String, Object> context = new HashMap<String, Object>();
if ("application/json".equals(contentType)) {
// Read request body as JSON and insert into the context
JSON json = new JSON(request.getReader());
Map<String,Object> items = json.JSONObject();
for (String key : items.keySet()) {
context.put(key, items.get(key));
}
} else if ("text/csv".equals(contentType)) {
// Directly copy request parameters into context.
for (Enumeration<String> params = request.getParameterNames(); params.hasMoreElements();) {
String param = params.nextElement();
......@@ -152,6 +145,14 @@ public class DirectControlServlet extends HttpServlet {
}
}
if ("application/json".equals(contentType)) {
// Read request body as JSON and insert into the context
JSON json = new JSON(request.getReader());
Map<String,Object> items = json.JSONObject();
for (String key : items.keySet()) {
context.put(key, items.get(key));
}
} else if ("text/csv".equals(contentType)) {
Iterable<CSVRecord> records = CSVFormat.EXCEL.parse(request.getReader());
List<List<String>> data = new ArrayList<List<String>>();
for (CSVRecord record : records) {
......@@ -175,15 +176,6 @@ public class DirectControlServlet extends HttpServlet {
context.put(key, items.get(key));
}
}
} else {
// Directly copy request parameters into context.
for (Enumeration<String> params = request.getParameterNames(); params.hasMoreElements();) {
String param = params.nextElement();
Object[] values = request.getParameterValues(param);
if (!"sessionId".equals(param) && !"_method".equals(param)) {
context.put(param, values.length == 1 ? values[0] : values);
}
}
}
}
......