Ejemplo n.º 1
0
 public void testBasicConsume() throws Exception {
   if (areTestsEnabled()) {
     MockMessageListener listener = new MockMessageListener();
     RelaxedFtpConsumer ftpConsumer = new RelaxedFtpConsumer();
     ConfiguredConsumeDestination ccd = new ConfiguredConsumeDestination(getDestinationString());
     ccd.setConfiguredThreadName("testCasualBasicConsume");
     ftpConsumer.setDestination(ccd);
     ftpConsumer.registerAdaptrisMessageListener(listener);
     ftpConsumer.setOlderThan(DEFAULT_QUIET_PERIOD);
     ftpConsumer.setPoller(new QuartzCronPoller("*/1 * * * * ?"));
     StandaloneConsumer sc = new StandaloneConsumer(createConnection(), ftpConsumer);
     start(sc);
     int count = 1;
     try {
       produce(new StandaloneProducer(createConnection(), createFtpProducer()), count);
       waitForMessages(listener, count);
       assertMessages(listener.getMessages(), count);
     } catch (Exception e) {
       log.error(e.getMessage(), e);
       throw e;
     } finally {
       stop(sc);
     }
   }
 }
Ejemplo n.º 2
0
  public void testConsume_OverrideUrl() throws Exception {
    if (areTestsEnabled()) {

      MockMessageListener listener = new MockMessageListener();
      RelaxedFtpConsumer ftpConsumer = new RelaxedFtpConsumer();
      ConfiguredConsumeDestination ccd =
          new ConfiguredConsumeDestination(getDestinationStringWithOverride());
      ccd.setConfiguredThreadName("testBasicConsumeWithOverride");
      ftpConsumer.setDestination(ccd);
      ftpConsumer.setOlderThan(DEFAULT_QUIET_PERIOD);
      ftpConsumer.registerAdaptrisMessageListener(listener);
      // Pass in a QuartzId so we don't print out the uname+password.
      ftpConsumer.setPoller(new QuartzCronPoller("*/1 * * * * ?", "testBasicConsumeWithOverride"));
      FileTransferConnectionUsingPassword con = createConnection();
      con.setDefaultPassword(null);
      con.setDefaultUserName(null);
      StandaloneConsumer sc = new StandaloneConsumer(con, ftpConsumer);
      start(sc);

      int count = 1;
      try {
        produce(new StandaloneProducer(createConnection(), createFtpProducer()), count);
        waitForMessages(listener, count);

        assertMessages(listener.getMessages(), count);
      } finally {
        stop(sc);
      }
    }
  }
Ejemplo n.º 3
0
  public void testConsume_EncryptedPassword() throws Exception {
    if (areTestsEnabled()) {
      MockMessageListener listener = new MockMessageListener();
      RelaxedFtpConsumer ftpConsumer = new RelaxedFtpConsumer();
      ConfiguredConsumeDestination ccd = new ConfiguredConsumeDestination(getDestinationString());
      ccd.setConfiguredThreadName("testBasicConsumeWithEncryptedPassword");
      ftpConsumer.setDestination(ccd);
      ftpConsumer.setOlderThan(DEFAULT_QUIET_PERIOD);
      ftpConsumer.registerAdaptrisMessageListener(listener);
      ftpConsumer.setPoller(new QuartzCronPoller("*/1 * * * * ?"));
      StandaloneConsumer sc = new StandaloneConsumer(createConnection(), ftpConsumer);
      start(sc);
      int count = 1;
      try {
        FileTransferConnectionUsingPassword conn = createConnection();
        String pw = conn.getDefaultPassword();
        String decodedPw = Password.decode(pw);
        if (pw.equals(decodedPw)) {
          // The password was never encrypted!
          conn.setDefaultPassword(
              Password.encode(conn.getDefaultPassword(), Password.PORTABLE_PASSWORD));
        }
        produce(new StandaloneProducer(conn, createFtpProducer()), count);
        waitForMessages(listener, count);

        assertMessages(listener.getMessages(), count);
      } finally {
        stop(sc);
      }
    }
  }
 private StandaloneConsumer createConsumerExample(
     SftpConnectionBehaviour behavior, Poller poller) {
   SftpConnection con = createConnectionForExamples();
   RelaxedFtpConsumer cfgConsumer = new RelaxedFtpConsumer();
   try {
     con.setSftpConnectionBehaviour(behavior);
     con.setDefaultUserName("UserName if Not configured in destination");
     cfgConsumer.setDestination(
         new ConfiguredConsumeDestination(
             "sftp://[email protected]:port/path/to/directory", "*.xml"));
     cfgConsumer.setPoller(poller);
   } catch (Exception e) {
     throw new RuntimeException(e);
   }
   return new StandaloneConsumer(con, cfgConsumer);
 }
Ejemplo n.º 5
0
  public void testConsumeWithNonMatchingFilter() throws Exception {
    if (areTestsEnabled()) {
      MockMessageListener listener = new MockMessageListener();
      RelaxedFtpConsumer ftpConsumer = new RelaxedFtpConsumer();
      ConfiguredConsumeDestination ccd =
          new ConfiguredConsumeDestination(getDestinationString(), "*.xml");
      ccd.setConfiguredThreadName("testConsumeWithNonMatchingFilter");
      ftpConsumer.setDestination(ccd);
      ftpConsumer.setOlderThan(DEFAULT_QUIET_PERIOD);
      ftpConsumer.setFileFilterImp("org.apache.oro.io.GlobFilenameFilter");
      ftpConsumer.registerAdaptrisMessageListener(listener);
      ftpConsumer.setPoller(new QuartzCronPoller("*/1 * * * * ?"));
      StandaloneConsumer sc = new StandaloneConsumer(createConnection(), ftpConsumer);

      start(sc);

      int count = 1;
      try {
        produce(new StandaloneProducer(createConnection(), createFtpProducer()), count);
        try {
          Thread.sleep(1500);
        } catch (Exception e) {;
        }
        assertMessages(listener.getMessages(), 0);
      } finally {
        stop(sc);
      }
    }
  }
Ejemplo n.º 6
0
  public void testConsumeWithFilter() throws Exception {
    if (areTestsEnabled()) {
      MockMessageListener listener = new MockMessageListener();
      RelaxedFtpConsumer ftpConsumer = new RelaxedFtpConsumer();
      ConfiguredConsumeDestination ccd =
          new ConfiguredConsumeDestination(getDestinationString(), "*.txt");
      ccd.setConfiguredThreadName("testConsumeWithFilter");
      ftpConsumer.setDestination(ccd);
      ftpConsumer.setOlderThan(DEFAULT_QUIET_PERIOD);

      ftpConsumer.setFileFilterImp("org.apache.oro.io.GlobFilenameFilter");
      ftpConsumer.registerAdaptrisMessageListener(listener);
      ftpConsumer.setPoller(new QuartzCronPoller("*/1 * * * * ?"));
      StandaloneConsumer sc = new StandaloneConsumer(createConnection(), ftpConsumer);
      start(sc);

      int count = 1;
      try {
        RelaxedFtpProducer ftpProducer = createFtpProducer();
        MetadataFileNameCreator mfc = new MetadataFileNameCreator();
        mfc.setDefaultName(new GuidGenerator().getUUID() + ".txt");
        mfc.setMetadataKey(new GuidGenerator().getUUID());
        ftpProducer.setFileNameCreator(mfc);
        produce(new StandaloneProducer(createConnection(), ftpProducer), count);
        waitForMessages(listener, count);

        assertMessages(listener.getMessages(), count);
      } finally {
        stop(sc);
      }
    }
  }