List of usage examples for org.springframework.messaging PollableChannel receive
@Nullable Message<?> receive();
From source file:com.aeg.ims.ftp.SftpInboundReceiveSample.java
public void runDemo() { ConfigurableApplicationContext context = new ClassPathXmlApplicationContext( "classpath:/META-INF/spring/integration/SftpInboundReceiveSample-context.xml"); RemoteFileTemplate<LsEntry> template = null; String file1 = "a.txt"; String file2 = "b.txt"; String file3 = "c.bar"; new File("local-dir", file1).delete(); new File("local-dir", file2).delete(); try {/*w ww . j a v a 2 s .c o m*/ PollableChannel localFileChannel = context.getBean("receiveChannel", PollableChannel.class); @SuppressWarnings("unchecked") SessionFactory<LsEntry> sessionFactory = context.getBean(CachingSessionFactory.class); template = new RemoteFileTemplate<LsEntry>(sessionFactory); SftpTestUtils.createTestFiles(template, file1, file2, file3); SourcePollingChannelAdapter adapter = context.getBean(SourcePollingChannelAdapter.class); adapter.start(); Message<?> received = localFileChannel.receive(); assertNotNull("Expected file", received); System.out.println("Received first file message: " + received); received = localFileChannel.receive(); assertNotNull("Expected file", received); System.out.println("Received second file message: " + received); received = localFileChannel.receive(1000); assertNull("Expected null", received); System.out.println("No third file was received as expected"); } finally { SftpTestUtils.cleanUp(template, file1, file2, file3); context.close(); assertTrue("Could note delete retrieved file", new File("local-dir", file1).delete()); assertTrue("Could note delete retrieved file", new File("local-dir", file2).delete()); } }
From source file:org.springframework.integration.xmpp.inbound.ChatMessageListeningEndpointTests.java
@Test public void testWithErrorChannel() throws NotConnectedException { 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"); });/*from w w w . ja v a 2 s .c o m*/ 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("kermit@frog.com"); smackMessage.setBody("hello"); smackMessage.setThread("1234"); listener.processPacket(smackMessage); ErrorMessage msg = (ErrorMessage) errorChannel.receive(); assertEquals("hello", ((MessagingException) msg.getPayload()).getFailedMessage().getPayload()); }