1 package org
.argeo
.slc
.web
.mvc
.process
;
3 import java
.io
.BufferedReader
;
6 import javax
.servlet
.http
.HttpServletRequest
;
7 import javax
.servlet
.http
.HttpServletResponse
;
9 import org
.apache
.commons
.logging
.Log
;
10 import org
.apache
.commons
.logging
.LogFactory
;
11 import org
.argeo
.slc
.msg
.MsgConstants
;
12 import org
.argeo
.slc
.process
.SlcExecution
;
13 import org
.argeo
.slc
.process
.SlcExecutionStep
;
14 import org
.argeo
.slc
.runtime
.SlcAgent
;
15 import org
.argeo
.slc
.runtime
.SlcAgentFactory
;
16 import org
.argeo
.slc
.services
.SlcExecutionService
;
17 import org
.argeo
.slc
.web
.mvc
.AbstractServiceController
;
18 import org
.springframework
.oxm
.Unmarshaller
;
19 import org
.springframework
.util
.Assert
;
20 import org
.springframework
.web
.servlet
.ModelAndView
;
21 import org
.springframework
.xml
.transform
.StringSource
;
23 /** Send a new SlcExecution. */
24 public class NewSlcExecutionController
extends AbstractServiceController
{
25 private final static Log log
= LogFactory
26 .getLog(NewSlcExecutionController
.class);
28 private SlcAgentFactory agentFactory
;
29 private Unmarshaller unmarshaller
;
30 private SlcExecutionService slcExecutionService
;
33 protected void handleServiceRequest(HttpServletRequest request
,
34 HttpServletResponse response
, ModelAndView modelAndView
)
37 if (log
.isTraceEnabled()) {
38 log
.debug("Content-Type: " + request
.getContentType());
39 log
.debug("Content-Length: " + request
.getContentLength());
42 String agentId
= request
43 .getParameter(MsgConstants
.PROPERTY_SLC_AGENT_ID
);
44 Assert
.notNull(agentId
, "agent id");
46 String answer
= request
.getParameter("body");
48 // lets read the message body instead
49 BufferedReader reader
= request
.getReader();
50 StringBuffer buffer
= new StringBuffer();
52 while (((line
= reader
.readLine()) != null)) {
55 answer
= buffer
.toString();
58 if (log
.isTraceEnabled())
59 log
.debug("Received message:\n" + answer
);
61 StringSource source
= new StringSource(answer
);
62 SlcExecution slcExecution
= (SlcExecution
) unmarshaller
65 // Workaround for https://www.argeo.org/bugzilla/show_bug.cgi?id=86
66 if (slcExecution
.getUuid() == null
67 || slcExecution
.getUuid().length() < 8)
68 slcExecution
.setUuid(UUID
.randomUUID().toString());
70 slcExecution
.setStatus(SlcExecution
.STATUS_SCHEDULED
);
71 slcExecution
.getSteps().add(
72 new SlcExecutionStep(SlcExecutionStep
.TYPE_START
,
73 "Process started from the Web UI"));
74 slcExecutionService
.newExecution(slcExecution
);
76 SlcAgent agent
= agentFactory
.getAgent(agentId
);
77 agent
.runSlcExecution(slcExecution
);
80 public void setUnmarshaller(Unmarshaller unmarshaller
) {
81 this.unmarshaller
= unmarshaller
;
84 public void setAgentFactory(SlcAgentFactory agentFactory
) {
85 this.agentFactory
= agentFactory
;
88 public void setSlcExecutionService(SlcExecutionService slcExecutionService
) {
89 this.slcExecutionService
= slcExecutionService
;