001    /**
002     * Licensed to the Apache Software Foundation (ASF) under one or more
003     * contributor license agreements.  See the NOTICE file distributed with
004     * this work for additional information regarding copyright ownership.
005     * The ASF licenses this file to You under the Apache License, Version 2.0
006     * (the "License"); you may not use this file except in compliance with
007     * the License.  You may obtain a copy of the License at
008     *
009     *      http://www.apache.org/licenses/LICENSE-2.0
010     *
011     * Unless required by applicable law or agreed to in writing, software
012     * distributed under the License is distributed on an "AS IS" BASIS,
013     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014     * See the License for the specific language governing permissions and
015     * limitations under the License.
016     */
017    package org.apache.activemq.web.controller;
018    
019    import javax.servlet.http.HttpServletRequest;
020    import javax.servlet.http.HttpServletResponse;
021    
022    import org.apache.activemq.broker.jmx.QueueViewMBean;
023    import org.apache.activemq.web.BrokerFacade;
024    import org.apache.activemq.web.DestinationFacade;
025    import org.apache.commons.logging.Log;
026    import org.apache.commons.logging.LogFactory;
027    import org.springframework.web.servlet.ModelAndView;
028    import org.springframework.web.servlet.mvc.Controller;
029    
030    /**
031     * Copies a message from one to another queue
032     * 
033     * @author <a href="http://www.nighttale.net">Dejan Bosanac</a>
034     * @version $Revision$
035     */
036    public class CopyMessage extends DestinationFacade implements Controller {
037        private String messageId;
038        private String destination;
039        private static final Log log = LogFactory.getLog(CopyMessage.class);
040    
041        public CopyMessage(BrokerFacade brokerFacade) {
042            super(brokerFacade);
043        }
044    
045        public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) throws Exception {
046            if (messageId != null) {
047                QueueViewMBean queueView = getQueueView();
048                if (queueView != null) {
049                    log.info(getJMSDestination() + "(" + messageId + ")" + " copy to " + destination);
050                    queueView.copyMessageTo(messageId, destination);
051                } else {
052                    log.warn("No queue named: " + getPhysicalDestinationName());
053                }
054            }
055            return redirectToBrowseView();
056        }
057    
058        public String getMessageId() {
059            return messageId;
060        }
061    
062        public void setMessageId(String messageId) {
063            this.messageId = messageId;
064        }
065        
066        
067    
068        public String getDestination() {
069                    return destination;
070            }
071    
072            public void setDestination(String destination) {
073                    this.destination = destination;
074            }
075    
076    }