mirror of https://github.com/apache/activemq.git
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:
parent
67fd739b3a
commit
5869f755bc
|
@ -18,6 +18,8 @@
|
|||
package org.apache.activemq.web;
|
||||
|
||||
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 java.util.Collection;
|
||||
|
@ -43,4 +45,8 @@ public interface BrokerFacade {
|
|||
* @throws Exception
|
||||
*/
|
||||
void purgeQueue(ActiveMQDestination destination) throws Exception;
|
||||
|
||||
QueueViewMBean getQueue(String name) throws Exception;
|
||||
|
||||
TopicViewMBean getTopic(String name) throws Exception;
|
||||
}
|
||||
|
|
|
@ -22,6 +22,7 @@ import org.apache.activemq.broker.jmx.DurableSubscriptionViewMBean;
|
|||
import org.apache.activemq.broker.jmx.ManagementContext;
|
||||
import org.apache.activemq.broker.jmx.TopicViewMBean;
|
||||
import org.apache.activemq.broker.jmx.QueueViewMBean;
|
||||
import org.apache.activemq.broker.jmx.DestinationViewMBean;
|
||||
|
||||
import javax.management.MBeanServer;
|
||||
import javax.management.MBeanServerInvocationHandler;
|
||||
|
@ -30,6 +31,7 @@ import java.util.ArrayList;
|
|||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Iterator;
|
||||
|
||||
/**
|
||||
* 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);
|
||||
}
|
||||
|
||||
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) {
|
||||
List answer = new ArrayList();
|
||||
MBeanServer mbeanServer = getManagementContext().getMBeanServer();
|
||||
|
|
|
@ -99,12 +99,8 @@ public class DestinationFacade {
|
|||
}
|
||||
|
||||
protected ActiveMQDestination createDestination() {
|
||||
if (isQueue()) {
|
||||
return new ActiveMQQueue(getValidDestination());
|
||||
}
|
||||
else {
|
||||
return new ActiveMQTopic(getValidDestination());
|
||||
}
|
||||
byte destinationType = isQueue() ? ActiveMQDestination.QUEUE_TYPE : ActiveMQDestination.TOPIC_TYPE;
|
||||
return ActiveMQDestination.createDestination(getValidDestination(), destinationType);
|
||||
}
|
||||
|
||||
protected String getValidDestination() {
|
||||
|
@ -126,5 +122,7 @@ public class DestinationFacade {
|
|||
return new ModelAndView("redirect:" + (isQueue() ? "queues.jsp" : "topics.jsp"));
|
||||
}
|
||||
|
||||
|
||||
protected String getPhysicalDestinationName() {
|
||||
return createDestination().getPhysicalName();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
|
@ -32,7 +32,8 @@
|
|||
<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="/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.
|
||||
- The default behaviour of DispatcherServlet is to propagate all exceptions to the
|
||||
|
|
|
@ -52,7 +52,7 @@
|
|||
<td>${row.JMSTimestamp}</td>
|
||||
<td>${row.JMSType}</td>
|
||||
<td>
|
||||
<a href="deleteDestination.action?JMSDestination=${row.JMSDestination}">Delete</a>
|
||||
<a href="deleteMessage.action?JMSDestination=${row.JMSDestination}&messageId=${row.JMSMessageID}">Delete</a>
|
||||
</td>
|
||||
</tr>
|
||||
</jms:forEachMessage>
|
||||
|
|
Loading…
Reference in New Issue