Search in sources :

Example 36 with SourcePollingChannelAdapter

use of org.springframework.integration.endpoint.SourcePollingChannelAdapter in project spring-integration by spring-projects.

the class SftpMessageHistoryTests method testMessageHistoryCompliance.

@Test
public void testMessageHistoryCompliance() {
    ClassPathXmlApplicationContext ac = new ClassPathXmlApplicationContext("MessageHistory-context.xml", SftpMessageHistoryTests.class);
    SourcePollingChannelAdapter spca = ac.getBean("sftpAdapter", SourcePollingChannelAdapter.class);
    assertEquals("sftpAdapter", spca.getComponentName());
    assertEquals("sftp:inbound-channel-adapter", spca.getComponentType());
    ac.close();
}
Also used : ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) SourcePollingChannelAdapter(org.springframework.integration.endpoint.SourcePollingChannelAdapter) Test(org.junit.Test)

Example 37 with SourcePollingChannelAdapter

use of org.springframework.integration.endpoint.SourcePollingChannelAdapter in project spring-integration-samples by spring-projects.

the class FileTransferRenameAfterFailureDemo method main.

public static void main(String[] args) throws Exception {
    LOGGER.info("\n=========================================================" + "\n                                                         " + "\n          Welcome to Spring Integration!                 " + "\n                                                         " + "\n    For more information please visit:                   " + "\n    http://www.springsource.org/spring-integration       " + "\n                                                         " + "\n=========================================================");
    final AbstractApplicationContext context = new ClassPathXmlApplicationContext("classpath:META-INF/spring/integration/expression-advice-context.xml");
    context.registerShutdownHook();
    @SuppressWarnings("unchecked") SessionFactory<FTPFile> sessionFactory = context.getBean(SessionFactory.class);
    SourcePollingChannelAdapter fileInbound = context.getBean(SourcePollingChannelAdapter.class);
    when(sessionFactory.getSession()).thenThrow(new RuntimeException("Force Failure"));
    fileInbound.start();
    LOGGER.info("\n=========================================================" + "\n                                                          " + "\n    This is the Expression Advice Sample -                " + "\n                                                          " + "\n    Press 'Enter' to terminate.                           " + "\n                                                          " + "\n    Place a file in " + System.getProperty("java.io.tmpdir") + "/adviceDemo ending   " + "\n    with .txt                                             " + "\n    The demo simulates a file transfer failure followed   " + "\n    by the Advice renaming the file; the result of the    " + "\n    rename is logged.                                     " + "\n                                                          " + "\n=========================================================");
    System.in.read();
    context.close();
    System.exit(0);
}
Also used : AbstractApplicationContext(org.springframework.context.support.AbstractApplicationContext) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) SourcePollingChannelAdapter(org.springframework.integration.endpoint.SourcePollingChannelAdapter) FTPFile(org.apache.commons.net.ftp.FTPFile)

Example 38 with SourcePollingChannelAdapter

use of org.springframework.integration.endpoint.SourcePollingChannelAdapter in project spring-integration-samples by spring-projects.

the class FileTransferDeleteAfterSuccessDemo method main.

public static void main(String[] args) throws Exception {
    LOGGER.info("\n=========================================================" + "\n                                                         " + "\n          Welcome to Spring Integration!                 " + "\n                                                         " + "\n    For more information please visit:                   " + "\n    http://www.springsource.org/spring-integration       " + "\n                                                         " + "\n=========================================================");
    final AbstractApplicationContext context = new ClassPathXmlApplicationContext("classpath:META-INF/spring/integration/expression-advice-context.xml");
    context.registerShutdownHook();
    @SuppressWarnings("unchecked") SessionFactory<FTPFile> sessionFactory = context.getBean(SessionFactory.class);
    SourcePollingChannelAdapter fileInbound = context.getBean(SourcePollingChannelAdapter.class);
    @SuppressWarnings("unchecked") Session<FTPFile> session = mock(Session.class);
    when(sessionFactory.getSession()).thenReturn(session);
    fileInbound.start();
    LOGGER.info("\n=========================================================" + "\n                                                          " + "\n    This is the Expression Advice Sample -                " + "\n                                                          " + "\n    Press 'Enter' to terminate.                           " + "\n                                                          " + "\n    Place a file in ${java.io.tmpdir}/adviceDemo ending   " + "\n    with .txt                                             " + "\n    The demo simulates a file transfer followed by the    " + "\n    Advice deleting the file; the result of the deletion  " + "\n    is logged.                                            " + "\n                                                          " + "\n=========================================================");
    System.in.read();
    context.close();
    System.exit(0);
}
Also used : AbstractApplicationContext(org.springframework.context.support.AbstractApplicationContext) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) SourcePollingChannelAdapter(org.springframework.integration.endpoint.SourcePollingChannelAdapter) FTPFile(org.apache.commons.net.ftp.FTPFile)

Example 39 with SourcePollingChannelAdapter

use of org.springframework.integration.endpoint.SourcePollingChannelAdapter in project spring-integration by spring-projects.

the class InboundChannelAdapterExpressionTests method testInt2867InnerExpression.

@Test
public void testInt2867InnerExpression() {
    SourcePollingChannelAdapter adapter = context.getBean("expressionElement", SourcePollingChannelAdapter.class);
    Expression expression = TestUtils.getPropertyValue(adapter, "source.expression", Expression.class);
    assertEquals("'Hello World!'", expression.getExpressionString());
}
Also used : Expression(org.springframework.expression.Expression) SourcePollingChannelAdapter(org.springframework.integration.endpoint.SourcePollingChannelAdapter) Test(org.junit.Test)

Example 40 with SourcePollingChannelAdapter

use of org.springframework.integration.endpoint.SourcePollingChannelAdapter in project spring-integration by spring-projects.

the class InboundChannelAdapterExpressionTests method fixedRate.

@Test
public void fixedRate() {
    SourcePollingChannelAdapter adapter = context.getBean("fixedRateProducer", SourcePollingChannelAdapter.class);
    assertFalse(adapter.isAutoStartup());
    DirectFieldAccessor adapterAccessor = new DirectFieldAccessor(adapter);
    Trigger trigger = TestUtils.getPropertyValue(adapter, "trigger", Trigger.class);
    assertEquals(PeriodicTrigger.class, trigger.getClass());
    DirectFieldAccessor triggerAccessor = new DirectFieldAccessor(trigger);
    assertEquals(5678L, triggerAccessor.getPropertyValue("period"));
    assertEquals(Boolean.TRUE, triggerAccessor.getPropertyValue("fixedRate"));
    assertEquals(context.getBean("fixedRateChannel"), adapterAccessor.getPropertyValue("outputChannel"));
    Expression expression = TestUtils.getPropertyValue(adapter, "source.expression", Expression.class);
    assertEquals("'fixedRateTest'", expression.getExpressionString());
}
Also used : PeriodicTrigger(org.springframework.scheduling.support.PeriodicTrigger) Trigger(org.springframework.scheduling.Trigger) CronTrigger(org.springframework.scheduling.support.CronTrigger) Expression(org.springframework.expression.Expression) DirectFieldAccessor(org.springframework.beans.DirectFieldAccessor) SourcePollingChannelAdapter(org.springframework.integration.endpoint.SourcePollingChannelAdapter) Test(org.junit.Test)

Aggregations

SourcePollingChannelAdapter (org.springframework.integration.endpoint.SourcePollingChannelAdapter)66 Test (org.junit.Test)58 ClassPathXmlApplicationContext (org.springframework.context.support.ClassPathXmlApplicationContext)29 Message (org.springframework.messaging.Message)15 PollableChannel (org.springframework.messaging.PollableChannel)13 Collection (java.util.Collection)10 ArrayList (java.util.ArrayList)9 QueueChannel (org.springframework.integration.channel.QueueChannel)9 JpaExecutor (org.springframework.integration.jpa.core.JpaExecutor)9 Consumer (org.springframework.integration.jpa.test.Consumer)9 DirectFieldAccessor (org.springframework.beans.DirectFieldAccessor)8 PeriodicTrigger (org.springframework.scheduling.support.PeriodicTrigger)8 Trigger (org.springframework.scheduling.Trigger)7 ConfigurableApplicationContext (org.springframework.context.ConfigurableApplicationContext)6 Expression (org.springframework.expression.Expression)6 CountDownLatch (java.util.concurrent.CountDownLatch)5 BeanFactory (org.springframework.beans.factory.BeanFactory)5 RedisConnectionFactory (org.springframework.data.redis.connection.RedisConnectionFactory)5 RedisAvailable (org.springframework.integration.redis.rules.RedisAvailable)5 File (java.io.File)4