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; 021 022import javax.jms.Destination; 023 024import org.springframework.lang.Nullable; 025import org.springframework.messaging.Message; 026import org.springframework.messaging.support.NativeMessageHeaderAccessor; 027 028/** 029 * A {@link org.springframework.messaging.support.MessageHeaderAccessor} 030 * implementation giving access to JMS-specific headers. 031 * 032 * @author Stephane Nicoll 033 * @since 4.1 034 */ 035public class JmsMessageHeaderAccessor extends NativeMessageHeaderAccessor { 036 037 protected JmsMessageHeaderAccessor(Map<String, List<String>> nativeHeaders) { 038 super(nativeHeaders); 039 } 040 041 protected JmsMessageHeaderAccessor(Message<?> message) { 042 super(message); 043 } 044 045 046 /** 047 * Return the {@link JmsHeaders#CORRELATION_ID correlationId}. 048 * @see JmsHeaders#CORRELATION_ID 049 */ 050 @Nullable 051 public String getCorrelationId() { 052 return (String) getHeader(JmsHeaders.CORRELATION_ID); 053 } 054 055 /** 056 * Return the {@link JmsHeaders#DESTINATION destination}. 057 * @see JmsHeaders#DESTINATION 058 */ 059 @Nullable 060 public Destination getDestination() { 061 return (Destination) getHeader(JmsHeaders.DESTINATION); 062 } 063 064 /** 065 * Return the {@link JmsHeaders#DELIVERY_MODE delivery mode}. 066 * @see JmsHeaders#DELIVERY_MODE 067 */ 068 @Nullable 069 public Integer getDeliveryMode() { 070 return (Integer) getHeader(JmsHeaders.DELIVERY_MODE); 071 } 072 073 /** 074 * Return the message {@link JmsHeaders#EXPIRATION expiration}. 075 * @see JmsHeaders#EXPIRATION 076 */ 077 @Nullable 078 public Long getExpiration() { 079 return (Long) getHeader(JmsHeaders.EXPIRATION); 080 } 081 082 /** 083 * Return the {@link JmsHeaders#MESSAGE_ID message id}. 084 * @see JmsHeaders#MESSAGE_ID 085 */ 086 @Nullable 087 public String getMessageId() { 088 return (String) getHeader(JmsHeaders.MESSAGE_ID); 089 } 090 091 /** 092 * Return the {@link JmsHeaders#PRIORITY priority}. 093 * @see JmsHeaders#PRIORITY 094 */ 095 @Nullable 096 public Integer getPriority() { 097 return (Integer) getHeader(JmsHeaders.PRIORITY); 098 } 099 100 /** 101 * Return the {@link JmsHeaders#REPLY_TO reply to}. 102 * @see JmsHeaders#REPLY_TO 103 */ 104 @Nullable 105 public Destination getReplyTo() { 106 return (Destination) getHeader(JmsHeaders.REPLY_TO); 107 } 108 109 /** 110 * Return the {@link JmsHeaders#REDELIVERED redelivered} flag. 111 * @see JmsHeaders#REDELIVERED 112 */ 113 @Nullable 114 public Boolean getRedelivered() { 115 return (Boolean) getHeader(JmsHeaders.REDELIVERED); 116 } 117 118 /** 119 * Return the {@link JmsHeaders#TYPE type}. 120 * @see JmsHeaders#TYPE 121 */ 122 @Nullable 123 public String getType() { 124 return (String) getHeader(JmsHeaders.TYPE); 125 } 126 127 /** 128 * Return the {@link JmsHeaders#TIMESTAMP timestamp}. 129 * @see JmsHeaders#TIMESTAMP 130 */ 131 @Override 132 @Nullable 133 public Long getTimestamp() { 134 return (Long) getHeader(JmsHeaders.TIMESTAMP); 135 } 136 137 138 // Static factory method 139 140 /** 141 * Create a {@link JmsMessageHeaderAccessor} from the headers of an existing message. 142 */ 143 public static JmsMessageHeaderAccessor wrap(Message<?> message) { 144 return new JmsMessageHeaderAccessor(message); 145 } 146 147}