Java tutorial
/* * Copyright 2002-2016 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.aeg.ims.transfer.protocol.ftp; import org.apache.commons.io.FileUtils; import org.springframework.context.ConfigurableApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext; import org.springframework.integration.support.MessageBuilder; import org.springframework.messaging.Message; import org.springframework.messaging.MessageChannel; import java.io.File; import java.io.InputStream; /** * * @author Oleg Zhurakousky * @author Gunnar Hillert * */ public class OutboundChannelAdapter { private final File baseFolder = new File("target" + File.separator + "toSend"); public void runDemo() throws Exception { ConfigurableApplicationContext ctx = new ClassPathXmlApplicationContext( "classpath:partners/CRH/OutboundChannelAdapter.xml"); MessageChannel ftpChannel = ctx.getBean("ftpChannel", MessageChannel.class); baseFolder.mkdirs(); final File fileToSendA = new File(baseFolder, "a.txt"); final File fileToSendB = new File(baseFolder, "b.txt"); final InputStream inputStreamA = OutboundChannelAdapter.class.getResourceAsStream("/test-files/a.txt"); final InputStream inputStreamB = OutboundChannelAdapter.class.getResourceAsStream("/test-files/b.txt"); FileUtils.copyInputStreamToFile(inputStreamA, fileToSendA); FileUtils.copyInputStreamToFile(inputStreamB, fileToSendB); //assertTrue(fileToSendA.exists()); //assertTrue(fileToSendB.exists()); final Message<File> messageA = MessageBuilder.withPayload(fileToSendA).build(); final Message<File> messageB = MessageBuilder.withPayload(fileToSendB).build(); ftpChannel.send(messageA); ftpChannel.send(messageB); Thread.sleep(2000); //assertTrue(new File(TestSuite.FTP_ROOT_DIR + File.separator + "a.txt").exists()); //assertTrue(new File(TestSuite.FTP_ROOT_DIR + File.separator + "b.txt").exists()); ctx.close(); } }