activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject svn commit: r1387504 - /activemq/trunk/activemq-web/src/main/java/org/apache/activemq/web/MessageServlet.java
Date Wed, 19 Sep 2012 09:33:27 GMT
Author: davsclaus
Date: Wed Sep 19 09:33:27 2012
New Revision: 1387504

URL: http://svn.apache.org/viewvc?rev=1387504&view=rev
Log:
AMQ-4043: Fixed web demo for simple send/receive.

Modified:
    activemq/trunk/activemq-web/src/main/java/org/apache/activemq/web/MessageServlet.java

Modified: activemq/trunk/activemq-web/src/main/java/org/apache/activemq/web/MessageServlet.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-web/src/main/java/org/apache/activemq/web/MessageServlet.java?rev=1387504&r1=1387503&r2=1387504&view=diff
==============================================================================
--- activemq/trunk/activemq-web/src/main/java/org/apache/activemq/web/MessageServlet.java
(original)
+++ activemq/trunk/activemq-web/src/main/java/org/apache/activemq/web/MessageServlet.java
Wed Sep 19 09:33:27 2012
@@ -131,7 +131,8 @@ public class MessageServlet extends Mess
                    String body = (String)client.getProducerTemplate().requestBody(point,
text);
                    ActiveMQTextMessage answer = new ActiveMQTextMessage();
                    answer.setText(body);
-                   writeMessageResponse(response.getWriter(), answer);
+
+                   writeResponse(request, response, answer);
                } catch (Exception e) {
                    IOException ex = new IOException();
                    ex.initCause(e);
@@ -148,6 +149,8 @@ public class MessageServlet extends Mess
             // lets return a unique URI for reliable messaging
             response.setHeader("messageID", message.getJMSMessageID());
             response.setStatus(HttpServletResponse.SC_OK);
+            response.getWriter().write("Message sent");
+
         } catch (JMSException e) {
             throw new ServletException("Could not post JMS message: " + e, e);
         }
@@ -241,23 +244,34 @@ public class MessageServlet extends Mess
         try {
 
             // write a responds
-            response.setContentType(defaultContentType);
             PrintWriter writer = response.getWriter();
 
             // handle any message(s)
             if (message == null) {
                 // No messages so OK response of for ajax else no content.
-                response.setStatus(HttpServletResponse.SC_NO_CONTENT);
+                response.setStatus(HttpServletResponse.SC_OK);
+                response.setContentType("text/plain");
+                writer.write("No message received");
+                writer.flush();
             } else {
                 // We have at least one message so set up the response
-                response.setStatus(HttpServletResponse.SC_OK);
+                messages = 1;
+
                 String type = getContentType(request);
                 if (type != null) {
                     response.setContentType(type);
+                } else {
+                    if (isXmlContent(message)) {
+                        response.setContentType(defaultContentType);
+                    } else {
+                        response.setContentType("text/plain");
+                    }
                 }
+                response.setStatus(HttpServletResponse.SC_OK);
 
                 setResponseHeaders(response, message);
                 writeMessageResponse(writer, message);
+                writer.flush();
             }
         } finally {
             if (LOG.isDebugEnabled()) {
@@ -285,6 +299,21 @@ public class MessageServlet extends Mess
         }
     }
 
+    protected boolean isXmlContent(Message message) throws JMSException {
+        if (message instanceof TextMessage) {
+            TextMessage textMsg = (TextMessage)message;
+            String txt = textMsg.getText();
+            if (txt != null) {
+                // assume its xml when it starts with <
+                if (txt.startsWith("<")) {
+                    return true;
+                }
+            }
+        }
+        // for any other kind of messages we dont assume xml
+        return false;
+    }
+
     public WebClient getWebClient(HttpServletRequest request) {
         String clientId = request.getParameter("clientId");
         if (clientId != null) {



Mime
View raw message