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