Package org.springframework.integration.endpoint

Examples of org.springframework.integration.endpoint.SourcePollingChannelAdapter


      @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();
View Full Code Here


    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                                                          "
View Full Code Here

    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                                                          "
View Full Code Here

          mfqms.setDirectories(paths);
          //make sure all the directories are rescanned each poll
          mfqms.setScanEachPoll(false);
          mfqms.afterPropertiesSet();

          SourcePollingChannelAdapter spca = new SourcePollingChannelAdapter();
          spca.setBeanName(platformType + "StatusFileSource");
          spca.setBeanFactory(context.getBeanFactory());
          spca.setMaxMessagesPerPoll(1);

          DynamicTrigger trigger;
          if (props.containsKey(platformType + ".scanRate")) {
            trigger = new DynamicTrigger(Integer.parseInt(props.getProperty(platformType + ".scanRate")), TimeUnit.MILLISECONDS);
          }
          else {
            trigger = new DynamicTrigger(600000, TimeUnit.MILLISECONDS);
          }
          trigger.setFixedRate(false);
          spca.setTrigger(trigger);

          spca.setSource(mfqms);
          spca.setOutputChannel(channelResolver.resolveChannelName(platformType + "StatusFileInputChannel"));
          spca.setAutoStartup(false);
          spca.afterPropertiesSet();

          DirectChannel outputChannel = (DirectChannel) channelResolver.resolveChannelName(platformType + "StatusChannel");
          outputChannel.setBeanName(platformType + "StatusChannel");
          outputChannel.setBeanFactory(context.getBeanFactory());

          if (props.containsKey("wiretap.enabled") && "true".equals(props.get("wiretap.enabled"))) {
            //set up wire tap
            DirectChannel wireTapChannel = (DirectChannel) channelResolver.resolveChannelName("wireTapChannel");
            wireTapChannel.setBeanName("wireTapChannel");
            wireTapChannel.setBeanFactory(context.getBeanFactory());

            LoggingHandler wireTapLogger = new LoggingHandler("TRACE");
            wireTapLogger.setBeanName("OutputWireTapper");
            wireTapLogger.setBeanFactory(context.getBeanFactory());
            wireTapLogger.setLoggerName("wiretap");
            wireTapLogger.setShouldLogFullMessage(true);
            wireTapLogger.afterPropertiesSet();
            wireTapChannel.subscribe(wireTapLogger);

            List<ChannelInterceptor> ints = new ArrayList<ChannelInterceptor>();
            WireTap wt = new WireTap(wireTapChannel);
            ints.add(wt);
            outputChannel.setInterceptors(ints);
          }

          DirectChannel signChannel = (DirectChannel)channelResolver.resolveChannelName(platformType+"MessageSignerChannel");
          signChannel.setBeanFactory(context.getBeanFactory());

          DirectChannel splitterChannel = (DirectChannel)channelResolver.resolveChannelName(platformType+"SplitterChannel");
          splitterChannel.setBeanFactory(context.getBeanFactory());

          if (props.containsKey(platformType + ".http.statusEndpointURIs")) {
            log.debug("Resolving " + platformType + ".http.statusEndpointURIs ...");
            String statusEndpointURIs = props.getProperty(platformType + ".http.statusEndpointURIs");
            for (String uri : statusEndpointURIs.split(",")) {
              //split into multiple messages
              MethodInvokingSplitter mis = new MethodInvokingSplitter(notificationUtils, "splitMessage");
              mis.setBeanName(platformType + "Splitter");
              mis.setBeanFactory(context.getBeanFactory());
              mis.setChannelResolver(channelResolver);
              mis.setOutputChannel(signChannel);
              splitterChannel.subscribe(mis);

              //sign messages and inject url into message headers via HeaderEnricher
              Map<String, SignedHeaderValueMessageProcessor<String>> urlHeaderToSign = new HashMap<String, SignedHeaderValueMessageProcessor<String>>();
              URI su = URI.create(uri);
              urlHeaderToSign.put("x-url", new SignedHeaderValueMessageProcessor<String>(su.getPath()));
              urlHeaderToSign.put("x-user", new SignedHeaderValueMessageProcessor<String>("notification"));
              NotificationMessageEnricher signer = new NotificationMessageEnricher(urlHeaderToSign);
              signer.setMessageProcessor(new MethodInvokingMessageProcessor(notificationUtils, "signMessageHeaders"));

              MessageTransformingHandler mth = new MessageTransformingHandler(signer);
              mth.setBeanName(platformType + "Signer");
              mth.setBeanFactory(context.getBeanFactory());
              mth.setChannelResolver(channelResolver);
              mth.setOutputChannel(outputChannel);
              mth.setRequiresReply(false);
              signChannel.subscribe(mth);

              DefaultHttpHeaderMapper hm = new DefaultHttpHeaderMapper();
              hm.setUserDefinedHeaderPrefix("");
              String[] names = {"Accept", "x-url", "x-signature", "x-user"};
              hm.setBeanFactory(context.getBeanFactory());
              hm.setOutboundHeaderNames(names);
              hm.setInboundHeaderNames(names);

              HttpRequestExecutingMessageHandler statusNotifier = new HttpRequestExecutingMessageHandler(uri);
              statusNotifier.setBeanName(platformType + "StatusNotifier");
              statusNotifier.setBeanFactory(context.getBeanFactory());
              statusNotifier.setChannelResolver(channelResolver);
              statusNotifier.setHttpMethod(HttpMethod.POST);
              statusNotifier.setCharset("UTF-8");
              statusNotifier.setHeaderMapper(hm);
              statusNotifier.setExtractPayload(true);
              statusNotifier.setOrder(3);
              statusNotifier.setRequiresReply(false);
              statusNotifier.setExpectReply(false);

              outputChannel.subscribe(statusNotifier);
            }
          }

          if (props.containsKey(platformType + ".tcp.host") && props.containsKey(platformType + ".tcp.port")) {
            String host = props.getProperty(platformType + ".tcp.host");
            int port = Integer.parseInt(props.getProperty(platformType + ".tcp.port"));

            TcpNetClientConnectionFactory tnccf = new TcpNetClientConnectionFactory(host, port);
            tnccf.setSoTimeout(10000);
            tnccf.setSingleUse(true);

            TcpOutboundGateway tog = new TcpOutboundGateway();
            tog.setBeanName(platformType + "StatusNotifier");
            tog.setBeanFactory(context.getBeanFactory());
            tog.setChannelResolver(channelResolver);
            tog.setConnectionFactory(tnccf);
            tog.setRequestTimeout(10000);
            tog.setRequiresReply(false);
            tog.setOutputChannel(outputChannel);

            outputChannel.subscribe(tog);
          }

          if ((!props.containsKey(platformType + ".tcp.host") || !props.containsKey(platformType + ".tcp.port")) && !props.containsKey(platformType + ".http.statusEndpointURIs")) {
            log.error("You have specified a list of paths to scan, but no valid endpoint to notify. Please add a <platform>.http.statusEndpointURIs property and/or <platform>.tcp.host/port properties in notification.properties");
          }
          else {
            spca.start();
          }
        }
        else {
          log.warn("You have not specified a list of " + platformType + " paths to scan. Please add a " + platformType.toLowerCase() + ".dataPaths property in notification.properties if you wish to track this platform");
        }
View Full Code Here

  ApplicationContext applicationContext;

  @Test(timeout = 100000)
  public void testSmbInboundChannelAdapterComplete() throws Exception{

    final SourcePollingChannelAdapter adapter = this.applicationContext.getBean("smbInbound", SourcePollingChannelAdapter.class);
    final PriorityBlockingQueue<?> queue = TestUtils.getPropertyValue(adapter, "source.fileSource.toBeReceived", PriorityBlockingQueue.class);

    assertNotNull(queue.comparator());
    assertEquals("smbInbound", adapter.getComponentName());
    assertEquals("smb:inbound-channel-adapter", adapter.getComponentType());
    assertNotNull(TestUtils.getPropertyValue(adapter, "poller"));
    assertEquals(applicationContext.getBean("smbChannel"), TestUtils.getPropertyValue(adapter, "outputChannel"));
    SmbInboundFileSynchronizingMessageSource inbound =
      (SmbInboundFileSynchronizingMessageSource) TestUtils.getPropertyValue(adapter, "source");
View Full Code Here

    assertTrue(SmbSessionFactory.class.isAssignableFrom(sessionFactory.getClass()));
  }

  @Test(timeout = 10000)
  public void cachingSessionFactoryByDefault() throws Exception{
    SourcePollingChannelAdapter adapter = applicationContext.getBean("simpleAdapter", SourcePollingChannelAdapter.class);
    Object sessionFactory = TestUtils.getPropertyValue(adapter, "source.synchronizer.sessionFactory");
    assertEquals(CachingSessionFactory.class, sessionFactory.getClass());
    SmbInboundFileSynchronizer fisync =
      TestUtils.getPropertyValue(adapter, "source.synchronizer", SmbInboundFileSynchronizer.class);
    String remoteFileSeparator = (String) TestUtils.getPropertyValue(fisync, "remoteFileSeparator");
View Full Code Here

  @Test(timeout = 10000)
  public void testSmbInboundChannelAdapterCompleteNoId() throws Exception{

    Map<String, SourcePollingChannelAdapter> spcas = applicationContext.getBeansOfType(SourcePollingChannelAdapter.class);
    SourcePollingChannelAdapter adapter = null;
    for (String key : spcas.keySet()) {
      if (!key.equals("smbInbound") && !key.equals("simpleAdapter")){
        adapter = spcas.get(key);
      }
    }
View Full Code Here

*
*/
public class SmbMessageHistoryTests extends AbstractBaseTest {
  @Test
  public void testMessageHistory() throws Exception {
    SourcePollingChannelAdapter adapter = getApplicationContext().getBean("smbInboundChannelAdapter", SourcePollingChannelAdapter.class);
    assertEquals("smbInboundChannelAdapter", adapter.getComponentName());
    assertEquals("smb:inbound-channel-adapter", adapter.getComponentType());
  }
View Full Code Here

TOP

Related Classes of org.springframework.integration.endpoint.SourcePollingChannelAdapter

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.