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.transport.amqp.message; 018 019import static org.apache.activemq.transport.amqp.message.AmqpMessageSupport.JMS_AMQP_MESSAGE_FORMAT; 020import static org.apache.activemq.transport.amqp.message.AmqpMessageSupport.JMS_AMQP_NATIVE; 021 022import javax.jms.Message; 023 024import org.apache.activemq.command.ActiveMQBytesMessage; 025import org.apache.activemq.command.ActiveMQMessage; 026import org.apache.activemq.util.ByteSequence; 027 028public class AMQPRawInboundTransformer extends InboundTransformer { 029 030 @Override 031 public String getTransformerName() { 032 return TRANSFORMER_RAW; 033 } 034 035 @Override 036 public InboundTransformer getFallbackTransformer() { 037 return null; // No fallback from full raw transform, message likely dropped. 038 } 039 040 @Override 041 protected ActiveMQMessage doTransform(EncodedMessage amqpMessage) throws Exception { 042 ActiveMQBytesMessage result = new ActiveMQBytesMessage(); 043 result.setContent(new ByteSequence(amqpMessage.getArray(), amqpMessage.getArrayOffset(), amqpMessage.getLength())); 044 045 // We cannot decode the message headers to check so err on the side of caution 046 // and mark all messages as persistent. 047 result.setPersistent(true); 048 result.setPriority((byte) Message.DEFAULT_PRIORITY); 049 050 final long now = System.currentTimeMillis(); 051 result.setTimestamp(now); 052 053 if (amqpMessage.getMessageFormat() != 0) { 054 result.setLongProperty(JMS_AMQP_MESSAGE_FORMAT, amqpMessage.getMessageFormat()); 055 } 056 057 result.setBooleanProperty(JMS_AMQP_NATIVE, true); 058 059 return result; 060 } 061}