1 package org.apache.activemq.transport.stomp; 2 3 import org.apache.activemq.command.ActiveMQMessage; 4 import org.apache.activemq.command.ActiveMQDestination; 5 6 import javax.jms.JMSException ; 7 import javax.jms.Destination ; 8 import java.io.IOException ; 9 import java.util.Map ; 10 import java.util.HashMap ; 11 12 17 public interface FrameTranslator 18 { 19 public ActiveMQMessage convertFrame(StompFrame frame) throws JMSException , ProtocolException; 20 21 public StompFrame convertMessage(ActiveMQMessage message) throws IOException , JMSException ; 22 23 public String convertDestination(Destination d); 24 25 public ActiveMQDestination convertDestination(String name) throws ProtocolException; 26 27 31 public final static class Helper 32 { 33 public static void copyStandardHeadersFromMessageToFrame(ActiveMQMessage message, 34 StompFrame command, 35 FrameTranslator ft) 36 throws IOException 37 { 38 final Map headers = command.getHeaders(); 39 headers.put(Stomp.Headers.Message.DESTINATION, ft.convertDestination(message.getDestination())); 40 headers.put(Stomp.Headers.Message.MESSAGE_ID, message.getJMSMessageID()); 41 42 if (message.getJMSCorrelationID() != null) { 43 headers.put(Stomp.Headers.Message.CORRELATION_ID, message.getJMSCorrelationID()); 44 } 45 headers.put(Stomp.Headers.Message.EXPIRATION_TIME, ""+message.getJMSExpiration()); 46 47 if (message.getJMSRedelivered()) { 48 headers.put(Stomp.Headers.Message.REDELIVERED, "true"); 49 } 50 headers.put(Stomp.Headers.Message.PRORITY, ""+message.getJMSPriority()); 51 52 if (message.getJMSReplyTo() != null) { 53 headers.put(Stomp.Headers.Message.REPLY_TO, ft.convertDestination(message.getJMSReplyTo())); 54 } 55 headers.put(Stomp.Headers.Message.TIMESTAMP, ""+message.getJMSTimestamp()); 56 57 if (message.getJMSType() != null) { 58 headers.put(Stomp.Headers.Message.TYPE, message.getJMSType()); 59 } 60 61 final Map properties = message.getProperties(); 63 if (properties != null) { 64 headers.putAll(properties); 65 } 66 } 67 68 public static void copyStandardHeadersFromFrameToMessage(StompFrame command, 69 ActiveMQMessage msg, 70 FrameTranslator ft) 71 throws ProtocolException, JMSException 72 { 73 final Map headers = new HashMap (command.getHeaders()); 74 final String destination = (String ) headers.remove(Stomp.Headers.Send.DESTINATION); 75 msg.setDestination( ft.convertDestination(destination)); 76 77 msg.setJMSCorrelationID((String ) headers.remove(Stomp.Headers.Send.CORRELATION_ID)); 79 80 Object o = headers.remove(Stomp.Headers.Send.EXPIRATION_TIME); 81 if (o != null) { 82 msg.setJMSExpiration(Long.parseLong((String ) o)); 83 } 84 85 o = headers.remove(Stomp.Headers.Send.PRIORITY); 86 if (o != null) { 87 msg.setJMSPriority(Integer.parseInt((String ) o)); 88 } 89 90 o = headers.remove(Stomp.Headers.Send.TYPE); 91 if (o != null) { 92 msg.setJMSType((String ) o); 93 } 94 95 o = headers.remove(Stomp.Headers.Send.REPLY_TO); 96 if (o != null) { 97 msg.setJMSReplyTo(ft.convertDestination((String ) o)); 98 } 99 100 o = headers.remove(Stomp.Headers.Send.PERSISTENT); 101 if (o != null) { 102 msg.setPersistent("true".equals(o)); 103 } 104 105 msg.setProperties(headers); 107 } 108 } 109 } 110 | Popular Tags |