Search in sources :

Example 16 with MimeEncoder

use of com.adaptris.core.MimeEncoder in project interlok by adaptris.

the class TranscodingServiceCase method createMimeMessage.

protected AdaptrisMessage createMimeMessage() throws Exception {
    AdaptrisMessage tempMessage = createSimpleMessage();
    MimeEncoder mimeEncoder = new MimeEncoder();
    byte[] payload = mimeEncoder.encode(tempMessage);
    return AdaptrisMessageFactory.getDefaultInstance().newMessage(payload);
}
Also used : AdaptrisMessage(com.adaptris.core.AdaptrisMessage) MimeEncoder(com.adaptris.core.MimeEncoder)

Example 17 with MimeEncoder

use of com.adaptris.core.MimeEncoder in project interlok by adaptris.

the class LargeFsConsumerTest method testConsume_WithUnsupportedEncoder.

@Test
public void testConsume_WithUnsupportedEncoder() throws Exception {
    String subDir = GUID.safeUUID();
    MockMessageListener stub = new MockMessageListener(10);
    FsConsumer fs = createConsumer(subDir);
    fs.setResetWipFiles(false);
    fs.setPoller(new FixedIntervalPoller(new TimeInterval(300L, TimeUnit.MILLISECONDS)));
    fs.setEncoder(new MimeEncoder());
    StandaloneConsumer sc = new StandaloneConsumer(fs);
    sc.registerAdaptrisMessageListener(stub);
    int count = 10;
    File parentDir = FsHelper.createFileReference(FsHelper.createUrlFromString(PROPERTIES.getProperty(BASE_KEY), true));
    try {
        File baseDir = new File(parentDir, subDir);
        baseDir.mkdirs();
        createMimeFiles(baseDir, ".xml", count);
        start(sc);
        waitForMessages(stub, count);
        assertEquals(count, stub.getMessages().size());
        assertIgnoreSize(stub.getMessages(), count, baseDir.listFiles((FilenameFilter) new Perl5FilenameFilter(".*\\.xml")));
    } finally {
        stop(sc);
    // FileUtils.deleteQuietly(new File(parentDir, subDir));
    }
}
Also used : FilenameFilter(java.io.FilenameFilter) Perl5FilenameFilter(org.apache.oro.io.Perl5FilenameFilter) Perl5FilenameFilter(org.apache.oro.io.Perl5FilenameFilter) TimeInterval(com.adaptris.util.TimeInterval) MimeEncoder(com.adaptris.core.MimeEncoder) FsConsumer(com.adaptris.core.fs.FsConsumer) MockMessageListener(com.adaptris.core.stubs.MockMessageListener) FixedIntervalPoller(com.adaptris.core.FixedIntervalPoller) StandaloneConsumer(com.adaptris.core.StandaloneConsumer) File(java.io.File) FsMessageConsumerTest(com.adaptris.core.fs.FsMessageConsumerTest) Test(org.junit.Test)

Example 18 with MimeEncoder

use of com.adaptris.core.MimeEncoder in project interlok by adaptris.

the class FtpConsumerTest method testConsumeWithEncoder.

@Test
public void testConsumeWithEncoder() throws Exception {
    int count = 1;
    EmbeddedFtpServer helper = new EmbeddedFtpServer();
    MockMessageListener listener = new MockMessageListener(100);
    AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage(PAYLOAD);
    byte[] bytes = new MimeEncoder().encode(msg);
    FileSystem filesystem = helper.createFilesystem_DirsOnly();
    for (int i = 0; i < count; i++) {
        FileEntry entry = new FileEntry(DEFAULT_WORK_DIR_CANONICAL + SLASH + DEFAULT_FILENAME + i + ".txt");
        entry.setContents(bytes);
        filesystem.add(entry);
    }
    FakeFtpServer server = helper.createAndStart(filesystem);
    StandaloneConsumer sc = null;
    try {
        FtpConsumer ftpConsumer = createForTests(listener);
        ftpConsumer.setEncoder(new MimeEncoder());
        FtpConnection consumeConnection = create(server);
        sc = new StandaloneConsumer(consumeConnection, ftpConsumer);
        start(sc);
        waitForMessages(listener, count);
        helper.assertMessages(listener.getMessages(), count);
    } catch (Exception e) {
        throw e;
    } finally {
        stop(sc);
        server.stop();
    }
}
Also used : FakeFtpServer(org.mockftpserver.fake.FakeFtpServer) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) MimeEncoder(com.adaptris.core.MimeEncoder) MockMessageListener(com.adaptris.core.stubs.MockMessageListener) FileSystem(org.mockftpserver.fake.filesystem.FileSystem) FileEntry(org.mockftpserver.fake.filesystem.FileEntry) StandaloneConsumer(com.adaptris.core.StandaloneConsumer) Test(org.junit.Test)

Example 19 with MimeEncoder

use of com.adaptris.core.MimeEncoder in project interlok by adaptris.

the class DefaultFailedMessageRetrierJmxTest method testMBean_Retry_File.

@Test
public void testMBean_Retry_File() throws Exception {
    Adapter adapter = createAdapter(getName());
    Channel c = createChannel(getName());
    StandardWorkflow wf = createWorkflow(getName());
    MockMessageProducer mock = new MockMessageProducer();
    wf.setProducer(mock);
    c.getWorkflowList().add(wf);
    adapter.getChannelList().add(c);
    DefaultFailedMessageRetrier retrier = new DefaultFailedMessageRetrier();
    adapter.setFailedMessageRetrier(retrier);
    AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage();
    msg.addMetadata(Workflow.WORKFLOW_ID_KEY, getName() + "@" + getName());
    File fileToRetry = writeFile(msg, new MimeEncoder());
    AdapterManager adapterManager = new AdapterManager(adapter);
    try {
        adapterManager.registerMBean();
        adapterManager.requestStart();
        ObjectName retrierObjName = createRetrierObjectName(adapterManager);
        DefaultFailedMessageRetrierJmxMBean jmxBean = JMX.newMBeanProxy(mBeanServer, retrierObjName, DefaultFailedMessageRetrierJmxMBean.class);
        assertTrue(jmxBean.retryMessage(fileToRetry));
        waitForMessages(mock, 1);
        assertEquals(1, mock.messageCount());
    } finally {
        adapterManager.requestClose();
        adapterManager.unregisterMBean();
    }
}
Also used : DefaultFailedMessageRetrierJmxMBean(com.adaptris.core.DefaultFailedMessageRetrierJmxMBean) StandardWorkflow(com.adaptris.core.StandardWorkflow) MockMessageProducer(com.adaptris.core.stubs.MockMessageProducer) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) MimeEncoder(com.adaptris.core.MimeEncoder) Channel(com.adaptris.core.Channel) Adapter(com.adaptris.core.Adapter) DefaultFailedMessageRetrier(com.adaptris.core.DefaultFailedMessageRetrier) File(java.io.File) ObjectName(javax.management.ObjectName) Test(org.junit.Test)

Example 20 with MimeEncoder

use of com.adaptris.core.MimeEncoder in project interlok by adaptris.

the class RelaxedFtpCase method testConsume_WithEncoder.

@Test
public void testConsume_WithEncoder() throws Exception {
    if (areTestsEnabled()) {
        MockMessageListener listener = new MockMessageListener();
        RelaxedFtpConsumer ftpConsumer = new RelaxedFtpConsumer();
        ftpConsumer.setFtpEndpoint(getDestinationString());
        ftpConsumer.registerAdaptrisMessageListener(listener);
        ftpConsumer.setQuietInterval(DEFAULT_QUIET_PERIOD);
        ftpConsumer.setPoller(new QuartzCronPoller("*/1 * * * * ?"));
        ftpConsumer.setEncoder(new MimeEncoder());
        FileTransferConnection consumeConnection = createConnection();
        consumeConnection.setCacheConnection(true);
        StandaloneConsumer sc = new StandaloneConsumer(consumeConnection, ftpConsumer);
        start(sc);
        int count = 1;
        try {
            FileTransferConnection produceConnection = createConnection();
            produceConnection.setCacheConnection(true);
            RelaxedFtpProducer producer = createFtpProducer();
            producer.setEncoder(new MimeEncoder());
            produce(new StandaloneProducer(produceConnection, producer), count);
            waitForMessages(listener, count);
            assertMessages(listener.getMessages(), count);
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            throw e;
        } finally {
            stop(sc);
        }
    }
}
Also used : QuartzCronPoller(com.adaptris.core.QuartzCronPoller) MimeEncoder(com.adaptris.core.MimeEncoder) MockMessageListener(com.adaptris.core.stubs.MockMessageListener) StandaloneConsumer(com.adaptris.core.StandaloneConsumer) StandaloneProducer(com.adaptris.core.StandaloneProducer) CoreException(com.adaptris.core.CoreException) Test(org.junit.Test)

Aggregations

MimeEncoder (com.adaptris.core.MimeEncoder)21 Test (org.junit.Test)18 AdaptrisMessage (com.adaptris.core.AdaptrisMessage)13 StandaloneConsumer (com.adaptris.core.StandaloneConsumer)7 MockMessageListener (com.adaptris.core.stubs.MockMessageListener)7 StandaloneProducer (com.adaptris.core.StandaloneProducer)6 File (java.io.File)5 FakeFtpServer (org.mockftpserver.fake.FakeFtpServer)4 FileSystem (org.mockftpserver.fake.filesystem.FileSystem)4 Adapter (com.adaptris.core.Adapter)3 Channel (com.adaptris.core.Channel)3 DefaultFailedMessageRetrier (com.adaptris.core.DefaultFailedMessageRetrier)3 DefaultFailedMessageRetrierJmxMBean (com.adaptris.core.DefaultFailedMessageRetrierJmxMBean)3 StandardWorkflow (com.adaptris.core.StandardWorkflow)3 MockMessageProducer (com.adaptris.core.stubs.MockMessageProducer)3 ObjectName (javax.management.ObjectName)3 CoreException (com.adaptris.core.CoreException)2 QuartzCronPoller (com.adaptris.core.QuartzCronPoller)2 TimeInterval (com.adaptris.util.TimeInterval)2 FileEntry (org.mockftpserver.fake.filesystem.FileEntry)2