use of org.springframework.integration.core.MessagingTemplate in project spring-integration by spring-projects.
the class ExtractRequestReplyPayloadTests method testOutboundInboundDefaultIsTx.
@Test
public void testOutboundInboundDefaultIsTx() {
this.outboundGateway.setExtractRequestPayload(true);
this.outboundGateway.setExtractReplyPayload(true);
this.inboundGateway.setExtractReplyPayload(true);
this.inboundGateway.setExtractRequestPayload(true);
final AtomicBoolean failOnce = new AtomicBoolean();
MessageHandler handler = message -> {
assertTrue(message.getPayload() instanceof String);
if (failOnce.compareAndSet(false, true)) {
throw new RuntimeException("test tx");
}
MessagingTemplate template = new MessagingTemplate();
template.setDefaultDestination((MessageChannel) message.getHeaders().getReplyChannel());
template.send(message);
};
this.jmsInputChannel.subscribe(handler);
this.outboundChannel.send(new GenericMessage<String>("Hello " + this.testName.getMethodName()));
Message<?> replyMessage = this.replyChannel.receive(10000);
assertTrue(replyMessage.getPayload() instanceof String);
this.jmsInputChannel.unsubscribe(handler);
}
use of org.springframework.integration.core.MessagingTemplate in project spring-integration by spring-projects.
the class JmsOutboundGatewayParserTests method gatewayMaintainsReplyChannelAndInboundHistory.
@Test
public void gatewayMaintainsReplyChannelAndInboundHistory() {
ActiveMqTestUtils.prepare();
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("gatewayMaintainsReplyChannel.xml", this.getClass());
SampleGateway gateway = context.getBean("gateway", SampleGateway.class);
SubscribableChannel jmsInput = context.getBean("jmsInput", SubscribableChannel.class);
MessageHandler handler = message -> {
MessageHistory history = MessageHistory.read(message);
assertNotNull(history);
Properties componentHistoryRecord = TestUtils.locateComponentInHistory(history, "inboundGateway", 0);
assertNotNull(componentHistoryRecord);
assertEquals("jms:inbound-gateway", componentHistoryRecord.get("type"));
MessagingTemplate messagingTemplate = new MessagingTemplate();
messagingTemplate.setDefaultDestination((MessageChannel) message.getHeaders().getReplyChannel());
messagingTemplate.send(message);
};
jmsInput.subscribe(handler);
String result = gateway.echo("hello");
assertEquals("hello", result);
JmsOutboundGateway gw1 = context.getBean("chain1$child.gateway.handler", JmsOutboundGateway.class);
MessageChannel out = TestUtils.getPropertyValue(gw1, "outputChannel", MessageChannel.class);
assertThat(out.getClass().getSimpleName(), equalTo("ReplyForwardingMessageChannel"));
JmsOutboundGateway gw2 = context.getBean("chain2$child.gateway.handler", JmsOutboundGateway.class);
out = TestUtils.getPropertyValue(gw2, "outputChannel", MessageChannel.class);
assertThat(out.getClass().getName(), containsString("MessageHandlerChain$"));
context.close();
}
use of org.springframework.integration.core.MessagingTemplate in project spring-integration by spring-projects.
the class XmppHeaderEnricherParserTests method to.
@SuppressWarnings("rawtypes")
@Test
public void to() {
MessagingTemplate messagingTemplate = new MessagingTemplate();
MessageHandler handler = mock(MessageHandler.class);
doAnswer(invocation -> {
Message message = invocation.getArgument(0);
String chatToUser = (String) message.getHeaders().get(XmppHeaders.TO);
assertNotNull(chatToUser);
assertEquals("test1@example.org", chatToUser);
return null;
}).when(handler).handleMessage(Mockito.any(Message.class));
output.subscribe(handler);
messagingTemplate.send(input, MessageBuilder.withPayload("foo").build());
verify(handler, times(1)).handleMessage(Mockito.any(Message.class));
}
Aggregations