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 { ...@@ -135,14 +135,7 @@ public class DirectControlServlet extends HttpServlet {
135 135
136 // Load context 136 // Load context
137 Map<String, Object> context = new HashMap<String, Object>(); 137 Map<String, Object> context = new HashMap<String, Object>();
138 if ("application/json".equals(contentType)) { 138
139 // Read request body as JSON and insert into the context
140 JSON json = new JSON(request.getReader());
141 Map<String,Object> items = json.JSONObject();
142 for (String key : items.keySet()) {
143 context.put(key, items.get(key));
144 }
145 } else if ("text/csv".equals(contentType)) {
146 // Directly copy request parameters into context. 139 // Directly copy request parameters into context.
147 for (Enumeration<String> params = request.getParameterNames(); params.hasMoreElements();) { 140 for (Enumeration<String> params = request.getParameterNames(); params.hasMoreElements();) {
148 String param = params.nextElement(); 141 String param = params.nextElement();
...@@ -152,6 +145,14 @@ public class DirectControlServlet extends HttpServlet { ...@@ -152,6 +145,14 @@ public class DirectControlServlet extends HttpServlet {
152 } 145 }
153 } 146 }
154 147
148 if ("application/json".equals(contentType)) {
149 // Read request body as JSON and insert into the context
150 JSON json = new JSON(request.getReader());
151 Map<String,Object> items = json.JSONObject();
152 for (String key : items.keySet()) {
153 context.put(key, items.get(key));
154 }
155 } else if ("text/csv".equals(contentType)) {
155 Iterable<CSVRecord> records = CSVFormat.EXCEL.parse(request.getReader()); 156 Iterable<CSVRecord> records = CSVFormat.EXCEL.parse(request.getReader());
156 List<List<String>> data = new ArrayList<List<String>>(); 157 List<List<String>> data = new ArrayList<List<String>>();
157 for (CSVRecord record : records) { 158 for (CSVRecord record : records) {
...@@ -175,15 +176,6 @@ public class DirectControlServlet extends HttpServlet { ...@@ -175,15 +176,6 @@ public class DirectControlServlet extends HttpServlet {
175 context.put(key, items.get(key)); 176 context.put(key, items.get(key));
176 } 177 }
177 } 178 }
178 } else {
179 // Directly copy request parameters into context.
180 for (Enumeration<String> params = request.getParameterNames(); params.hasMoreElements();) {
181 String param = params.nextElement();
182 Object[] values = request.getParameterValues(param);
183 if (!"sessionId".equals(param) && !"_method".equals(param)) {
184 context.put(param, values.length == 1 ? values[0] : values);
185 }
186 }
187 } 179 }
188 } 180 }
189 181
......