1 package org
.argeo
.slc
.web
.mvc
.process
;
3 import java
.io
.BufferedReader
;
5 import javax
.servlet
.http
.HttpServletRequest
;
6 import javax
.servlet
.http
.HttpServletResponse
;
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
;
21 /** Send a new SlcExecution. */
22 public class NewSlcExecutionController
extends AbstractServiceController
{
23 private final static Log log
= LogFactory
24 .getLog(NewSlcExecutionController
.class);
26 private SlcAgentFactory agentFactory
;
27 private Unmarshaller unmarshaller
;
28 private SlcExecutionService slcExecutionService
;
31 protected void handleServiceRequest(HttpServletRequest request
,
32 HttpServletResponse response
, ModelAndView modelAndView
)
35 if (log
.isTraceEnabled()) {
36 log
.debug("Content-Type: " + request
.getContentType());
37 log
.debug("Content-Length: " + request
.getContentLength());
40 String agentId
= request
41 .getParameter(MsgConstants
.PROPERTY_SLC_AGENT_ID
);
42 Assert
.notNull(agentId
, "agent id");
44 String answer
= request
.getParameter("body");
46 // lets read the message body instead
47 BufferedReader reader
= request
.getReader();
48 StringBuffer buffer
= new StringBuffer();
50 while (((line
= reader
.readLine()) != null)) {
53 answer
= buffer
.toString();
56 if (log
.isTraceEnabled())
57 log
.debug("Received message:\n" + answer
);
59 StringSource source
= new StringSource(answer
);
60 SlcExecution slcExecution
= (SlcExecution
) unmarshaller
63 slcExecution
.setStatus(SlcExecution
.STATUS_SCHEDULED
);
64 slcExecutionService
.newExecution(slcExecution
);
66 SlcAgent agent
= agentFactory
.getAgent(agentId
);
67 agent
.runSlcExecution(slcExecution
);
70 public void setUnmarshaller(Unmarshaller unmarshaller
) {
71 this.unmarshaller
= unmarshaller
;
74 public void setAgentFactory(SlcAgentFactory agentFactory
) {
75 this.agentFactory
= agentFactory
;
78 public void setSlcExecutionService(SlcExecutionService slcExecutionService
) {
79 this.slcExecutionService
= slcExecutionService
;