001/* 002 * Copyright 2002-2018 the original author or authors. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * https://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016 017package org.springframework.jms.support; 018 019import java.util.List; 020import java.util.Map; 021import javax.jms.Destination; 022 023import org.springframework.messaging.Message; 024import org.springframework.messaging.support.NativeMessageHeaderAccessor; 025 026/** 027 * A {@link org.springframework.messaging.support.MessageHeaderAccessor} 028 * implementation giving access to JMS-specific headers. 029 * 030 * @author Stephane Nicoll 031 * @since 4.1 032 */ 033public class JmsMessageHeaderAccessor extends NativeMessageHeaderAccessor { 034 035 protected JmsMessageHeaderAccessor(Map<String, List<String>> nativeHeaders) { 036 super(nativeHeaders); 037 } 038 039 protected JmsMessageHeaderAccessor(Message<?> message) { 040 super(message); 041 } 042 043 044 /** 045 * Return the {@link JmsHeaders#CORRELATION_ID correlationId}. 046 * @see JmsHeaders#CORRELATION_ID 047 */ 048 public String getCorrelationId() { 049 return (String) getHeader(JmsHeaders.CORRELATION_ID); 050 } 051 052 /** 053 * Return the {@link JmsHeaders#DESTINATION destination}. 054 * @see JmsHeaders#DESTINATION 055 */ 056 public Destination getDestination() { 057 return (Destination) getHeader(JmsHeaders.DESTINATION); 058 } 059 060 /** 061 * Return the {@link JmsHeaders#DELIVERY_MODE delivery mode}. 062 * @see JmsHeaders#DELIVERY_MODE 063 */ 064 public Integer getDeliveryMode() { 065 return (Integer) getHeader(JmsHeaders.DELIVERY_MODE); 066 } 067 068 /** 069 * Return the message {@link JmsHeaders#EXPIRATION expiration}. 070 * @see JmsHeaders#EXPIRATION 071 */ 072 public Long getExpiration() { 073 return (Long) getHeader(JmsHeaders.EXPIRATION); 074 } 075 076 /** 077 * Return the {@link JmsHeaders#MESSAGE_ID message id}. 078 * @see JmsHeaders#MESSAGE_ID 079 */ 080 public String getMessageId() { 081 return (String) getHeader(JmsHeaders.MESSAGE_ID); 082 } 083 084 /** 085 * Return the {@link JmsHeaders#PRIORITY priority}. 086 * @see JmsHeaders#PRIORITY 087 */ 088 public Integer getPriority() { 089 return (Integer) getHeader(JmsHeaders.PRIORITY); 090 } 091 092 /** 093 * Return the {@link JmsHeaders#REPLY_TO reply to}. 094 * @see JmsHeaders#REPLY_TO 095 */ 096 public Destination getReplyTo() { 097 return (Destination) getHeader(JmsHeaders.REPLY_TO); 098 } 099 100 /** 101 * Return the {@link JmsHeaders#REDELIVERED redelivered} flag. 102 * @see JmsHeaders#REDELIVERED 103 */ 104 public Boolean getRedelivered() { 105 return (Boolean) getHeader(JmsHeaders.REDELIVERED); 106 } 107 108 /** 109 * Return the {@link JmsHeaders#TYPE type}. 110 * @see JmsHeaders#TYPE 111 */ 112 public String getType() { 113 return (String) getHeader(JmsHeaders.TYPE); 114 } 115 116 /** 117 * Return the {@link JmsHeaders#TIMESTAMP timestamp}. 118 * @see JmsHeaders#TIMESTAMP 119 */ 120 @Override 121 public Long getTimestamp() { 122 return (Long) getHeader(JmsHeaders.TIMESTAMP); 123 } 124 125 126 // Static factory method 127 128 /** 129 * Create a {@link JmsMessageHeaderAccessor} from the headers of an existing message. 130 */ 131 public static JmsMessageHeaderAccessor wrap(Message<?> message) { 132 return new JmsMessageHeaderAccessor(message); 133 } 134 135}