]> git.argeo.org Git - gpl/argeo-slc.git/blob - runtime/org.argeo.slc.server/src/main/java/org/argeo/slc/web/mvc/process/NewSlcExecutionController.java
Attachments management
[gpl/argeo-slc.git] / runtime / org.argeo.slc.server / src / main / java / org / argeo / slc / web / mvc / process / NewSlcExecutionController.java
1 package org.argeo.slc.web.mvc.process;
2
3 import java.io.BufferedReader;
4
5 import javax.servlet.http.HttpServletRequest;
6 import javax.servlet.http.HttpServletResponse;
7
8 import org.apache.commons.logging.Log;
9 import org.apache.commons.logging.LogFactory;
10 import org.argeo.slc.msg.MsgConstants;
11 import org.argeo.slc.process.SlcExecution;
12 import org.argeo.slc.runtime.SlcAgent;
13 import org.argeo.slc.runtime.SlcAgentFactory;
14 import org.argeo.slc.services.process.SlcExecutionService;
15 import org.argeo.slc.web.mvc.AbstractServiceController;
16 import org.springframework.oxm.Unmarshaller;
17 import org.springframework.web.servlet.ModelAndView;
18 import org.springframework.xml.transform.StringSource;
19
20 /** Send a new SlcExecution. */
21 public class NewSlcExecutionController extends AbstractServiceController {
22 private final static Log log = LogFactory
23 .getLog(NewSlcExecutionController.class);
24
25 private SlcAgentFactory agentFactory;
26 private Unmarshaller unmarshaller;
27 private SlcExecutionService slcExecutionService;
28
29 @Override
30 protected void handleServiceRequest(HttpServletRequest request,
31 HttpServletResponse response, ModelAndView modelAndView)
32 throws Exception {
33
34 if (log.isTraceEnabled()) {
35 log.debug("Content-Type: " + request.getContentType());
36 log.debug("Content-Length: " + request.getContentLength());
37 }
38
39 String agentId = request
40 .getParameter(MsgConstants.PROPERTY_SLC_AGENT_ID);
41
42 String answer = request.getParameter("body");
43 if (answer == null) {
44 // lets read the message body instead
45 BufferedReader reader = request.getReader();
46 StringBuffer buffer = new StringBuffer();
47 String line = null;
48 while (((line = reader.readLine()) != null)) {
49 buffer.append(line);
50 }
51 answer = buffer.toString();
52 }
53
54 if (log.isTraceEnabled())
55 log.debug("Received message:\n" + answer);
56
57 StringSource source = new StringSource(answer);
58 SlcExecution slcExecution = (SlcExecution) unmarshaller
59 .unmarshal(source);
60
61 slcExecution.setStatus(SlcExecution.STATUS_SCHEDULED);
62 slcExecutionService.newExecution(slcExecution);
63
64 SlcAgent agent = agentFactory.getAgent(agentId);
65 agent.runSlcExecution(slcExecution);
66 }
67
68 public void setUnmarshaller(Unmarshaller unmarshaller) {
69 this.unmarshaller = unmarshaller;
70 }
71
72 public void setAgentFactory(SlcAgentFactory agentFactory) {
73 this.agentFactory = agentFactory;
74 }
75
76 public void setSlcExecutionService(SlcExecutionService slcExecutionService) {
77 this.slcExecutionService = slcExecutionService;
78 }
79
80 }