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
.msg
.ObjectList
;
13 import org
.argeo
.slc
.process
.SlcExecution
;
14 import org
.argeo
.slc
.process
.SlcExecutionStep
;
15 import org
.argeo
.slc
.runtime
.SlcAgent
;
16 import org
.argeo
.slc
.runtime
.SlcAgentFactory
;
17 import org
.argeo
.slc
.services
.SlcExecutionService
;
18 import org
.argeo
.slc
.web
.mvc
.AbstractServiceController
;
19 import org
.springframework
.oxm
.Marshaller
;
20 import org
.springframework
.oxm
.Unmarshaller
;
21 import org
.springframework
.util
.Assert
;
22 import org
.springframework
.web
.servlet
.ModelAndView
;
23 import org
.springframework
.xml
.transform
.StringResult
;
24 import org
.springframework
.xml
.transform
.StringSource
;
26 /** Send a new SlcExecution. */
27 public class NewSlcExecutionController
extends AbstractServiceController
{
28 private final static Log log
= LogFactory
29 .getLog(NewSlcExecutionController
.class);
31 private SlcAgentFactory agentFactory
;
32 private Unmarshaller unmarshaller
;
33 private Marshaller marshaller
;
34 private SlcExecutionService slcExecutionService
;
37 protected void handleServiceRequest(HttpServletRequest request
,
38 HttpServletResponse response
, ModelAndView modelAndView
)
41 if (log
.isTraceEnabled()) {
42 log
.debug("Content-Type: " + request
.getContentType());
43 log
.debug("Content-Length: " + request
.getContentLength());
46 String agentId
= request
47 .getParameter(MsgConstants
.PROPERTY_SLC_AGENT_ID
);
48 Assert
.notNull(agentId
, "agent id");
50 String answer
= request
.getParameter("body");
52 // lets read the message body instead
53 BufferedReader reader
= request
.getReader();
54 StringBuffer buffer
= new StringBuffer();
56 while (((line
= reader
.readLine()) != null)) {
59 answer
= buffer
.toString();
62 if (log
.isTraceEnabled())
63 log
.debug("Received message:\n" + answer
);
65 StringSource source
= new StringSource(answer
);
66 SlcExecution slcExecution
= (SlcExecution
) unmarshaller
69 // Workaround for https://www.argeo.org/bugzilla/show_bug.cgi?id=86
70 if (slcExecution
.getUuid() == null
71 || slcExecution
.getUuid().length() < 8)
72 slcExecution
.setUuid(UUID
.randomUUID().toString());
74 slcExecution
.setStatus(SlcExecution
.STATUS_SCHEDULED
);
75 slcExecution
.getSteps().add(
76 new SlcExecutionStep(SlcExecutionStep
.TYPE_START
,
77 "Process started from the Web UI"));
79 ObjectList ol
= new ObjectList(slcExecution
.getRealizedFlows());
80 StringResult result
= new StringResult();
81 marshaller
.marshal(ol
, result
);
82 slcExecution
.setRealizedFlowsXml(result
.toString());
84 slcExecutionService
.newExecution(slcExecution
);
86 SlcAgent agent
= agentFactory
.getAgent(agentId
);
87 agent
.runSlcExecution(slcExecution
);
90 public void setUnmarshaller(Unmarshaller unmarshaller
) {
91 this.unmarshaller
= unmarshaller
;
94 public void setAgentFactory(SlcAgentFactory agentFactory
) {
95 this.agentFactory
= agentFactory
;
98 public void setSlcExecutionService(SlcExecutionService slcExecutionService
) {
99 this.slcExecutionService
= slcExecutionService
;
102 public void setMarshaller(Marshaller marshaller
) {
103 this.marshaller
= marshaller
;