/** * Create a {@link JmsResponse} targeting the specified {@link Destination}. */ public static <T> JmsResponse<T> forDestination(T result, Destination destination) { Assert.notNull(destination, "Destination must not be null"); return new JmsResponse<>(result, destination); }
@Test public void destinationDoesNotUseDestinationResolver() throws JMSException { Destination destination = mock(Destination.class); Destination actual = JmsResponse.forDestination("foo", destination).resolveDestination(null, null); assertSame(destination, actual); }
public JmsResponse<String> replyPayloadToQueue(Message<String> input) { return JmsResponse.forQueue(input.getPayload(), "queueOut"); }
@Test public void resolveDestinationForQueue() throws JMSException { Session session = mock(Session.class); DestinationResolver destinationResolver = mock(DestinationResolver.class); Destination destination = mock(Destination.class); given(destinationResolver.resolveDestinationName(session, "myQueue", false)).willReturn(destination); JmsResponse<String> jmsResponse = JmsResponse.forQueue("foo", "myQueue"); Destination actual = jmsResponse.resolveDestination(destinationResolver, session); assertSame(destination, actual); }
private Destination getResponseDestination(Message request, Message response, Session session, Object result) throws JMSException { if (result instanceof JmsResponse) { JmsResponse<?> jmsResponse = (JmsResponse) result; Destination destination = jmsResponse.resolveDestination(getDestinationResolver(), session); if (destination != null) { return destination; } } return getResponseDestination(request, response, session); }
/** * Build a JMS message to be sent as response based on the given result object. * @param session the JMS Session to operate on * @param result the content of the message, as returned from the listener method * @return the JMS {@code Message} (never {@code null}) * @throws JMSException if thrown by JMS API methods * @see #setMessageConverter */ protected Message buildMessage(Session session, Object result) throws JMSException { Object content = preProcessResponse(result instanceof JmsResponse ? ((JmsResponse<?>) result).getResponse() : result); MessageConverter converter = getMessageConverter(); if (converter != null) { if (content instanceof org.springframework.messaging.Message) { return this.messagingMessageConverter.toMessage(content, session); } else { return converter.toMessage(content, session); } } if (!(content instanceof Message)) { throw new MessageConversionException( "No MessageConverter specified - cannot handle message [" + content + "]"); } return (Message) content; }
public JmsResponse<String> replyPayloadToTopic(Message<String> input) { return JmsResponse.forTopic(input.getPayload(), "topicOut"); }
public JmsResponse<String> replyPayloadToDestination(Message<String> input) { return JmsResponse.forDestination(input.getPayload(), sharedReplyDestination); }
private Destination getResponseDestination(Message request, Message response, Session session, Object result) throws JMSException { if (result instanceof JmsResponse) { JmsResponse<?> jmsResponse = (JmsResponse) result; Destination destination = jmsResponse.resolveDestination(getDestinationResolver(), session); if (destination != null) { return destination; } } return getResponseDestination(request, response, session); }
/** * Build a JMS message to be sent as response based on the given result object. * @param session the JMS Session to operate on * @param result the content of the message, as returned from the listener method * @return the JMS {@code Message} (never {@code null}) * @throws JMSException if thrown by JMS API methods * @see #setMessageConverter */ protected Message buildMessage(Session session, Object result) throws JMSException { Object content = preProcessResponse(result instanceof JmsResponse ? ((JmsResponse<?>) result).getResponse() : result); MessageConverter converter = getMessageConverter(); if (converter != null) { if (content instanceof org.springframework.messaging.Message) { return this.messagingMessageConverter.toMessage(content, session); } else { return converter.toMessage(content, session); } } if (!(content instanceof Message)) { throw new MessageConversionException( "No MessageConverter specified - cannot handle message [" + content + "]"); } return (Message) content; }
@Test public void createWithNullTopicName() { thrown.expect(IllegalArgumentException.class); JmsResponse.forTopic("foo", null); }
@Test public void createWithNulDestination() { thrown.expect(IllegalArgumentException.class); JmsResponse.forDestination("foo", null); }
/** * Create a {@link JmsResponse} targeting the topic with the specified name. */ public static <T> JmsResponse<T> forTopic(T result, String topicName) { Assert.notNull(topicName, "Topic name must not be null"); return new JmsResponse<>(result, new DestinationNameHolder(topicName, true)); }
Destination destination = jmsResponse.resolveDestination(getDestinationResolver(), session); if (destination != null) { return destination;
/** * Build a JMS message to be sent as response based on the given result object. * @param session the JMS Session to operate on * @param result the content of the message, as returned from the listener method * @return the JMS {@code Message} (never {@code null}) * @throws JMSException if thrown by JMS API methods * @see #setMessageConverter */ protected Message buildMessage(Session session, Object result) throws JMSException { Object content = preProcessResponse(result instanceof JmsResponse ? ((JmsResponse<?>) result).getResponse() : result); MessageConverter converter = getMessageConverter(); if (converter != null) { if (content instanceof org.springframework.messaging.Message) { return this.messagingMessageConverter.toMessage(content, session); } else { return converter.toMessage(content, session); } } if (!(content instanceof Message)) { throw new MessageConversionException( "No MessageConverter specified - cannot handle message [" + content + "]"); } return (Message) content; }
@Test public void createWithNullQueueName() { thrown.expect(IllegalArgumentException.class); JmsResponse.forQueue("foo", null); }
/** * Create a {@link JmsResponse} targeting the queue with the specified name. */ public static <T> JmsResponse<T> forQueue(T result, String queueName) { Assert.notNull(queueName, "Queue name must not be null"); return new JmsResponse<>(result, new DestinationNameHolder(queueName, false)); }
@Test public void createWithNulResponse() { thrown.expect(IllegalArgumentException.class); JmsResponse.forQueue(null, "myQueue"); }
public JmsResponse<String> replyPayloadNoDestination(Message<String> input) { return new JmsResponse<>(input.getPayload(), null); }
/** * Create a {@link JmsResponse} targeting the specified {@link Destination}. */ public static <T> JmsResponse<T> forDestination(T result, Destination destination) { Assert.notNull(destination, "Destination must not be null"); return new JmsResponse<T>(result, destination); }