use of javax.jms.Destination in project spring-framework by spring-projects.
the class AbstractAdaptableMessageListener method handleResult.
/**
* Handle the given result object returned from the listener method,
* sending a response message back.
* @param result the result object to handle (never {@code null})
* @param request the original request message
* @param session the JMS Session to operate on (may be {@code null})
* @throws ReplyFailureException if the response message could not be sent
* @see #buildMessage
* @see #postProcessResponse
* @see #getResponseDestination
* @see #sendResponse
*/
protected void handleResult(Object result, Message request, Session session) {
if (session != null) {
if (logger.isDebugEnabled()) {
logger.debug("Listener method returned result [" + result + "] - generating response message for it");
}
try {
Message response = buildMessage(session, result);
postProcessResponse(request, response);
Destination destination = getResponseDestination(request, response, session, result);
sendResponse(session, destination, response);
} catch (Exception ex) {
throw new ReplyFailureException("Failed to send reply with payload [" + result + "]", ex);
}
} else {
// No JMS Session available
if (logger.isWarnEnabled()) {
logger.warn("Listener method returned result [" + result + "]: not generating response message for it because of no JMS Session given");
}
}
}
use of javax.jms.Destination in project spring-framework by spring-projects.
the class MethodJmsListenerEndpointTests method processAndReplyWithSendTo.
private void processAndReplyWithSendTo(MessagingMessageListenerAdapter listener, String replyDestinationName, boolean pubSubDomain) throws JMSException {
String body = "echo text";
String correlationId = "link-1234";
Destination replyDestination = new Destination() {
};
DestinationResolver destinationResolver = mock(DestinationResolver.class);
TextMessage reply = mock(TextMessage.class);
QueueSender queueSender = mock(QueueSender.class);
Session session = mock(Session.class);
given(destinationResolver.resolveDestinationName(session, replyDestinationName, pubSubDomain)).willReturn(replyDestination);
given(session.createTextMessage(body)).willReturn(reply);
given(session.createProducer(replyDestination)).willReturn(queueSender);
listener.setDestinationResolver(destinationResolver);
StubTextMessage inputMessage = createSimpleJmsTextMessage(body);
inputMessage.setJMSCorrelationID(correlationId);
listener.onMessage(inputMessage, session);
verify(destinationResolver).resolveDestinationName(session, replyDestinationName, pubSubDomain);
verify(reply).setJMSCorrelationID(correlationId);
verify(queueSender).send(reply);
verify(queueSender).close();
}
use of javax.jms.Destination in project spring-framework by spring-projects.
the class JmsResponseTests method resolveDestinationForQueue.
@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);
}
use of javax.jms.Destination in project spring-framework by spring-projects.
the class JmsMessagingTemplateTests method convertAndSendDefaultDestination.
@Test
public void convertAndSendDefaultDestination() throws JMSException {
Destination destination = new Destination() {
};
messagingTemplate.setDefaultDestination(destination);
messagingTemplate.convertAndSend("my Payload");
verify(jmsTemplate).send(eq(destination), messageCreator.capture());
TextMessage textMessage = createTextMessage(messageCreator.getValue());
assertEquals("my Payload", textMessage.getText());
}
use of javax.jms.Destination in project spring-framework by spring-projects.
the class JmsMessagingTemplateTests method sendAndReceive.
@Test
public void sendAndReceive() {
Destination destination = new Destination() {
};
Message<String> request = createTextMessage();
javax.jms.Message replyJmsMessage = createJmsTextMessage();
given(jmsTemplate.sendAndReceive(eq(destination), any())).willReturn(replyJmsMessage);
Message<?> actual = messagingTemplate.sendAndReceive(destination, request);
verify(jmsTemplate, times(1)).sendAndReceive(eq(destination), any());
assertTextMessage(actual);
}
Aggregations