use of org.springframework.messaging.support.ErrorMessage in project spring-integration by spring-projects.
the class TcpNioConnectionReadTests method testCloseCleanupPartialData.
/**
* Tests socket closure when no data received.
* @throws Exception
*/
@Test
public void testCloseCleanupPartialData() throws Exception {
ByteArrayCrLfSerializer serializer = new ByteArrayCrLfSerializer();
serializer.setMaxMessageSize(1024);
final Semaphore semaphore = new Semaphore(0);
final List<TcpConnection> added = new ArrayList<TcpConnection>();
final List<TcpConnection> removed = new ArrayList<TcpConnection>();
final CountDownLatch errorMessageLetch = new CountDownLatch(1);
final AtomicReference<Throwable> errorMessageRef = new AtomicReference<Throwable>();
AbstractServerConnectionFactory scf = getConnectionFactory(serializer, message -> {
if (message instanceof ErrorMessage) {
errorMessageRef.set(((ErrorMessage) message).getPayload());
errorMessageLetch.countDown();
}
return false;
}, new TcpSender() {
@Override
public void addNewConnection(TcpConnection connection) {
added.add(connection);
semaphore.release();
}
@Override
public void removeDeadConnection(TcpConnection connection) {
removed.add(connection);
semaphore.release();
}
});
Socket socket = SocketFactory.getDefault().createSocket("localhost", scf.getPort());
socket.getOutputStream().write("partial".getBytes());
socket.close();
whileOpen(semaphore, added);
assertEquals(1, added.size());
assertTrue(errorMessageLetch.await(10, TimeUnit.SECONDS));
assertThat(errorMessageRef.get().getMessage(), anyOf(containsString("Connection is closed"), containsString("Socket closed during message assembly")));
assertTrue(semaphore.tryAcquire(10000, TimeUnit.MILLISECONDS));
assertTrue(removed.size() > 0);
scf.stop();
}
use of org.springframework.messaging.support.ErrorMessage in project spring-integration by spring-projects.
the class AbstractMongoDbMessageStoreTests method testInt3076ErrorMessage.
@Test
@MongoDbAvailable
public void testInt3076ErrorMessage() throws Exception {
MessageStore store = this.getMessageStore();
Person p = new Person();
p.setFname("John");
p.setLname("Doe");
Message<Person> failedMessage = MessageBuilder.withPayload(p).build();
MessagingException messagingException;
try {
throw new RuntimeException("intentional");
} catch (Exception e) {
messagingException = new MessagingException(failedMessage, "intentional MessagingException", e);
}
Message<?> messageToStore = new ErrorMessage(messagingException);
store.addMessage(messageToStore);
Message<?> retrievedMessage = store.getMessage(messageToStore.getHeaders().getId());
assertNotNull(retrievedMessage);
assertTrue(retrievedMessage instanceof ErrorMessage);
assertThat(retrievedMessage.getPayload(), Matchers.instanceOf(MessagingException.class));
assertThat(((MessagingException) retrievedMessage.getPayload()).getMessage(), containsString("intentional MessagingException"));
assertEquals(failedMessage, ((MessagingException) retrievedMessage.getPayload()).getFailedMessage());
assertEquals(messageToStore.getHeaders(), retrievedMessage.getHeaders());
}
use of org.springframework.messaging.support.ErrorMessage in project spring-integration by spring-projects.
the class ChatMessageListeningEndpointTests method testWithErrorChannel.
@Test
public void testWithErrorChannel() throws Exception {
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
XMPPConnection connection = mock(XMPPConnection.class);
bf.registerSingleton(XmppContextUtils.XMPP_CONNECTION_BEAN_NAME, connection);
ChatMessageListeningEndpoint endpoint = new ChatMessageListeningEndpoint();
DirectChannel outChannel = new DirectChannel();
outChannel.subscribe(message -> {
throw new RuntimeException("ooops");
});
PollableChannel errorChannel = new QueueChannel();
endpoint.setBeanFactory(bf);
endpoint.setOutputChannel(outChannel);
endpoint.setErrorChannel(errorChannel);
endpoint.afterPropertiesSet();
StanzaListener listener = (StanzaListener) TestUtils.getPropertyValue(endpoint, "stanzaListener");
Message smackMessage = new Message(JidCreate.from("kermit@frog.com"));
smackMessage.setBody("hello");
smackMessage.setThread("1234");
listener.processStanza(smackMessage);
ErrorMessage msg = (ErrorMessage) errorChannel.receive();
assertEquals("hello", ((MessagingException) msg.getPayload()).getFailedMessage().getPayload());
}
use of org.springframework.messaging.support.ErrorMessage in project spring-framework by spring-projects.
the class MessageMethodArgumentResolverTests method resolveMessageSubclassMatch.
@Test
public void resolveMessageSubclassMatch() throws Exception {
ErrorMessage message = new ErrorMessage(new UnsupportedOperationException());
MethodParameter parameter = new MethodParameter(this.method, 4);
assertThat(this.resolver.supportsParameter(parameter)).isTrue();
assertThat(this.resolver.resolveArgument(parameter, message)).isSameAs(message);
}
Aggregations