Read the message body using the same method as ActiveMQ web
authorMathieu Baudier <mbaudier@argeo.org>
Wed, 6 May 2009 19:38:05 +0000 (19:38 +0000)
committerMathieu Baudier <mbaudier@argeo.org>
Wed, 6 May 2009 19:38:05 +0000 (19:38 +0000)
git-svn-id: https://svn.argeo.org/slc/trunk@2406 4cfe0d0a-d680-48aa-b62c-e0a02a3f76cc

runtime/org.argeo.slc.server/src/main/java/org/argeo/slc/web/mvc/process/NewSlcExecutionController.java

index c551005bc2e93d7b5643a54692c770c3df97c9e9..236e8fb10019fa2d9cfa17b358d9b8b9d2d0ce97 100644 (file)
@@ -1,9 +1,12 @@
 package org.argeo.slc.web.mvc.process;\r
 \r
+import java.io.BufferedReader;\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.process.SlcExecution;\r
 import org.argeo.slc.runtime.SlcAgent;\r
@@ -11,9 +14,13 @@ import org.argeo.slc.runtime.SlcAgentFactory;
 import org.argeo.slc.web.mvc.AbstractServiceController;\r
 import org.springframework.oxm.Unmarshaller;\r
 import org.springframework.web.servlet.ModelAndView;\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
 \r
@@ -25,7 +32,26 @@ public class NewSlcExecutionController extends AbstractServiceController {
                String agentId = request\r
                                .getParameter(MsgConstants.PROPERTY_SLC_AGENT_ID);\r
 \r
-               StreamSource source = new StreamSource(request.getInputStream());\r
+               String answer = request.getParameter("body");\r
+               if (answer == null && "text/xml".equals(request.getContentType())) {\r
+                       // lets read the message body instead\r
+                       BufferedReader reader = request.getReader();\r
+                       StringBuffer buffer = new StringBuffer();\r
+                       while (true) {\r
+                               String line = reader.readLine();\r
+                               if (line == null) {\r
+                                       break;\r
+                               }\r
+                               buffer.append(line);\r
+                               buffer.append("\n");\r
+                       }\r
+                       answer = buffer.toString();\r
+               }\r
+\r
+               if (log.isDebugEnabled())\r
+                       log.debug("Received message:\n" + answer);\r
+\r
+               StringSource source = new StringSource(answer);\r
                SlcExecution slcExecution = (SlcExecution) unmarshaller\r
                                .unmarshal(source);\r
 \r