use of org.springframework.messaging.MessagingException in project spring-integration by spring-projects.
the class RoutingSlipTests method testInvalidRoutingSlipRoutStrategy.
@Test
public void testInvalidRoutingSlipRoutStrategy() {
try {
new RoutingSlipHeaderValueMessageProcessor(new Date());
fail("IllegalArgumentException expected");
} catch (Exception e) {
assertThat(e, instanceOf(IllegalArgumentException.class));
assertThat(e.getMessage(), containsString("The RoutingSlip can contain " + "only bean names of MessageChannel or RoutingSlipRouteStrategy, " + "or MessageChannel and RoutingSlipRouteStrategy instances"));
}
try {
this.invalidRoutingSlipChannel.send(new GenericMessage<>("foo"));
fail("MessagingException expected");
} catch (Exception e) {
assertThat(e, instanceOf(MessagingException.class));
assertThat(e.getMessage(), containsString("replyChannel must be a MessageChannel or String"));
}
}
use of org.springframework.messaging.MessagingException in project spring-integration by spring-projects.
the class TcpConnectionSupport method waitForListenerRegistration.
private void waitForListenerRegistration() {
try {
Assert.state(this.listenerRegisteredLatch.await(1, TimeUnit.MINUTES), "TcpListener not registered");
this.manualListenerRegistration = false;
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
throw new MessagingException("Interrupted while waiting for listener registration", e);
}
}
use of org.springframework.messaging.MessagingException in project spring-integration by spring-projects.
the class MBeanTreePollingMessageSource method doReceive.
/**
* Provides the mapped tree object
*/
@Override
protected Object doReceive() {
Assert.notNull(this.server, "MBeanServer is required");
try {
Map<String, Object> beans = new HashMap<String, Object>();
Set<ObjectInstance> results = this.server.queryMBeans(this.queryName, this.queryExpression);
for (ObjectInstance instance : results) {
Object result = this.converter.convert(this.server, instance);
beans.put(instance.getObjectName().getCanonicalName(), result);
}
return beans;
} catch (Exception e) {
throw new MessagingException("Failed to retrieve tree snapshot", e);
}
}
use of org.springframework.messaging.MessagingException in project spring-integration by spring-projects.
the class RemoteFileTemplate method sendFileToRemoteDirectory.
private void sendFileToRemoteDirectory(InputStream inputStream, String temporaryRemoteDirectory, String remoteDirectory, String fileName, Session<F> session, FileExistsMode mode) throws IOException {
remoteDirectory = this.normalizeDirectoryPath(remoteDirectory);
temporaryRemoteDirectory = this.normalizeDirectoryPath(temporaryRemoteDirectory);
String remoteFilePath = remoteDirectory + fileName;
String tempRemoteFilePath = temporaryRemoteDirectory + fileName;
// write remote file first with temporary file extension if enabled
String tempFilePath = tempRemoteFilePath + (this.useTemporaryFileName ? this.temporaryFileSuffix : "");
if (this.autoCreateDirectory) {
try {
RemoteFileUtils.makeDirectories(remoteDirectory, session, this.remoteFileSeparator, this.logger);
} catch (IllegalStateException e) {
// Revert to old FTP behavior if recursive mkdir fails, for backwards compatibility
session.mkdir(remoteDirectory);
}
}
try {
boolean rename = this.useTemporaryFileName;
if (FileExistsMode.REPLACE.equals(mode)) {
session.write(inputStream, tempFilePath);
} else if (FileExistsMode.APPEND.equals(mode)) {
session.append(inputStream, tempFilePath);
} else {
if (exists(remoteFilePath)) {
if (FileExistsMode.FAIL.equals(mode)) {
throw new MessagingException("The destination file already exists at '" + remoteFilePath + "'.");
} else {
if (this.logger.isDebugEnabled()) {
this.logger.debug("File not transferred to '" + remoteFilePath + "'; already exists.");
}
}
rename = false;
} else {
session.write(inputStream, tempFilePath);
}
}
// then rename it to its final name if necessary
if (rename) {
session.rename(tempFilePath, remoteFilePath);
}
} catch (Exception e) {
throw new MessagingException("Failed to write to '" + tempFilePath + "' while uploading the file", e);
} finally {
inputStream.close();
}
}
use of org.springframework.messaging.MessagingException in project spring-integration by spring-projects.
the class TcpSendingMessageHandlerTests method testConnectionException.
@Test
public void testConnectionException() throws Exception {
TcpSendingMessageHandler handler = new TcpSendingMessageHandler();
AbstractConnectionFactory mockCcf = mock(AbstractClientConnectionFactory.class);
Mockito.doAnswer(invocation -> {
throw new SocketException("Failed to connect");
}).when(mockCcf).getConnection();
handler.setConnectionFactory(mockCcf);
try {
handler.handleMessage(new GenericMessage<String>("foo"));
fail("Expected exception");
} catch (Exception e) {
assertTrue(e instanceof MessagingException);
assertTrue(e.getCause() != null);
assertTrue(e.getCause() instanceof SocketException);
assertEquals("Failed to connect", e.getCause().getMessage());
}
}
Aggregations