use of org.springframework.messaging.support.GenericMessage in project spring-framework by spring-projects.
the class GenericMessagingTemplateTests method sendAndReceive.
@Test
public void sendAndReceive() {
SubscribableChannel channel = new ExecutorSubscribableChannel(this.executor);
channel.subscribe(new MessageHandler() {
@Override
public void handleMessage(Message<?> message) throws MessagingException {
MessageChannel replyChannel = (MessageChannel) message.getHeaders().getReplyChannel();
replyChannel.send(new GenericMessage<>("response"));
}
});
String actual = this.template.convertSendAndReceive(channel, "request", String.class);
assertEquals("response", actual);
}
use of org.springframework.messaging.support.GenericMessage in project spring-framework by spring-projects.
the class MessageReceivingTemplateTests method receiveAndConvertNoConverter.
@Test
public void receiveAndConvertNoConverter() {
Message<?> expected = new GenericMessage<Object>("payload");
this.template.setDefaultDestination("home");
this.template.setReceiveMessage(expected);
this.template.setMessageConverter(new GenericMessageConverter());
try {
this.template.receiveAndConvert(Writer.class);
} catch (MessageConversionException ex) {
assertTrue("Invalid exception message '" + ex.getMessage() + "'", ex.getMessage().contains("payload"));
assertSame(expected, ex.getFailedMessage());
}
}
use of org.springframework.messaging.support.GenericMessage in project spring-framework by spring-projects.
the class MessageMethodArgumentResolverTests method resolveWithWrongMessageType.
@Test
public void resolveWithWrongMessageType() throws Exception {
UnsupportedOperationException ex = new UnsupportedOperationException();
Message<? extends Throwable> message = new GenericMessage<Throwable>(ex);
MethodParameter parameter = new MethodParameter(this.method, 4);
assertTrue(this.resolver.supportsParameter(parameter));
thrown.expect(MethodArgumentTypeMismatchException.class);
thrown.expectMessage(ErrorMessage.class.getName());
thrown.expectMessage(GenericMessage.class.getName());
assertSame(message, this.resolver.resolveArgument(parameter, message));
}
use of org.springframework.messaging.support.GenericMessage in project spring-framework by spring-projects.
the class GenericMessagingTemplateTests method sendAndReceiveTimeout.
@Test
public void sendAndReceiveTimeout() throws InterruptedException {
final AtomicReference<Throwable> failure = new AtomicReference<Throwable>();
final CountDownLatch latch = new CountDownLatch(1);
this.template.setReceiveTimeout(1);
this.template.setThrowExceptionOnLateReply(true);
SubscribableChannel channel = new ExecutorSubscribableChannel(this.executor);
channel.subscribe(new MessageHandler() {
@Override
public void handleMessage(Message<?> message) throws MessagingException {
try {
Thread.sleep(500);
MessageChannel replyChannel = (MessageChannel) message.getHeaders().getReplyChannel();
replyChannel.send(new GenericMessage<>("response"));
failure.set(new IllegalStateException("Expected exception"));
} catch (InterruptedException e) {
failure.set(e);
} catch (MessageDeliveryException ex) {
String expected = "Reply message received but the receiving thread has exited due to a timeout";
String actual = ex.getMessage();
if (!expected.equals(actual)) {
failure.set(new IllegalStateException("Unexpected error: '" + actual + "'"));
}
} finally {
latch.countDown();
}
}
});
assertNull(this.template.convertSendAndReceive(channel, "request", String.class));
assertTrue(latch.await(1000, TimeUnit.MILLISECONDS));
Throwable ex = failure.get();
if (ex != null) {
throw new AssertionError(ex);
}
}
use of org.springframework.messaging.support.GenericMessage in project camel by apache.
the class SpringIntegrationConverter method toSpringMessage.
@Converter
public static org.springframework.messaging.Message<?> toSpringMessage(final org.apache.camel.Message camelMessage) throws Exception {
if (camelMessage instanceof SpringIntegrationMessage) {
SpringIntegrationMessage siMessage = (SpringIntegrationMessage) camelMessage;
org.springframework.messaging.Message<?> message = siMessage.getMessage();
if (message != null) {
return message;
}
}
// Create a new spring message and copy the attributes and body from the camel message
MessageHeaders messageHeaders = new MessageHeaders(camelMessage.getHeaders());
return new GenericMessage<Object>(camelMessage.getBody(), messageHeaders);
}
Aggregations