added support for message deletion on the web console to fix AMQ-1197

git-svn-id: https://svn.apache.org/repos/asf/activemq/trunk@516117 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
James Strachan 2007-03-08 17:47:38 +00:00
parent 67fd739b3a
commit 5869f755bc
6 changed files with 101 additions and 9 deletions

View File

@ -18,6 +18,8 @@
package org.apache.activemq.web; package org.apache.activemq.web;
import org.apache.activemq.broker.jmx.BrokerViewMBean; import org.apache.activemq.broker.jmx.BrokerViewMBean;
import org.apache.activemq.broker.jmx.QueueViewMBean;
import org.apache.activemq.broker.jmx.TopicViewMBean;
import org.apache.activemq.command.ActiveMQDestination; import org.apache.activemq.command.ActiveMQDestination;
import java.util.Collection; import java.util.Collection;
@ -43,4 +45,8 @@ public interface BrokerFacade {
* @throws Exception * @throws Exception
*/ */
void purgeQueue(ActiveMQDestination destination) throws Exception; void purgeQueue(ActiveMQDestination destination) throws Exception;
QueueViewMBean getQueue(String name) throws Exception;
TopicViewMBean getTopic(String name) throws Exception;
} }

View File

@ -22,6 +22,7 @@ import org.apache.activemq.broker.jmx.DurableSubscriptionViewMBean;
import org.apache.activemq.broker.jmx.ManagementContext; import org.apache.activemq.broker.jmx.ManagementContext;
import org.apache.activemq.broker.jmx.TopicViewMBean; import org.apache.activemq.broker.jmx.TopicViewMBean;
import org.apache.activemq.broker.jmx.QueueViewMBean; import org.apache.activemq.broker.jmx.QueueViewMBean;
import org.apache.activemq.broker.jmx.DestinationViewMBean;
import javax.management.MBeanServer; import javax.management.MBeanServer;
import javax.management.MBeanServerInvocationHandler; import javax.management.MBeanServerInvocationHandler;
@ -30,6 +31,7 @@ import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.Iterator;
/** /**
* A useful base class for an implementation of {@link BrokerFacade} * A useful base class for an implementation of {@link BrokerFacade}
@ -66,6 +68,25 @@ public abstract class BrokerFacadeSupport implements BrokerFacade {
return getManagedObjects(queues, DurableSubscriptionViewMBean.class); return getManagedObjects(queues, DurableSubscriptionViewMBean.class);
} }
public QueueViewMBean getQueue(String name) throws Exception {
return (QueueViewMBean) getDestinationByName(getQueues(), name);
}
public TopicViewMBean getTopic(String name) throws Exception {
return (TopicViewMBean) getDestinationByName(getTopics(), name);
}
protected DestinationViewMBean getDestinationByName(Collection collection, String name) {
Iterator iter = collection.iterator();
while (iter.hasNext()) {
DestinationViewMBean destinationViewMBean = (DestinationViewMBean) iter.next();
if (name.equals(destinationViewMBean.getName())) {
return destinationViewMBean;
}
}
return null;
}
protected Collection getManagedObjects(ObjectName[] names, Class type) { protected Collection getManagedObjects(ObjectName[] names, Class type) {
List answer = new ArrayList(); List answer = new ArrayList();
MBeanServer mbeanServer = getManagementContext().getMBeanServer(); MBeanServer mbeanServer = getManagementContext().getMBeanServer();

View File

@ -99,12 +99,8 @@ public class DestinationFacade {
} }
protected ActiveMQDestination createDestination() { protected ActiveMQDestination createDestination() {
if (isQueue()) { byte destinationType = isQueue() ? ActiveMQDestination.QUEUE_TYPE : ActiveMQDestination.TOPIC_TYPE;
return new ActiveMQQueue(getValidDestination()); return ActiveMQDestination.createDestination(getValidDestination(), destinationType);
}
else {
return new ActiveMQTopic(getValidDestination());
}
} }
protected String getValidDestination() { protected String getValidDestination() {
@ -126,5 +122,7 @@ public class DestinationFacade {
return new ModelAndView("redirect:" + (isQueue() ? "queues.jsp" : "topics.jsp")); return new ModelAndView("redirect:" + (isQueue() ? "queues.jsp" : "topics.jsp"));
} }
protected String getPhysicalDestinationName() {
return createDestination().getPhysicalName();
}
} }

View File

@ -0,0 +1,66 @@
/**
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.activemq.web.controller;
import org.apache.activemq.broker.jmx.QueueViewMBean;
import org.apache.activemq.web.BrokerFacade;
import org.apache.activemq.web.DestinationFacade;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.Controller;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
* @version $Revision$
*/
public class DeleteMessage extends DestinationFacade implements Controller {
private String messageId;
public DeleteMessage(BrokerFacade brokerFacade) {
super(brokerFacade);
}
public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) throws Exception {
if (messageId != null) {
QueueViewMBean queueView = getQueue();
if (queueView != null) {
System.out.println("#### removing message: " + messageId);
queueView.removeMessage(messageId);
}
else {
System.out.println("#### NO QUEUE!");
}
}
return redirectToBrowseView();
}
public String getMessageId() {
return messageId;
}
public void setMessageId(String messageId) {
this.messageId = messageId;
}
protected QueueViewMBean getQueue() throws Exception {
String name = getPhysicalDestinationName();
System.out.println("####Êlooking up queue: " + name);
return getBrokerFacade().getQueue(name);
}
}

View File

@ -32,6 +32,7 @@
<bean name="/deleteSubscriber.action" class="org.apache.activemq.web.controller.DeleteSubscriber" autowire="constructor" singleton="false"/> <bean name="/deleteSubscriber.action" class="org.apache.activemq.web.controller.DeleteSubscriber" autowire="constructor" singleton="false"/>
<bean name="/sendMessage.action" class="org.apache.activemq.web.controller.SendMessage" autowire="constructor" singleton="false"/> <bean name="/sendMessage.action" class="org.apache.activemq.web.controller.SendMessage" autowire="constructor" singleton="false"/>
<bean name="/purgeDestination.action" class="org.apache.activemq.web.controller.PurgeDestination" autowire="constructor" singleton="false"/> <bean name="/purgeDestination.action" class="org.apache.activemq.web.controller.PurgeDestination" autowire="constructor" singleton="false"/>
<bean name="/deleteMessage.action" class="org.apache.activemq.web.controller.DeleteMessage" autowire="constructor" singleton="false"/>
<!-- <!--
- This bean resolves specific types of exception to corresponding error views. - This bean resolves specific types of exception to corresponding error views.

View File

@ -52,7 +52,7 @@
<td>${row.JMSTimestamp}</td> <td>${row.JMSTimestamp}</td>
<td>${row.JMSType}</td> <td>${row.JMSType}</td>
<td> <td>
<a href="deleteDestination.action?JMSDestination=${row.JMSDestination}">Delete</a> <a href="deleteMessage.action?JMSDestination=${row.JMSDestination}&messageId=${row.JMSMessageID}">Delete</a>
</td> </td>
</tr> </tr>
</jms:forEachMessage> </jms:forEachMessage>