List of usage examples for org.springframework.integration.file.remote.handler FileTransferringMessageHandler handleMessage
@Override
public void handleMessage(Message<?> messageArg)
From source file:org.springframework.integration.ftp.outbound.FtpOutboundTests.java
@Test public void testHandleFileContentMessage() throws Exception { File file = new File("remote-target-dir/handlerContent.test"); if (file.exists()) { file.delete();/*from w w w. ja v a2s . c o m*/ } assertFalse(file.exists()); FileTransferringMessageHandler<FTPFile> handler = new FileTransferringMessageHandler<FTPFile>( sessionFactory); handler.setRemoteDirectoryExpression(new LiteralExpression("remote-target-dir")); handler.setFileNameGenerator(new FileNameGenerator() { public String generateFileName(Message<?> message) { return "handlerContent.test"; } }); handler.setBeanFactory(mock(BeanFactory.class)); handler.afterPropertiesSet(); handler.handleMessage(new GenericMessage<String>("hello")); assertTrue(file.exists()); }
From source file:org.springframework.integration.ftp.outbound.FtpOutboundTests.java
@Test public void testHandleFileAsByte() throws Exception { File file = new File("remote-target-dir/handlerContent.test"); if (file.exists()) { file.delete();//w w w .j ava 2 s .co m } assertFalse(file.exists()); FileTransferringMessageHandler<FTPFile> handler = new FileTransferringMessageHandler<FTPFile>( sessionFactory); handler.setRemoteDirectoryExpression(new LiteralExpression("remote-target-dir")); handler.setFileNameGenerator(new FileNameGenerator() { public String generateFileName(Message<?> message) { return "handlerContent.test"; } }); handler.setBeanFactory(mock(BeanFactory.class)); handler.afterPropertiesSet(); handler.handleMessage(new GenericMessage<byte[]>("hello".getBytes())); assertTrue(file.exists()); }
From source file:org.springframework.integration.ftp.outbound.FtpOutboundTests.java
@Test public void testHandleFileMessage() throws Exception { File targetDir = new File("remote-target-dir"); assertTrue("target directory does not exist: " + targetDir.getName(), targetDir.exists()); FileTransferringMessageHandler<FTPFile> handler = new FileTransferringMessageHandler<FTPFile>( sessionFactory);//from w w w . j av a 2 s.co m handler.setRemoteDirectoryExpression(new LiteralExpression(targetDir.getName())); handler.setFileNameGenerator(new FileNameGenerator() { public String generateFileName(Message<?> message) { return ((File) message.getPayload()).getName() + ".test"; } }); handler.setBeanFactory(mock(BeanFactory.class)); handler.afterPropertiesSet(); File srcFile = File.createTempFile("testHandleFileMessage", ".tmp"); srcFile.deleteOnExit(); File destFile = new File(targetDir, srcFile.getName() + ".test"); destFile.deleteOnExit(); handler.handleMessage(new GenericMessage<File>(srcFile)); assertTrue("destination file was not created", destFile.exists()); }
From source file:org.springframework.integration.ftp.outbound.FtpSendingMessageHandlerTests.java
@Test public void testHandleFileContentMessage() throws Exception { File file = new File("remote-target-dir/handlerContent.test"); if (file.exists()) { file.delete();//from w w w.j a va 2 s . com } assertFalse(file.exists()); FileTransferringMessageHandler<FTPFile> handler = new FileTransferringMessageHandler<FTPFile>( sessionFactory); handler.setRemoteDirectoryExpression(new LiteralExpression("remote-target-dir")); handler.setFileNameGenerator(new FileNameGenerator() { public String generateFileName(Message<?> message) { return "handlerContent.test"; } }); handler.afterPropertiesSet(); handler.handleMessage(new GenericMessage<String>("hello")); assertTrue(file.exists()); }
From source file:org.springframework.integration.ftp.outbound.FtpSendingMessageHandlerTests.java
@Test public void testHandleFileAsByte() throws Exception { File file = new File("remote-target-dir/handlerContent.test"); if (file.exists()) { file.delete();//from www . j a v a 2s . c o m } assertFalse(file.exists()); FileTransferringMessageHandler<FTPFile> handler = new FileTransferringMessageHandler<FTPFile>( sessionFactory); handler.setRemoteDirectoryExpression(new LiteralExpression("remote-target-dir")); handler.setFileNameGenerator(new FileNameGenerator() { public String generateFileName(Message<?> message) { return "handlerContent.test"; } }); handler.afterPropertiesSet(); handler.handleMessage(new GenericMessage<byte[]>("hello".getBytes())); assertTrue(file.exists()); }
From source file:org.springframework.integration.ftp.outbound.FtpSendingMessageHandlerTests.java
@Test public void testHandleFileMessage() throws Exception { File targetDir = new File("remote-target-dir"); assertTrue("target directory does not exist: " + targetDir.getName(), targetDir.exists()); FileTransferringMessageHandler<FTPFile> handler = new FileTransferringMessageHandler<FTPFile>( sessionFactory);//from www. ja va2 s. c o m handler.setRemoteDirectoryExpression(new LiteralExpression(targetDir.getName())); handler.setFileNameGenerator(new FileNameGenerator() { public String generateFileName(Message<?> message) { return ((File) message.getPayload()).getName() + ".test"; } }); handler.afterPropertiesSet(); File srcFile = File.createTempFile("testHandleFileMessage", ".tmp"); srcFile.deleteOnExit(); File destFile = new File(targetDir, srcFile.getName() + ".test"); destFile.deleteOnExit(); handler.handleMessage(new GenericMessage<File>(srcFile)); assertTrue("destination file was not created", destFile.exists()); }