Issue #BF-5728: Move parameter parsing logic out of the 2 separate
conditions, and instead do it at the beginning for all 3.
Showing
1 changed file
with
10 additions
and
18 deletions
... | @@ -135,6 +135,16 @@ public class DirectControlServlet extends HttpServlet { | ... | @@ -135,6 +135,16 @@ 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 | |||
139 | // Directly copy request parameters into context. | ||
140 | for (Enumeration<String> params = request.getParameterNames(); params.hasMoreElements();) { | ||
141 | String param = params.nextElement(); | ||
142 | Object[] values = request.getParameterValues(param); | ||
143 | if (!"sessionId".equals(param) && !"_method".equals(param)) { | ||
144 | context.put(param, values.length == 1 ? values[0] : values); | ||
145 | } | ||
146 | } | ||
147 | |||
138 | if ("application/json".equals(contentType)) { | 148 | if ("application/json".equals(contentType)) { |
139 | // Read request body as JSON and insert into the context | 149 | // Read request body as JSON and insert into the context |
140 | JSON json = new JSON(request.getReader()); | 150 | JSON json = new JSON(request.getReader()); |
... | @@ -143,15 +153,6 @@ public class DirectControlServlet extends HttpServlet { | ... | @@ -143,15 +153,6 @@ public class DirectControlServlet extends HttpServlet { |
143 | context.put(key, items.get(key)); | 153 | context.put(key, items.get(key)); |
144 | } | 154 | } |
145 | } else if ("text/csv".equals(contentType)) { | 155 | } else if ("text/csv".equals(contentType)) { |
146 | // Directly copy request parameters into context. | ||
147 | for (Enumeration<String> params = request.getParameterNames(); params.hasMoreElements();) { | ||
148 | String param = params.nextElement(); | ||
149 | Object[] values = request.getParameterValues(param); | ||
150 | if (!"sessionId".equals(param) && !"_method".equals(param)) { | ||
151 | context.put(param, values.length == 1 ? values[0] : values); | ||
152 | } | ||
153 | } | ||
154 | |||
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 | ... | ... |
-
Please register or sign in to post a comment