Search in sources :

Example 76 with CoreException

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

the class FsConsumerCase method testInitWithoutMkdirs.

@Test
public void testInitWithoutMkdirs() throws Exception {
    String subdir = new GuidGenerator().safeUUID();
    FsConsumerImpl fs = createConsumer(subdir);
    fs.setCreateDirs(false);
    try {
        LifecycleHelper.init(fs);
        fail("Should fail since dir can't exist");
    } catch (CoreException e) {
        // Expected
        ;
    } finally {
        LifecycleHelper.close(fs);
        FileUtils.deleteQuietly(new File(PROPERTIES.getProperty(BASE_KEY), subdir));
    }
}
Also used : CoreException(com.adaptris.core.CoreException) GuidGenerator(com.adaptris.util.GuidGenerator) File(java.io.File) Test(org.junit.Test)

Example 77 with CoreException

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

the class FsConsumerCase method testBasicInit.

@Test
public void testBasicInit() throws Exception {
    String subDir = new GuidGenerator().safeUUID();
    FsConsumerImpl consumer = createConsumer(subDir);
    try {
        FsConsumerImpl consumer2 = createConsumer();
        try {
            LifecycleHelper.init(consumer2);
            fail("no destination  - should throw Exception");
        } catch (CoreException e) {
        // expected
        }
        // test creation of file filter imp...
        consumer.setFilterExpression(".*\\.xml");
        consumer.setFileFilterImp(Perl5FilenameFilter.class.getName());
        try {
            LifecycleHelper.init(consumer);
        } catch (CoreException e) {
            fail("Exception calling init with valid FileFilter " + e);
        }
        LifecycleHelper.close(consumer);
        // test creation of invalid FF Imp
        consumer.setFileFilterImp("com.class.does.not.exist.FileFilter");
        try {
            LifecycleHelper.init(consumer);
            fail("Calling init with invalid FileFilter ");
        } catch (CoreException e) {
        }
    } finally {
        FileUtils.deleteQuietly(new File(PROPERTIES.getProperty(BASE_KEY), subDir));
    }
}
Also used : Perl5FilenameFilter(org.apache.oro.io.Perl5FilenameFilter) CoreException(com.adaptris.core.CoreException) GuidGenerator(com.adaptris.util.GuidGenerator) File(java.io.File) Test(org.junit.Test)

Example 78 with CoreException

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

the class ConfigPreProcessorsTest method testProcessURL.

@Test
public void testProcessURL() throws Exception {
    ConfigPreProcessors p = new ConfigPreProcessors(new DummyConfigurationPreProcessor(new KeyValuePairSet()), new DummyConfigurationPreProcessor(new KeyValuePairSet()));
    URL onClasspath = this.getClass().getClassLoader().getResource("xstream-standalone.xml");
    assertNotNull(p.process(onClasspath));
    try {
        p.process(new URL("file:///./does/not/exist"));
        fail();
    } catch (CoreException expected) {
    }
}
Also used : CoreException(com.adaptris.core.CoreException) KeyValuePairSet(com.adaptris.util.KeyValuePairSet) URL(java.net.URL) Test(org.junit.Test)

Example 79 with CoreException

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

the class MarshallingItemCache method writePersistentStore.

private void writePersistentStore() {
    try {
        File store = new File(getPersistentStore());
        File parent = store.getParentFile();
        if (parent != null) {
            parent.mkdirs();
        }
        marshaller.marshal(convertToList(cache), store);
        logR.trace("Persisted " + cache.size() + " entries to disk");
    } catch (CoreException e) {
        logR.warn("Failed to store cache, cache will be empty upon restart");
    }
}
Also used : CoreException(com.adaptris.core.CoreException) File(java.io.File)

Example 80 with CoreException

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

the class NonDeletingFsConsumer method processFile.

@Override
protected int processFile(File fileToProcess) throws CoreException {
    int result = 0;
    try {
        if (checkModified(fileToProcess) && isFileAccessible(fileToProcess)) {
            ProcessedItem item = new ProcessedItem(fileToProcess.getCanonicalPath(), fileToProcess.lastModified(), fileToProcess.length());
            try {
                filesDetected.addProcessedItem(item);
                if (hasChanged(item)) {
                    AdaptrisMessage msg = createAdaptrisMessage(fileToProcess);
                    addStandardMetadata(msg, fileToProcess, fileToProcess);
                    retrieveAdaptrisMessageListener().onAdaptrisMessage(msg);
                    result++;
                } else {
                    log.trace("[{}] hasn't changed since last poll", item.getAbsolutePath());
                }
            } catch (Exception e) {
                filesDetected.removeProcessedItem(item);
                throw e;
            }
        }
    } catch (Exception e) {
        throw new CoreException(e);
    }
    return result;
}
Also used : CoreException(com.adaptris.core.CoreException) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) CoreException(com.adaptris.core.CoreException)

Aggregations

CoreException (com.adaptris.core.CoreException)186 Test (org.junit.Test)110 AdaptrisMessage (com.adaptris.core.AdaptrisMessage)44 Adapter (com.adaptris.core.Adapter)32 ObjectName (javax.management.ObjectName)29 Channel (com.adaptris.core.Channel)27 ArrayList (java.util.ArrayList)24 IOException (java.io.IOException)20 File (java.io.File)19 ServiceException (com.adaptris.core.ServiceException)14 TimeInterval (com.adaptris.util.TimeInterval)13 Document (org.w3c.dom.Document)12 MalformedObjectNameException (javax.management.MalformedObjectNameException)11 AdaptrisMarshaller (com.adaptris.core.AdaptrisMarshaller)10 StandardWorkflow (com.adaptris.core.StandardWorkflow)9 URLString (com.adaptris.util.URLString)9 TimeoutException (java.util.concurrent.TimeoutException)9 PoolingWorkflow (com.adaptris.core.PoolingWorkflow)8 Workflow (com.adaptris.core.Workflow)8 XPath (com.adaptris.util.text.xml.XPath)8