use of org.springframework.integration.channel.QueueChannel in project spring-integration by spring-projects.
the class ServiceActivatorDefaultFrameworkMethodTests method testReplyingMessageHandlerWithStandardMethod.
@Test
public void testReplyingMessageHandlerWithStandardMethod() {
QueueChannel replyChannel = new QueueChannel();
Message<?> message = MessageBuilder.withPayload("test").setReplyChannel(replyChannel).build();
this.replyingHandlerWithStandardMethodTestInputChannel.send(message);
Message<?> reply = replyChannel.receive(0);
assertEquals("TEST", reply.getPayload());
assertEquals("replyingHandlerWithStandardMethodTestInputChannel,replyingHandlerWithStandardMethodTestService", reply.getHeaders().get("history").toString());
StackTraceElement[] st = (StackTraceElement[]) reply.getHeaders().get("callStack");
assertTrue(StackTraceUtils.isFrameContainingXBeforeFrameContainingY("AbstractSubscribableChannel", "MethodInvokerHelper", // close to the metal
st));
}
use of org.springframework.integration.channel.QueueChannel in project spring-integration by spring-projects.
the class AdvisedMessageHandlerTests method filterDiscardWithinAdvice.
@Test
public void filterDiscardWithinAdvice() {
MessageFilter filter = new MessageFilter(message -> false);
final QueueChannel discardChannel = new QueueChannel();
filter.setDiscardChannel(discardChannel);
List<Advice> adviceChain = new ArrayList<Advice>();
final AtomicReference<Message<?>> discardedWithinAdvice = new AtomicReference<Message<?>>();
adviceChain.add(new AbstractRequestHandlerAdvice() {
@Override
protected Object doInvoke(ExecutionCallback callback, Object target, Message<?> message) throws Exception {
Object result = callback.execute();
discardedWithinAdvice.set(discardChannel.receive(0));
return result;
}
});
filter.setAdviceChain(adviceChain);
filter.setBeanFactory(mock(BeanFactory.class));
filter.afterPropertiesSet();
filter.handleMessage(new GenericMessage<String>("foo"));
assertNotNull(discardedWithinAdvice.get());
assertNull(discardChannel.receive(0));
}
use of org.springframework.integration.channel.QueueChannel in project spring-integration by spring-projects.
the class AdvisedMessageHandlerTests method propagateOnFailureExpressionFailures.
@Test
public void propagateOnFailureExpressionFailures() {
final AtomicBoolean doFail = new AtomicBoolean(true);
AbstractReplyProducingMessageHandler handler = new AbstractReplyProducingMessageHandler() {
@Override
protected Object handleRequestMessage(Message<?> requestMessage) {
if (doFail.get()) {
throw new RuntimeException("qux");
}
return "baz";
}
};
QueueChannel replies = new QueueChannel();
handler.setOutputChannel(replies);
Message<String> message = new GenericMessage<String>("Hello, world!");
PollableChannel successChannel = new QueueChannel();
PollableChannel failureChannel = new QueueChannel();
ExpressionEvaluatingRequestHandlerAdvice advice = new ExpressionEvaluatingRequestHandlerAdvice();
advice.setBeanFactory(mock(BeanFactory.class));
advice.setSuccessChannel(successChannel);
advice.setFailureChannel(failureChannel);
advice.setOnSuccessExpressionString("1/0");
advice.setOnFailureExpressionString("1/0");
List<Advice> adviceChain = new ArrayList<Advice>();
adviceChain.add(advice);
handler.setAdviceChain(adviceChain);
handler.setBeanFactory(mock(BeanFactory.class));
handler.afterPropertiesSet();
// failing advice with failure
try {
handler.handleMessage(message);
fail("Expected exception");
} catch (Exception e) {
assertEquals("qux", e.getCause().getMessage());
}
Message<?> reply = replies.receive(1);
assertNull(reply);
Message<?> failure = failureChannel.receive(10000);
assertNotNull(failure);
assertEquals("Hello, world!", ((MessagingException) failure.getPayload()).getFailedMessage().getPayload());
assertEquals(MessageHandlingExpressionEvaluatingAdviceException.class, failure.getPayload().getClass());
assertEquals("qux", ((Exception) failure.getPayload()).getCause().getMessage());
// propagate failing advice with failure; expect original exception
advice.setPropagateEvaluationFailures(true);
try {
handler.handleMessage(message);
fail("Expected Exception");
} catch (MessageHandlingException e) {
assertEquals("qux", e.getCause().getMessage());
}
reply = replies.receive(1);
assertNull(reply);
failure = failureChannel.receive(10000);
assertNotNull(failure);
assertEquals("Hello, world!", ((MessagingException) failure.getPayload()).getFailedMessage().getPayload());
assertEquals(MessageHandlingExpressionEvaluatingAdviceException.class, failure.getPayload().getClass());
assertEquals("qux", ((Exception) failure.getPayload()).getCause().getMessage());
}
use of org.springframework.integration.channel.QueueChannel in project spring-integration by spring-projects.
the class ObjectToJsonTransformerParserTests method testNodeResultType.
@Test
public void testNodeResultType() {
TestPerson person = new TestPerson();
person.setFirstName("John");
person.setLastName("Doe");
person.setAge(42);
QueueChannel replyChannel = new QueueChannel();
Message<TestPerson> message = MessageBuilder.withPayload(person).setReplyChannel(replyChannel).build();
this.jsonNodeInput.send(message);
Message<?> reply = replyChannel.receive(0);
assertNotNull(reply);
Object payload = reply.getPayload();
assertThat(payload, Matchers.instanceOf(JsonNode.class));
StandardEvaluationContext evaluationContext = new StandardEvaluationContext();
evaluationContext.addPropertyAccessor(new JsonPropertyAccessor());
Expression expression = new SpelExpressionParser().parseExpression("firstName.toString() == 'John' and age.toString() == '42'");
assertTrue(expression.getValue(evaluationContext, payload, Boolean.class));
}
use of org.springframework.integration.channel.QueueChannel in project spring-integration by spring-projects.
the class ObjectToJsonTransformerParserTests method testInt2831CustomJsonObjectMapper.
@Test
public void testInt2831CustomJsonObjectMapper() {
TestPerson person = new TestPerson();
person.setFirstName("John");
person.setLastName("Doe");
person.setAge(42);
QueueChannel replyChannel = new QueueChannel();
Message<TestPerson> message = MessageBuilder.withPayload(person).setReplyChannel(replyChannel).build();
this.customJsonObjectMapperInput.send(message);
Message<?> reply = replyChannel.receive(0);
assertNotNull(reply);
assertNotNull(reply.getPayload());
assertEquals(String.class, reply.getPayload().getClass());
String resultString = (String) reply.getPayload();
assertEquals("{" + person.toString() + "}", resultString);
}
Aggregations