patch for AMQ-1326 applied (with a few more code improvements)

git-svn-id: https://svn.apache.org/repos/asf/activemq/trunk@700405 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Bosanac Dejan 2008-09-30 10:23:22 +00:00
parent ddd2fa687b
commit 74c27e70be
6 changed files with 208 additions and 8 deletions

View File

@ -0,0 +1,76 @@
/**
* 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 javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.activemq.broker.jmx.QueueViewMBean;
import org.apache.activemq.web.BrokerFacade;
import org.apache.activemq.web.DestinationFacade;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.Controller;
/**
* Copies a message from one to another queue
*
* @author <a href="http://www.nighttale.net">Dejan Bosanac</a>
* @version $Revision$
*/
public class CopyMessage extends DestinationFacade implements Controller {
private String messageId;
private String destination;
private static final Log log = LogFactory.getLog(CopyMessage.class);
public CopyMessage(BrokerFacade brokerFacade) {
super(brokerFacade);
}
public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) throws Exception {
if (messageId != null) {
QueueViewMBean queueView = getQueueView();
if (queueView != null) {
log.info(getJMSDestination() + "(" + messageId + ")" + " copy to " + destination);
queueView.copyMessageTo(messageId, destination);
} else {
log.warn("No queue named: " + getPhysicalDestinationName());
}
}
return redirectToBrowseView();
}
public String getMessageId() {
return messageId;
}
public void setMessageId(String messageId) {
this.messageId = messageId;
}
public String getDestination() {
return destination;
}
public void setDestination(String destination) {
this.destination = destination;
}
}

View File

@ -22,6 +22,8 @@ import javax.servlet.http.HttpServletResponse;
import org.apache.activemq.broker.jmx.QueueViewMBean;
import org.apache.activemq.web.BrokerFacade;
import org.apache.activemq.web.DestinationFacade;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.Controller;
@ -30,6 +32,7 @@ import org.springframework.web.servlet.mvc.Controller;
*/
public class DeleteMessage extends DestinationFacade implements Controller {
private String messageId;
private static final Log log = LogFactory.getLog(DeleteMessage.class);
public DeleteMessage(BrokerFacade brokerFacade) {
super(brokerFacade);
@ -37,12 +40,12 @@ public class DeleteMessage extends DestinationFacade implements Controller {
public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) throws Exception {
if (messageId != null) {
QueueViewMBean queueView = getQueue();
QueueViewMBean queueView = getQueueView();
if (queueView != null) {
System.out.println("#### removing message: " + messageId);
log.info("Removing message " + getJMSDestination() + "(" + messageId + ")");
queueView.removeMessage(messageId);
} else {
System.out.println("#### NO QUEUE!");
log.warn("No queue named: " + getPhysicalDestinationName());
}
}
return redirectToBrowseView();
@ -56,9 +59,4 @@ public class DeleteMessage extends DestinationFacade implements Controller {
this.messageId = messageId;
}
protected QueueViewMBean getQueue() throws Exception {
String name = getPhysicalDestinationName();
System.out.println("####Êlooking up queue: " + name);
return getBrokerFacade().getQueue(name);
}
}

View File

@ -0,0 +1,76 @@
/**
* 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 javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.activemq.broker.jmx.QueueViewMBean;
import org.apache.activemq.web.BrokerFacade;
import org.apache.activemq.web.DestinationFacade;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.Controller;
/**
* Moves a message from one to another queue
*
* @author <a href="http://www.nighttale.net">Dejan Bosanac</a>
* @version $Revision$
*/
public class MoveMessage extends DestinationFacade implements Controller {
private String messageId;
private String destination;
private static final Log log = LogFactory.getLog(MoveMessage.class);
public MoveMessage(BrokerFacade brokerFacade) {
super(brokerFacade);
}
public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) throws Exception {
if (messageId != null) {
QueueViewMBean queueView = getQueueView();
if (queueView != null) {
log.info("Moving message " + getJMSDestination() + "(" + messageId + ")" + " to " + destination);
queueView.moveMessageTo(messageId, destination);
} else {
log.warn("No queue named: " + getPhysicalDestinationName());
}
}
return redirectToBrowseView();
}
public String getMessageId() {
return messageId;
}
public void setMessageId(String messageId) {
this.messageId = messageId;
}
public String getDestination() {
return destination;
}
public void setDestination(String destination) {
this.destination = destination;
}
}

View File

@ -33,6 +33,8 @@
<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"/>
<bean name="/copyMessage.action" class="org.apache.activemq.web.controller.CopyMessage" autowire="constructor" singleton="false"/>
<bean name="/moveMessage.action" class="org.apache.activemq.web.controller.MoveMessage" autowire="constructor" singleton="false"/>
<!--
- This bean resolves specific types of exception to corresponding error views.

View File

@ -106,3 +106,16 @@ function getEventTarget(e) {
return targ;
}
function confirmAction(id, url) {
//TODO i18n messages
var select = document.getElementById(id);
var selectedIndex = select.selectedIndex;
if (select.selectedIndex == 0) {
alert("Please select a value");
return;
}
var value = select.options[selectedIndex].value;
url = url.replace(/%target%/gi, value);
if (confirm("Are you sure?"))
location.href=url;
}

View File

@ -136,6 +136,41 @@ No message could be found for ID ${requestContext.messageQuery.JMSMessageID}
</table>
</td>
</tr>
<tr>
<td class="layout" colspan="2">
<table id="body" width="100%">
<thead>
<tr>
<th colspan="2">
Message Actions
</th>
</tr>
</thead>
<tbody>
<tr>
<td colspan="2"><a href="deleteMessage.action?JMSDestination=${row.JMSDestination}&messageId=${row.JMSMessageID}">Delete</a></td>
</tr>
<tr class="odd">
<td><a href="javascript:confirmAction('queue', 'copyMessage.action?destination=%target%&JMSDestination=${row.JMSDestination}&messageId=${row.JMSMessageID}&JMSDestinationType=queue')">Copy</a></td>
<td rowspan="2">
<select id="queue">
<option value=""> -- Please select --</option>
<c:forEach items="${requestContext.brokerQuery.queues}" var="queues">
<c:if test="${queues.name != requestContext.messageQuery.JMSDestination}">
<option value="${queues.name}">${queues.name}</option>
</c:if>
</c:forEach>
</select>
</td>
</tr>
<tr class="odd">
<td><a href="javascript:confirmAction('queue', 'moveMessage.action?destination=%target%&JMSDestination=${row.JMSDestination}&messageId=${row.JMSMessageID}&JMSDestinationType=queue')">Move</a></td>
</tr>
</tbody>
</table>
</td>
</tr>
</table>