protected void doHandleResult(InvocationResult resultArg, Message request, Channel channel, Object source) { if (this.logger.isDebugEnabled()) { this.logger.debug("Listener method returned result [" + resultArg + "] - generating response message for it"); } try { Message response = buildMessage(channel, resultArg.getReturnValue(), resultArg.getReturnType()); postProcessResponse(request, response); Address replyTo = getReplyToAddress(request, source, resultArg); sendResponse(channel, replyTo, response); } catch (Exception ex) { throw new ReplyFailureException("Failed to send reply with payload '" + resultArg + "'", ex); } }
@Test public void processAndReplyWithMessageAndStringReply() throws Exception { MessagingMessageListenerAdapter listener = createDefaultInstance(org.springframework.amqp.core.Message.class); listener.setMessageConverter(null); listener.setResponseExchange("fooQueue"); String body = "echo text"; org.springframework.amqp.core.Message message = MessageTestUtils.createTextMessage(body, new MessageProperties()); try { processAndReply(listener, message, "fooQueue", "", false, null); fail("Should have fail. Not converter and the reply is not a message"); } catch (ReplyFailureException ex) { Throwable cause = ex.getCause(); assertNotNull(cause); assertEquals(MessageConversionException.class, cause.getClass()); assertTrue(ex.getMessage().contains("foo")); // exception holds the content of the reply } assertDefaultListenerMethodInvocation(); }
assertThat(ex.getMessage(), containsString("Failed to send reply"));
protected void doHandleResult(InvocationResult resultArg, Message request, Channel channel, Object source) { if (this.logger.isDebugEnabled()) { this.logger.debug("Listener method returned result [" + resultArg + "] - generating response message for it"); } try { Message response = buildMessage(channel, resultArg.getReturnValue(), resultArg.getReturnType()); postProcessResponse(request, response); Address replyTo = getReplyToAddress(request, source, resultArg); sendResponse(channel, replyTo, response); } catch (Exception ex) { throw new ReplyFailureException("Failed to send reply with payload '" + resultArg + "'", ex); } }