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.console.util;
018    
019    import java.net.URI;
020    import java.util.List;
021    import java.util.Set;
022    
023    import javax.jms.ConnectionFactory;
024    import javax.jms.Destination;
025    
026    import org.apache.activemq.console.filter.AmqMessagesQueryFilter;
027    import org.apache.activemq.console.filter.GroupPropertiesViewFilter;
028    import org.apache.activemq.console.filter.MapTransformFilter;
029    import org.apache.activemq.console.filter.PropertiesViewFilter;
030    import org.apache.activemq.console.filter.QueryFilter;
031    import org.apache.activemq.console.filter.StubQueryFilter;
032    import org.apache.activemq.console.filter.WildcardToMsgSelectorTransformFilter;
033    
034    public final class AmqMessagesUtil {
035    
036        public static final String JMS_MESSAGE_HEADER_PREFIX = "JMS_HEADER_FIELD:";
037        public static final String JMS_MESSAGE_CUSTOM_PREFIX = "JMS_CUSTOM_FIELD:";
038        public static final String JMS_MESSAGE_BODY_PREFIX = "JMS_BODY_FIELD:";
039    
040        private AmqMessagesUtil() {
041        }
042    
043        public static List getAllMessages(URI brokerUrl, Destination dest) throws Exception {
044            return getMessages(brokerUrl, dest, "");
045        }
046    
047        public static List getMessages(URI brokerUrl, Destination dest, String selector) throws Exception {
048            return createMessageQueryFilter(brokerUrl, dest).query(selector);
049        }
050    
051        public static List getMessages(ConnectionFactory connectionFactory, Destination dest, String selector) throws Exception {
052            return createMessageQueryFilter(connectionFactory, dest).query(selector);
053        }
054    
055        public static List getMessages(URI brokerUrl, Destination dest, List selectors) throws Exception {
056            return createMessageQueryFilter(brokerUrl, dest).query(selectors);
057        }
058    
059        public static List getMessages(ConnectionFactory connectionFactory, Destination dest, List selectors) throws Exception {
060            return createMessageQueryFilter(connectionFactory, dest).query(selectors);
061        }
062    
063        public static List filterMessagesView(List messages, Set groupViews, Set attributeViews) throws Exception {
064            return (new PropertiesViewFilter(attributeViews, new GroupPropertiesViewFilter(groupViews, new MapTransformFilter(new StubQueryFilter(messages))))).query("");
065        }
066    
067        public static QueryFilter createMessageQueryFilter(URI brokerUrl, Destination dest) {
068            return new WildcardToMsgSelectorTransformFilter(new AmqMessagesQueryFilter(brokerUrl, dest));
069        }
070    
071        public static QueryFilter createMessageQueryFilter(ConnectionFactory connectionFactory, Destination dest) {
072            return new WildcardToMsgSelectorTransformFilter(new AmqMessagesQueryFilter(connectionFactory, dest));
073        }
074    }