5050 * @since 4.2
5151 * @see org.springframework.jms.annotation.JmsListener
5252 * @see org.springframework.messaging.handler.annotation.SendTo
53+ * @param <T> the type of the response
5354 */
54- public class JmsResponse {
55+ public class JmsResponse < T > {
5556
56- private final Object response ;
57+ private final T response ;
5758
5859 private final Object destination ;
5960
@@ -62,7 +63,7 @@ public class JmsResponse {
6263 * @param response the content of the result
6364 * @param destination the destination
6465 */
65- protected JmsResponse (Object response , Object destination ) {
66+ protected JmsResponse (T response , Object destination ) {
6667 Assert .notNull (response , "Result must not be null" );
6768 this .response = response ;
6869 this .destination = destination ;
@@ -71,32 +72,42 @@ protected JmsResponse(Object response, Object destination) {
7172 /**
7273 * Create a {@link JmsResponse} targeting the queue with the specified name.
7374 */
74- public static JmsResponse forQueue (Object result , String queueName ) {
75+ public static < T > JmsResponse < T > forQueue (T result , String queueName ) {
7576 Assert .notNull (queueName , "Queue name must not be null" );
76- return new JmsResponse (result , new DestinationNameHolder (queueName , false ));
77+ return new JmsResponse < T > (result , new DestinationNameHolder (queueName , false ));
7778 }
7879
7980 /**
8081 * Create a {@link JmsResponse} targeting the topic with the specified name.
8182 */
82- public static JmsResponse forTopic (Object result , String topicName ) {
83+ public static < T > JmsResponse < T > forTopic (T result , String topicName ) {
8384 Assert .notNull (topicName , "Topic name must not be null" );
84- return new JmsResponse (result , new DestinationNameHolder (topicName , true ));
85+ return new JmsResponse < T > (result , new DestinationNameHolder (topicName , true ));
8586 }
8687
8788 /**
8889 * Create a {@link JmsResponse} targeting the specified {@link Destination}.
8990 */
90- public static JmsResponse forDestination (Object result , Destination destination ) {
91+ public static < T > JmsResponse < T > forDestination (T result , Destination destination ) {
9192 Assert .notNull (destination , "Destination must not be null" );
92- return new JmsResponse (result , destination );
93+ return new JmsResponse < T > (result , destination );
9394 }
9495
95-
96- public Object getResponse () {
97- return response ;
96+ /**
97+ * Return the content of the response.
98+ */
99+ public T getResponse () {
100+ return this .response ;
98101 }
99102
103+ /**
104+ * Resolve the {@link Destination} to use for this instance. The {@link DestinationResolver}
105+ * and {@link Session} can be used to resolve a destination at runtime.
106+ * @param destinationResolver the destination resolver to use if necessary
107+ * @param session the session to use, if necessary
108+ * @return the {@link Destination} to use
109+ * @throws JMSException if the DestinationResolver failed to resolve the destination
110+ */
100111 public Destination resolveDestination (DestinationResolver destinationResolver , Session session )
101112 throws JMSException {
102113
0 commit comments