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.store.amq; 018 019 import javax.jms.JMSException; 020 021 import org.apache.activemq.command.ActiveMQBlobMessage; 022 import org.apache.activemq.command.ActiveMQBytesMessage; 023 import org.apache.activemq.command.ActiveMQMapMessage; 024 import org.apache.activemq.command.ActiveMQMessage; 025 import org.apache.activemq.command.ActiveMQObjectMessage; 026 import org.apache.activemq.command.ActiveMQStreamMessage; 027 import org.apache.activemq.command.ActiveMQTextMessage; 028 import org.apache.activemq.util.ByteSequence; 029 030 public class MessageBodyFormatter { 031 final ActiveMQMessage message; 032 033 public MessageBodyFormatter(ActiveMQMessage message) { 034 this.message=message; 035 } 036 037 @Override 038 public String toString() { 039 try { 040 switch (message.getDataStructureType()) { 041 case ActiveMQMessage.DATA_STRUCTURE_TYPE: 042 return ""; 043 case ActiveMQBlobMessage.DATA_STRUCTURE_TYPE: 044 ActiveMQBlobMessage blob = (ActiveMQBlobMessage) message; 045 return blob.getRemoteBlobUrl(); 046 case ActiveMQMapMessage.DATA_STRUCTURE_TYPE: 047 ActiveMQMapMessage map = (ActiveMQMapMessage)message; 048 return map.getContentMap().toString(); 049 case ActiveMQTextMessage.DATA_STRUCTURE_TYPE: 050 ActiveMQTextMessage text = (ActiveMQTextMessage)message; 051 return text.getText(); 052 case ActiveMQBytesMessage.DATA_STRUCTURE_TYPE: 053 case ActiveMQObjectMessage.DATA_STRUCTURE_TYPE: 054 case ActiveMQStreamMessage.DATA_STRUCTURE_TYPE: 055 ByteSequence data = message.getContent(); 056 return "binary payload {length="+data.getLength()+", compressed="+message.isCompressed()+"}"; 057 } 058 } catch (JMSException e) { 059 } 060 return ""; 061 } 062 }