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