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); }
/** * Set the name of the default response topic to send response messages to. * This will be applied in case of a request message that does not carry a * "JMSReplyTo" field. * <p>Alternatively, specify a JMS Destination object as "defaultResponseDestination". * @see #setDestinationResolver * @see #setDefaultResponseDestination(javax.jms.Destination) */ public void setDefaultResponseTopicName(String destinationName) { this.defaultResponseDestination = new DestinationNameHolder(destinationName, true); }
@SuppressWarnings("unchecked") @Override public Object fromMessage(javax.jms.Message message) throws JMSException, MessageConversionException { return new LazyResolutionMessage(message); }
@Test public void testWithMessageDelegate() throws Exception { TextMessage textMessage = mock(TextMessage.class); MessageDelegate delegate = mock(MessageDelegate.class); MessageListenerAdapter adapter = new MessageListenerAdapter(delegate); // we DON'T want the default SimpleMessageConversion happening... adapter.setMessageConverter(null); adapter.onMessage(textMessage); verify(delegate).handleMessage(textMessage); }
@Test public void testWithResponsiveMessageDelegate_DoesNotSendReturnTextMessageIfNoSessionSupplied() throws Exception { TextMessage textMessage = mock(TextMessage.class); ResponsiveMessageDelegate delegate = mock(ResponsiveMessageDelegate.class); given(delegate.handleMessage(textMessage)).willReturn(TEXT); MessageListenerAdapter adapter = new MessageListenerAdapter(delegate); // we DON'T want the default SimpleMessageConversion happening... adapter.setMessageConverter(null); adapter.onMessage(textMessage); }
/** * 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)); }
protected MessagingMessageListenerAdapter createInstance(Method m) { MessagingMessageListenerAdapter adapter = new MessagingMessageListenerAdapter(); adapter.setHandlerMethod(factory.createInvocableHandlerMethod(sample, m)); return adapter; }
@Bean public MessageListener simpleMessageListener() { return new MessageListenerAdapter(); } }
/** * Determine the name of the listener method that is supposed to * handle the given message. * <p>The default implementation simply returns the configured * default listener method, if any. * @param originalMessage the JMS request message * @param extractedMessage the converted JMS request message, * to be passed into the listener method as argument * @return the name of the listener method (never {@code null}) * @throws JMSException if thrown by JMS API methods * @see #setDefaultListenerMethod */ protected String getListenerMethodName(Message originalMessage, Object extractedMessage) throws JMSException { return getDefaultListenerMethod(); }
/** * Create an empty {@link MessagingMessageListenerAdapter} instance. * @return a new {@code MessagingMessageListenerAdapter} or subclass thereof */ protected MessagingMessageListenerAdapter createMessageListenerInstance() { return new MessagingMessageListenerAdapter(); }
/** * 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); }
/** * Set the {@link JmsHeaderMapper} implementation to use to map the standard * JMS headers. By default, a {@link SimpleJmsHeaderMapper} is used. * @see SimpleJmsHeaderMapper */ public void setHeaderMapper(JmsHeaderMapper headerMapper) { Assert.notNull(headerMapper, "HeaderMapper must not be null"); this.messagingMessageConverter.setHeaderMapper(headerMapper); }
/** * Extract the payload of the current message. Since we deferred the resolution * of the payload, a custom converter may still return a full message for it. In * this case, its payload is returned. * @return the payload of the message */ private Object unwrapPayload() throws JMSException { Object payload = extractPayload(this.message); if (payload instanceof org.springframework.messaging.Message) { return ((org.springframework.messaging.Message) payload).getPayload(); } return payload; }
@Override public Object getPayload() { if (this.payload == null) { try { this.payload = unwrapPayload(); } catch (JMSException ex) { throw new MessageConversionException( "Failed to extract payload from [" + this.message + "]", ex); } } return this.payload; }
private SampleResponse createSampleResponse(String name) { return new SampleResponse(name, "lengthy description"); }
@Before public void setup() { initializeFactory(factory); }
@Override protected void handleListenerException(Throwable ex) { assertNotNull("The Throwable passed to the handleListenerException(..) method must never be null.", ex); assertTrue("The Throwable passed to the handleListenerException(..) method must be of type [ListenerExecutionFailedException].", ex instanceof ListenerExecutionFailedException); ListenerExecutionFailedException lefx = (ListenerExecutionFailedException) ex; Throwable cause = lefx.getCause(); assertNotNull("The cause of a ListenerExecutionFailedException must be preserved.", cause); assertSame(exception, cause); } };
/** * 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)); }
private JmsListenerEndpoint createDummyEndpoint() { SimpleJmsListenerEndpoint endpoint = new SimpleJmsListenerEndpoint(); endpoint.setMessageListener(new MessageListenerAdapter()); endpoint.setDestination("testQueue"); return endpoint; }
/** * Set the name of the default response queue to send response messages to. * This will be applied in case of a request message that does not carry a * "JMSReplyTo" field. * <p>Alternatively, specify a JMS Destination object as "defaultResponseDestination". * @see #setDestinationResolver * @see #setDefaultResponseDestination(javax.jms.Destination) */ public void setDefaultResponseQueueName(String destinationName) { this.defaultResponseDestination = new DestinationNameHolder(destinationName, false); }