Changeset 528:1faedac1f0b4
- Timestamp:
- 09/24/09 15:34:35 (4 years ago)
- Author:
- tgambet
- Branch:
- default
- convert_revision:
- svn:cdcfb263-7567-472c-a848-e2c2df3466e7/trunk@529
- Message:
-
createError method removed, redirection on Index is done in ouputModules
- Files:
-
Legend:
- Unmodified
- Added
- Removed
-
|
r510
|
r528
|
|
| 1 | | // $Id: ObserveAction.java,v 1.41 2009-09-23 14:08:46 tgambet Exp $ |
| | 1 | // $Id: ObserveAction.java,v 1.42 2009-09-24 15:34:35 tgambet Exp $ |
| 2 | 2 | // Author: Jean-Guilhem Rouel |
| 3 | 3 | // (c) COPYRIGHT MIT, ERCIM and Keio, 2006. |
| … |
… |
|
| 14 | 14 | import java.util.Map; |
| 15 | 15 | |
| 16 | | import javax.servlet.RequestDispatcher; |
| 17 | 16 | import javax.servlet.ServletConfig; |
| 18 | 17 | import javax.servlet.ServletException; |
| … |
… |
|
| 109 | 108 | mapOfStringObject.put("unicorncall", aUnicornCall); |
| 110 | 109 | |
| | 110 | resp.setContentType(mapOfOutputParameter.get("mimetype") + "; charset=UTF-8"); |
| | 111 | |
| 111 | 112 | // Retrieve the parameters from the request |
| 112 | 113 | Map<String, Object> reqParams; |
| … |
… |
|
| 116 | 117 | OutputModule aOutputModule = OutputFactory.createOutputModule(mapOfOutputParameter, mapOfSpecificParameter); |
| 117 | 118 | messages.add(new Message(e)); |
| 118 | | createError(req, resp, null, mapOfStringObject, aOutputModule); |
| | 119 | aOutputModule.produceError(mapOfStringObject, resp.getWriter()); |
| 119 | 120 | return; |
| 120 | 121 | } |
| … |
… |
|
| 155 | 156 | logger.trace("Task parameter: " + key + " - " + (String) reqParams.get(key)); |
| 156 | 157 | String task = getTask((String) reqParams.get(key), messages); |
| | 158 | mapOfStringObject.put("current_task", Framework.mapOfTask.get(task)); |
| 157 | 159 | if (!task.equals(reqParams.get(key))) { |
| 158 | 160 | mapOfStringObject.put("default_task", Framework.mapOfTask.get(Framework.mapOfTask.getDefaultTaskId())); |
| … |
… |
|
| 206 | 208 | logger.debug("No task parameter found. Task parameter is set to task id: " + task); |
| 207 | 209 | mapOfStringObject.put("default_task", Framework.mapOfTask.get(Framework.mapOfTask.getDefaultTaskId())); |
| | 210 | mapOfStringObject.put("current_task", Framework.mapOfTask.get(task)); |
| 208 | 211 | aUnicornCall.setTask(task); |
| 209 | 212 | } |
| … |
… |
|
| 213 | 216 | if (!reqParams.containsKey(paramPrefix + "uri") && !reqParams.containsKey(paramPrefix + "text") && !reqParams.containsKey(paramPrefix + "file")) { |
| 214 | 217 | messages.add(new Message(Message.Level.ERROR, "$message_nothing_to_validate", null)); |
| 215 | | createError(req, resp, reqParams, mapOfStringObject, aOutputModule); |
| | 218 | aOutputModule.produceError( mapOfStringObject, resp.getWriter()); |
| 216 | 219 | return; |
| 217 | 220 | } |
| 218 | 221 | |
| 219 | | resp.setContentType(mapOfOutputParameter.get("mimetype") + "; charset=" + mapOfOutputParameter.get("charset")); |
| | 222 | //req.setAttribute("unicorn_parameters", reqParams); |
| | 223 | |
| | 224 | for (Object objKey : reqParams.keySet()) { |
| | 225 | String key = (String) objKey; |
| | 226 | String ref; |
| | 227 | if (key.startsWith(Property.get("UNICORN_PARAMETER_OUTPUT_PREFIX"))) |
| | 228 | continue; |
| | 229 | if (key.startsWith(paramPrefix)) |
| | 230 | ref = "param_" + key.substring(paramPrefix.length()); |
| | 231 | else |
| | 232 | ref = "param_" + key; |
| | 233 | if (reqParams.get(key) instanceof String[]) { |
| | 234 | String[] s = (String[]) reqParams.get(key); |
| | 235 | ArrayList<String> array = new ArrayList<String>(); |
| | 236 | for (int i = 0; i < s.length; i++) |
| | 237 | array.add(s[i]); |
| | 238 | mapOfStringObject.put(ref, array); |
| | 239 | } |
| | 240 | else { |
| | 241 | mapOfStringObject.put(ref, reqParams.get(key)); |
| | 242 | } |
| | 243 | } |
| 220 | 244 | |
| 221 | 245 | String s = "Resolved parameters:"; |
| … |
… |
|
| 236 | 260 | // Launch the observation |
| 237 | 261 | try { |
| 238 | | aOutputModule.produceFirstOutput( mapOfStringObject, resp.getWriter()); |
| | 262 | aOutputModule.produceFirstOutput(mapOfStringObject, resp.getWriter()); |
| 239 | 263 | aUnicornCall.doTask(); |
| 240 | 264 | messages.addAll(aUnicornCall.getMessages()); |
| 241 | 265 | if (aUnicornCall.getResponses().size() == 0) { |
| 242 | 266 | messages.add(new Message(Message.Level.ERROR, "$message_no_observation_done", null)); |
| 243 | | createError(req, resp, reqParams, mapOfStringObject, aOutputModule); |
| | 267 | aOutputModule.produceError(mapOfStringObject, resp.getWriter()); |
| 244 | 268 | } else { |
| 245 | 269 | aOutputModule.produceOutput(mapOfStringObject, resp.getWriter()); |
| … |
… |
|
| 250 | 274 | else |
| 251 | 275 | messages.add(new Message(Message.Level.ERROR, ucnException.getMessage(), null)); |
| 252 | | createError(req, resp, reqParams, mapOfStringObject, aOutputModule); |
| | 276 | aOutputModule.produceError(mapOfStringObject, resp.getWriter()); |
| 253 | 277 | } catch (final Exception aException) { |
| 254 | 278 | logger.error("Exception : " + aException.getMessage(), aException); |
| 255 | 279 | messages.add(new Message(aException)); |
| 256 | | createError(req, resp, reqParams, mapOfStringObject, aOutputModule); |
| | 280 | aOutputModule.produceError(mapOfStringObject, resp.getWriter()); |
| 257 | 281 | } finally { |
| 258 | 282 | if ("true".equals(Property.get("DELETE_UPLOADED_FILES")) && aFileItemUploaded != null) |
| … |
… |
|
| 330 | 354 | return params; |
| 331 | 355 | } |
| 332 | | |
| 333 | | private void createError(HttpServletRequest req, HttpServletResponse resp, |
| 334 | | Map<String, Object> reqParams, Map<String, Object> mapOfStringObject, OutputModule aOutputModule) throws IOException, ServletException { |
| 335 | | |
| 336 | | // If text/html is the mime-type the error will be displayed directly on index |
| 337 | | if (aOutputModule.getOutputParameter("mimetype").equals("text/html")) {// mapOfOutputParameter.get("mimetype").equals("text/html")) { |
| 338 | | redirect(req, resp, reqParams, (ArrayList<?>) mapOfStringObject.get("messages")); |
| 339 | | return; |
| 340 | | } |
| 341 | | |
| 342 | | aOutputModule.produceError( mapOfStringObject, resp.getWriter()); |
| 343 | | } |
| 344 | | |
| 345 | | private void redirect(HttpServletRequest req, HttpServletResponse resp, Map<String, Object> reqParams, ArrayList<?> messages) throws IOException, ServletException { |
| 346 | | req.setAttribute("unicorn_messages", messages); |
| 347 | | if (reqParams != null) |
| 348 | | req.setAttribute("unicorn_parameters", reqParams); |
| 349 | | RequestDispatcher dispatcher = req.getRequestDispatcher("index.html"); |
| 350 | | dispatcher.forward(req, resp); |
| 351 | | logger.info("request redirected to index"); |
| 352 | | } |
| 353 | 356 | |
| 354 | 357 | /** |