]> 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
@update:79; Simplify the execution of flows
[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.util.Assert;
18 import org.springframework.web.servlet.ModelAndView;
19 import org.springframework.xml.transform.StringSource;
20
21 /** Send a new SlcExecution. */
22 public class NewSlcExecutionController extends AbstractServiceController {
23 private final static Log log = LogFactory
24 .getLog(NewSlcExecutionController.class);
25
26 private SlcAgentFactory agentFactory;
27 private Unmarshaller unmarshaller;
28 private SlcExecutionService slcExecutionService;
29
30 @Override
31 protected void handleServiceRequest(HttpServletRequest request,
32 HttpServletResponse response, ModelAndView modelAndView)
33 throws Exception {
34
35 if (log.isTraceEnabled()) {
36 log.debug("Content-Type: " + request.getContentType());
37 log.debug("Content-Length: " + request.getContentLength());
38 }
39
40 String agentId = request
41 .getParameter(MsgConstants.PROPERTY_SLC_AGENT_ID);
42 Assert.notNull(agentId, "agent id");
43
44 String answer = request.getParameter("body");
45 if (answer == null) {
46 // lets read the message body instead
47 BufferedReader reader = request.getReader();
48 StringBuffer buffer = new StringBuffer();
49 String line = null;
50 while (((line = reader.readLine()) != null)) {
51 buffer.append(line);
52 }
53 answer = buffer.toString();
54 }
55
56 if (log.isTraceEnabled())
57 log.debug("Received message:\n" + answer);
58
59 StringSource source = new StringSource(answer);
60 SlcExecution slcExecution = (SlcExecution) unmarshaller
61 .unmarshal(source);
62
63 slcExecution.setStatus(SlcExecution.STATUS_SCHEDULED);
64 slcExecutionService.newExecution(slcExecution);
65
66 SlcAgent agent = agentFactory.getAgent(agentId);
67 agent.runSlcExecution(slcExecution);
68 }
69
70 public void setUnmarshaller(Unmarshaller unmarshaller) {
71 this.unmarshaller = unmarshaller;
72 }
73
74 public void setAgentFactory(SlcAgentFactory agentFactory) {
75 this.agentFactory = agentFactory;
76 }
77
78 public void setSlcExecutionService(SlcExecutionService slcExecutionService) {
79 this.slcExecutionService = slcExecutionService;
80 }
81
82 }