mirror of https://github.com/apache/activemq.git
patch applied for http://issues.apache.org/activemq/browse/AMQ-1315 with thanks - also refactored the QueueBrowseServlet to use the WebClient
git-svn-id: https://svn.apache.org/repos/asf/activemq/trunk@646357 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
cec77fd12a
commit
60bcc521a7
|
@ -60,7 +60,7 @@
|
||||||
<a href="graph.jsp?JMSDestination=${row.name}">Graph</a>
|
<a href="graph.jsp?JMSDestination=${row.name}">Graph</a>
|
||||||
--%>
|
--%>
|
||||||
<a href="queueBrowse/${row.name}?view=rss&feedType=atom_1.0" title="Atom 1.0"><img src="images/feed_atom.png"/></a>
|
<a href="queueBrowse/${row.name}?view=rss&feedType=atom_1.0" title="Atom 1.0"><img src="images/feed_atom.png"/></a>
|
||||||
<a href="queueBrowse/${row.name}?view=rss&ffeedType=rss_2.0" title="RSS 2.0"><img src="images/feed_rss.png"/></a>
|
<a href="queueBrowse/${row.name}?view=rss&feedType=rss_2.0" title="RSS 2.0"><img src="images/feed_rss.png"/></a>
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
<a href="send.jsp?JMSDestination=${row.name}&JMSDestinationType=queue">Send To</a>
|
<a href="send.jsp?JMSDestination=${row.name}&JMSDestinationType=queue">Send To</a>
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
/**
|
/*
|
||||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||||
* contributor license agreements. See the NOTICE file distributed with
|
* contributor license agreements. See the NOTICE file distributed with
|
||||||
* this work for additional information regarding copyright ownership.
|
* this work for additional information regarding copyright ownership.
|
||||||
|
@ -17,14 +17,13 @@
|
||||||
package org.apache.activemq.web;
|
package org.apache.activemq.web;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.io.PrintWriter;
|
||||||
import java.util.Enumeration;
|
import java.util.Enumeration;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.LinkedList;
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import javax.jms.Connection;
|
|
||||||
import javax.jms.ConnectionFactory;
|
|
||||||
import javax.jms.JMSException;
|
import javax.jms.JMSException;
|
||||||
|
import javax.jms.Message;
|
||||||
import javax.jms.Queue;
|
import javax.jms.Queue;
|
||||||
import javax.jms.QueueBrowser;
|
import javax.jms.QueueBrowser;
|
||||||
import javax.jms.Session;
|
import javax.jms.Session;
|
||||||
|
@ -33,79 +32,61 @@ import javax.servlet.http.HttpServlet;
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
|
||||||
import org.apache.activemq.ActiveMQConnectionFactory;
|
|
||||||
import org.apache.activemq.util.FactoryFinder;
|
import org.apache.activemq.util.FactoryFinder;
|
||||||
import org.apache.activemq.util.IntrospectionSupport;
|
import org.apache.activemq.util.IntrospectionSupport;
|
||||||
import org.apache.activemq.web.view.MessageRenderer;
|
import org.apache.activemq.web.view.MessageRenderer;
|
||||||
|
import org.apache.activemq.web.view.XmlMessageRenderer;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Renders the contents of a queue using some kind of view. The URI is assumed
|
* Renders the contents of a queue using some kind of view. The URI is assumed
|
||||||
* to be the queue. The following parameters can be used
|
* to be the queue. The following parameters can be used
|
||||||
|
* <p/>
|
||||||
* <ul>
|
* <ul>
|
||||||
* <li>view - specifies the type of the view such as simple, xml, rss</li>
|
* <li>view - specifies the type of the view such as simple, xml, rss</li>
|
||||||
* <li>selector - specifies the SQL 92 selector to apply to the queue</li>
|
* <li>selector - specifies the SQL 92 selector to apply to the queue</li>
|
||||||
* </ul>
|
* </ul>
|
||||||
*
|
*
|
||||||
* @version $Revision: $
|
* @version $Revision: $
|
||||||
*/
|
*/
|
||||||
// TODO Why do we implement our own session pool?
|
|
||||||
// TODO This doesn't work, since nobody will be setting the connection factory
|
|
||||||
// (because nobody is able to). Just use the WebClient?
|
|
||||||
public class QueueBrowseServlet extends HttpServlet {
|
public class QueueBrowseServlet extends HttpServlet {
|
||||||
|
|
||||||
private static FactoryFinder factoryFinder = new FactoryFinder("META-INF/services/org/apache/activemq/web/view/");
|
private static FactoryFinder factoryFinder = new FactoryFinder("META-INF/services/org/apache/activemq/web/view/");
|
||||||
|
|
||||||
private ConnectionFactory connectionFactory;
|
|
||||||
private Connection connection;
|
|
||||||
private LinkedList<Session> sessions = new LinkedList<Session>();
|
|
||||||
|
|
||||||
public Connection getConnection() throws JMSException {
|
|
||||||
if (connection == null) {
|
|
||||||
connection = getConnectionFactory().createConnection();
|
|
||||||
connection.start();
|
|
||||||
}
|
|
||||||
return connection;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setConnection(Connection connection) {
|
|
||||||
this.connection = connection;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ConnectionFactory getConnectionFactory() {
|
|
||||||
if (connectionFactory == null) {
|
|
||||||
String uri = getServletContext().getInitParameter("org.apache.activemq.brokerURL");
|
|
||||||
if (uri != null) {
|
|
||||||
connectionFactory = new ActiveMQConnectionFactory(uri);
|
|
||||||
} else {
|
|
||||||
throw new IllegalStateException("missing ConnectionFactory in QueueBrowserServlet");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return connectionFactory;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setConnectionFactory(ConnectionFactory connectionFactory) {
|
|
||||||
this.connectionFactory = connectionFactory;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Implementation methods
|
// Implementation methods
|
||||||
// -------------------------------------------------------------------------
|
// -------------------------------------------------------------------------
|
||||||
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
|
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
|
||||||
Session session = null;
|
|
||||||
try {
|
try {
|
||||||
session = borrowSession();
|
WebClient client = WebClient.getWebClient(request);
|
||||||
|
Session session = client.getSession();
|
||||||
Queue queue = getQueue(request, session);
|
Queue queue = getQueue(request, session);
|
||||||
if (queue == null) {
|
if (queue == null) {
|
||||||
throw new ServletException("No queue URI specified");
|
throw new ServletException("No queue URI specified");
|
||||||
}
|
}
|
||||||
String selector = getSelector(request);
|
|
||||||
QueueBrowser browser = session.createBrowser(queue, selector);
|
String msgId = request.getParameter("msgId");
|
||||||
MessageRenderer renderer = getMessageRenderer(request);
|
if (msgId == null) {
|
||||||
configureRenderer(request, renderer);
|
MessageRenderer renderer = getMessageRenderer(request);
|
||||||
renderer.renderMessages(request, response, browser);
|
configureRenderer(request, renderer);
|
||||||
} catch (JMSException e) {
|
|
||||||
|
String selector = getSelector(request);
|
||||||
|
QueueBrowser browser = session.createBrowser(queue, selector);
|
||||||
|
renderer.renderMessages(request, response, browser);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
XmlMessageRenderer renderer = new XmlMessageRenderer();
|
||||||
|
QueueBrowser browser = session.createBrowser(queue, "JMSMessageID='" + msgId + "'");
|
||||||
|
if (!browser.getEnumeration().hasMoreElements()) {
|
||||||
|
response.sendError(HttpServletResponse.SC_NOT_FOUND);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Message message = (Message) browser.getEnumeration().nextElement();
|
||||||
|
|
||||||
|
PrintWriter writer = response.getWriter();
|
||||||
|
renderer.renderMessage(writer, request, response, browser, message);
|
||||||
|
writer.flush();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (JMSException e) {
|
||||||
throw new ServletException(e);
|
throw new ServletException(e);
|
||||||
} finally {
|
|
||||||
returnSession(session);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -115,49 +96,29 @@ public class QueueBrowseServlet extends HttpServlet {
|
||||||
style = "simple";
|
style = "simple";
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
return (MessageRenderer)factoryFinder.newInstance(style);
|
return (MessageRenderer) factoryFinder.newInstance(style);
|
||||||
} catch (IllegalAccessException e) {
|
}
|
||||||
|
catch (IllegalAccessException e) {
|
||||||
throw new NoSuchViewStyleException(style, e);
|
throw new NoSuchViewStyleException(style, e);
|
||||||
} catch (InstantiationException e) {
|
}
|
||||||
|
catch (InstantiationException e) {
|
||||||
throw new NoSuchViewStyleException(style, e);
|
throw new NoSuchViewStyleException(style, e);
|
||||||
} catch (ClassNotFoundException e) {
|
}
|
||||||
|
catch (ClassNotFoundException e) {
|
||||||
throw new NoSuchViewStyleException(style, e);
|
throw new NoSuchViewStyleException(style, e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
protected void configureRenderer(HttpServletRequest request, MessageRenderer renderer) {
|
protected void configureRenderer(HttpServletRequest request, MessageRenderer renderer) {
|
||||||
Map<String, String> properties = new HashMap<String, String>();
|
Map<String, String> properties = new HashMap<String, String>();
|
||||||
for (Enumeration iter = request.getParameterNames(); iter.hasMoreElements();) {
|
for (Enumeration<String> iter = request.getParameterNames(); iter.hasMoreElements();) {
|
||||||
String name = (String)iter.nextElement();
|
String name = (String) iter.nextElement();
|
||||||
properties.put(name, request.getParameter(name));
|
properties.put(name, request.getParameter(name));
|
||||||
}
|
}
|
||||||
IntrospectionSupport.setProperties(renderer, properties);
|
IntrospectionSupport.setProperties(renderer, properties);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected Session borrowSession() throws JMSException {
|
|
||||||
Session answer = null;
|
|
||||||
synchronized (sessions) {
|
|
||||||
if (sessions.isEmpty()) {
|
|
||||||
answer = createSession();
|
|
||||||
} else {
|
|
||||||
answer = sessions.removeLast();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return answer;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void returnSession(Session session) {
|
|
||||||
if (session != null) {
|
|
||||||
synchronized (sessions) {
|
|
||||||
sessions.add(session);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected Session createSession() throws JMSException {
|
|
||||||
return getConnection().createSession(false, Session.AUTO_ACKNOWLEDGE);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected String getSelector(HttpServletRequest request) {
|
protected String getSelector(HttpServletRequest request) {
|
||||||
return request.getParameter("selector");
|
return request.getParameter("selector");
|
||||||
}
|
}
|
||||||
|
@ -177,9 +138,6 @@ public class QueueBrowseServlet extends HttpServlet {
|
||||||
}
|
}
|
||||||
uri = uri.replace('/', '.');
|
uri = uri.replace('/', '.');
|
||||||
|
|
||||||
System.out.println("destination uri = " + uri);
|
|
||||||
|
|
||||||
return session.createQueue(uri);
|
return session.createQueue(uri);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -115,7 +115,7 @@ public class RssMessageRenderer extends SimpleMessageRenderer {
|
||||||
SyndEntry entry = new SyndEntryImpl();
|
SyndEntry entry = new SyndEntryImpl();
|
||||||
String title = message.getJMSMessageID();
|
String title = message.getJMSMessageID();
|
||||||
entry.setTitle(title);
|
entry.setTitle(title);
|
||||||
String link = request.getRequestURI() + "/" + title;
|
String link = request.getRequestURI() + "?msgId=" + title;
|
||||||
entry.setLink(link);
|
entry.setLink(link);
|
||||||
entry.setPublishedDate(new Date());
|
entry.setPublishedDate(new Date());
|
||||||
return entry;
|
return entry;
|
||||||
|
|
Loading…
Reference in New Issue