package org.argeo.slc.web.mvc.process;\r
\r
+import java.io.BufferedReader;\r
+import java.util.UUID;\r
+\r
import javax.servlet.http.HttpServletRequest;\r
import javax.servlet.http.HttpServletResponse;\r
-import javax.xml.transform.stream.StreamSource;\r
\r
+import org.apache.commons.logging.Log;\r
+import org.apache.commons.logging.LogFactory;\r
import org.argeo.slc.msg.MsgConstants;\r
+import org.argeo.slc.msg.ObjectList;\r
import org.argeo.slc.process.SlcExecution;\r
+import org.argeo.slc.process.SlcExecutionStep;\r
import org.argeo.slc.runtime.SlcAgent;\r
import org.argeo.slc.runtime.SlcAgentFactory;\r
+import org.argeo.slc.services.SlcExecutionService;\r
import org.argeo.slc.web.mvc.AbstractServiceController;\r
+import org.springframework.oxm.Marshaller;\r
import org.springframework.oxm.Unmarshaller;\r
+import org.springframework.util.Assert;\r
import org.springframework.web.servlet.ModelAndView;\r
+import org.springframework.xml.transform.StringResult;\r
+import org.springframework.xml.transform.StringSource;\r
\r
/** Send a new SlcExecution. */\r
public class NewSlcExecutionController extends AbstractServiceController {\r
+ private final static Log log = LogFactory\r
+ .getLog(NewSlcExecutionController.class);\r
+\r
private SlcAgentFactory agentFactory;\r
private Unmarshaller unmarshaller;\r
+ private Marshaller marshaller;\r
+ private SlcExecutionService slcExecutionService;\r
\r
@Override\r
protected void handleServiceRequest(HttpServletRequest request,\r
HttpServletResponse response, ModelAndView modelAndView)\r
throws Exception {\r
\r
+ if (log.isTraceEnabled()) {\r
+ log.debug("Content-Type: " + request.getContentType());\r
+ log.debug("Content-Length: " + request.getContentLength());\r
+ }\r
+\r
String agentId = request\r
.getParameter(MsgConstants.PROPERTY_SLC_AGENT_ID);\r
+ Assert.notNull(agentId, "agent id");\r
+\r
+ String answer = request.getParameter("body");\r
+ if (answer == null) {\r
+ // lets read the message body instead\r
+ BufferedReader reader = request.getReader();\r
+ StringBuffer buffer = new StringBuffer();\r
+ String line = null;\r
+ while (((line = reader.readLine()) != null)) {\r
+ buffer.append(line);\r
+ }\r
+ answer = buffer.toString();\r
+ }\r
\r
- StreamSource source = new StreamSource(request.getInputStream());\r
+ if (log.isTraceEnabled())\r
+ log.debug("Received message:\n" + answer);\r
+\r
+ StringSource source = new StringSource(answer);\r
SlcExecution slcExecution = (SlcExecution) unmarshaller\r
.unmarshal(source);\r
\r
+ // Workaround for https://www.argeo.org/bugzilla/show_bug.cgi?id=86\r
+ if (slcExecution.getUuid() == null\r
+ || slcExecution.getUuid().length() < 8)\r
+ slcExecution.setUuid(UUID.randomUUID().toString());\r
+\r
+ slcExecution.setStatus(SlcExecution.STATUS_SCHEDULED);\r
+ slcExecution.getSteps().add(\r
+ new SlcExecutionStep(SlcExecutionStep.TYPE_START,\r
+ "Process started from the Web UI"));\r
+\r
+ ObjectList ol = new ObjectList(slcExecution.getRealizedFlows());\r
+ StringResult result = new StringResult();\r
+ marshaller.marshal(ol, result);\r
+ slcExecution.setRealizedFlowsXml(result.toString());\r
+\r
+ slcExecutionService.newExecution(slcExecution);\r
+\r
SlcAgent agent = agentFactory.getAgent(agentId);\r
agent.runSlcExecution(slcExecution);\r
}\r
this.agentFactory = agentFactory;\r
}\r
\r
+ public void setSlcExecutionService(SlcExecutionService slcExecutionService) {\r
+ this.slcExecutionService = slcExecutionService;\r
+ }\r
+\r
+ public void setMarshaller(Marshaller marshaller) {\r
+ this.marshaller = marshaller;\r
+ }\r
+\r
}\r