use of org.springframework.integration.handler.AbstractReplyProducingMessageHandler in project spring-integration-samples by spring-projects.
the class TcpServerConnectionDeserializeTest method testHappyPath.
@Test
public void testHappyPath() {
// add a listener to this channel, otherwise there is not one defined
// the reason we use a listener here is so we can assert truths on the
// message and/or payload
SubscribableChannel channel = (SubscribableChannel) incomingServerChannel;
channel.subscribe(new AbstractReplyProducingMessageHandler() {
@Override
protected Object handleRequestMessage(Message<?> requestMessage) {
byte[] payload = (byte[]) requestMessage.getPayload();
// we assert during the processing of the messaging that the
// payload is just the content we wanted to send without the
// framing bytes (STX/ETX)
assertEquals("Hello World!", new String(payload));
return requestMessage;
}
});
String sourceMessage = wrapWithStxEtx("Hello World!");
String result = gw.send(sourceMessage);
System.out.println(result);
assertEquals("Hello World!", result);
}
use of org.springframework.integration.handler.AbstractReplyProducingMessageHandler in project spring-cloud-stream by spring-cloud.
the class BindingServiceConfigurationTests method valdateImportedConfiguartionHandlerPostProcessing.
@Test
public void valdateImportedConfiguartionHandlerPostProcessing() {
ApplicationContext context = new SpringApplicationBuilder(TestChannelBinderConfiguration.getCompleteConfiguration(RootConfiguration.class)).web(WebApplicationType.NONE).run();
Map<String, AbstractReplyProducingMessageHandler> beansOfType = context.getBeansOfType(AbstractReplyProducingMessageHandler.class);
for (AbstractReplyProducingMessageHandler handler : beansOfType.values()) {
assertTrue(handler.getNotPropagatedHeaders().contains("contentType"));
}
}
use of org.springframework.integration.handler.AbstractReplyProducingMessageHandler in project spring-integration by spring-projects.
the class EnricherParserTests4 method nullResultIntegrationTest.
@Test
public void nullResultIntegrationTest() {
SubscribableChannel requests = context.getBean("requests", SubscribableChannel.class);
class NullFoo extends AbstractReplyProducingMessageHandler {
@Override
protected Object handleRequestMessage(Message<?> requestMessage) {
return null;
}
}
NullFoo foo = new NullFoo();
foo.setOutputChannel(context.getBean("replies", MessageChannel.class));
requests.subscribe(foo);
Target original = new Target();
Message<?> request = MessageBuilder.withPayload(original).setHeader("sourceName", "test").setHeader("notOverwrite", "test").build();
context.getBean("input", MessageChannel.class).send(request);
Message<?> reply = context.getBean("output", PollableChannel.class).receive(0);
Target enriched = (Target) reply.getPayload();
assertEquals("Could not determine the name", enriched.getName());
assertEquals(11, enriched.getAge());
assertEquals(null, enriched.getGender());
assertTrue(enriched.isMarried());
assertNotSame(original, enriched);
assertEquals(1, adviceCalled);
MessageHeaders headers = reply.getHeaders();
assertEquals("Could not determine the foo", headers.get("foo"));
assertEquals("Could not determine the testBean", headers.get("testBean"));
assertEquals("Could not determine the sourceName", headers.get("sourceName"));
assertEquals("test", headers.get("notOverwrite"));
adviceCalled--;
requests.unsubscribe(foo);
}
use of org.springframework.integration.handler.AbstractReplyProducingMessageHandler in project spring-integration by spring-projects.
the class EnricherParserWithRequestPayloadExpressionTests method integrationTest.
@Test
public void integrationTest() {
SubscribableChannel requests = context.getBean("requests", SubscribableChannel.class);
requests.subscribe(new AbstractReplyProducingMessageHandler() {
@Override
protected Object handleRequestMessage(Message<?> requestMessage) {
assertTrue("Expected the payload of the requestMessage to be a String", requestMessage.getPayload() instanceof Integer);
Integer payload = (Integer) requestMessage.getPayload();
assertEquals("Expected value: 99", Integer.valueOf(99), payload);
return new Source(String.valueOf(payload));
}
});
Target original = new Target();
original.setAge(99);
Message<?> request = MessageBuilder.withPayload(original).build();
context.getBean("input", MessageChannel.class).send(request);
Message<?> reply = context.getBean("output", PollableChannel.class).receive(0);
Target enriched = (Target) reply.getPayload();
assertEquals("Name as SpEL", enriched.getName());
assertEquals(99, enriched.getAge());
assertSame(original, enriched);
}
use of org.springframework.integration.handler.AbstractReplyProducingMessageHandler in project spring-integration by spring-projects.
the class ContentEnricherTests method testErrorChannel.
/**
* In this test a {@link Target} message is passed into a {@link ContentEnricher}.
* The Enricher passes the message to a "request-channel" to a handler which throws
* an exception. The {@link ContentEnricher} then uses the error flow and consults
* the "error-channel" which returns a alternative {@link Target}.
*/
@Test
public void testErrorChannel() throws Exception {
final DirectChannel requestChannel = new DirectChannel();
requestChannel.subscribe(new AbstractReplyProducingMessageHandler() {
@Override
protected Object handleRequestMessage(Message<?> requestMessage) {
throw new RuntimeException();
}
});
final DirectChannel errorChannel = new DirectChannel();
errorChannel.subscribe(new AbstractReplyProducingMessageHandler() {
@Override
protected Object handleRequestMessage(Message<?> requestMessage) {
return new Target("failed");
}
});
final QueueChannel replyChannel = new QueueChannel();
final ContentEnricher enricher = new ContentEnricher();
enricher.setRequestChannel(requestChannel);
enricher.setErrorChannel(errorChannel);
SpelExpressionParser parser = new SpelExpressionParser();
Map<String, Expression> propertyExpressions = new HashMap<String, Expression>();
propertyExpressions.put("name", parser.parseExpression("payload.name + ' target'"));
enricher.setPropertyExpressions(propertyExpressions);
enricher.setBeanFactory(mock(BeanFactory.class));
enricher.afterPropertiesSet();
final Target target = new Target("replace me");
Message<?> requestMessage = MessageBuilder.withPayload(target).setReplyChannel(replyChannel).build();
enricher.handleMessage(requestMessage);
Message<?> reply = replyChannel.receive(10000);
Target result = (Target) reply.getPayload();
assertEquals("failed target", result.getName());
}
Aggregations