Search in sources :

Example 26 with GenericFile

use of org.apache.camel.component.file.GenericFile in project camel by apache.

the class FtpSimpleConsumeStreamingTest method testFtpSimpleConsumeAbsolute.

@Test
public void testFtpSimpleConsumeAbsolute() throws Exception {
    if (!canTest()) {
        return;
    }
    String expected = "Hello World";
    // create file using regular file
    // FTP Server does not support absolute path, so lets simulate it
    String path = FTP_ROOT_DIR + "/tmp/mytemp";
    template.sendBodyAndHeader("file:" + path, expected, Exchange.FILE_NAME, "hello.txt");
    MockEndpoint mock = getMockEndpoint("mock:result");
    mock.expectedMessageCount(1);
    mock.expectedHeaderReceived(Exchange.FILE_NAME, "hello.txt");
    context.startRoute("foo");
    assertMockEndpointsSatisfied();
    GenericFile<?> remoteFile = (GenericFile<?>) mock.getExchanges().get(0).getIn().getBody();
    assertTrue(remoteFile.getBody() instanceof InputStream);
}
Also used : MockEndpoint(org.apache.camel.component.mock.MockEndpoint) InputStream(java.io.InputStream) GenericFile(org.apache.camel.component.file.GenericFile) Test(org.junit.Test)

Example 27 with GenericFile

use of org.apache.camel.component.file.GenericFile in project camel by apache.

the class JcloudsPayloadConverter method convertTo.

@FallbackConverter
@SuppressWarnings("unchecked")
public static <T extends Payload> T convertTo(Class<T> type, Exchange exchange, Object value, TypeConverterRegistry registry) throws IOException {
    Class<?> sourceType = value.getClass();
    if (GenericFile.class.isAssignableFrom(sourceType)) {
        GenericFile<?> genericFile = (GenericFile<?>) value;
        if (genericFile.getFile() != null) {
            Class<?> genericFileType = genericFile.getFile().getClass();
            TypeConverter converter = registry.lookup(Payload.class, genericFileType);
            if (converter != null) {
                return (T) converter.convertTo(Payload.class, genericFile.getFile());
            }
        }
    }
    return null;
}
Also used : TypeConverter(org.apache.camel.TypeConverter) InputStreamPayload(org.jclouds.io.payloads.InputStreamPayload) ByteSourcePayload(org.jclouds.io.payloads.ByteSourcePayload) Payload(org.jclouds.io.Payload) GenericFile(org.apache.camel.component.file.GenericFile) FallbackConverter(org.apache.camel.FallbackConverter)

Example 28 with GenericFile

use of org.apache.camel.component.file.GenericFile in project camel by apache.

the class GenericFileDeleteProcessStrategyTest method testTroubleDeletingFile.

public void testTroubleDeletingFile() throws Exception {
    deleteCounter = 0;
    existsCounter = 0;
    @SuppressWarnings("unchecked") GenericFileEndpoint<Object> endpoint = context.getEndpoint("file://target/foo", GenericFileEndpoint.class);
    Exchange exchange = endpoint.createExchange();
    GenericFile<Object> file = new GenericFile<Object>();
    file.setAbsoluteFilePath("target/foo/me.txt");
    GenericFileDeleteProcessStrategy<Object> strategy = new GenericFileDeleteProcessStrategy<Object>();
    strategy.commit(new MyGenericFileOperations(), endpoint, exchange, file);
    assertEquals("Should have tried to delete file 2 times", 2, deleteCounter);
    assertEquals("Should have tried to delete file 2 times", 2, existsCounter);
}
Also used : Exchange(org.apache.camel.Exchange) GenericFile(org.apache.camel.component.file.GenericFile)

Example 29 with GenericFile

use of org.apache.camel.component.file.GenericFile in project camel by apache.

the class FileLanguageExtSingleTest method createExchange.

public Exchange createExchange() {
    // create the file
    String uri = "file://target/filelanguage?fileExist=Override";
    template.sendBodyAndHeader(uri, "Bye World", Exchange.FILE_NAME, "test/bye.def.txt");
    // get the file handle
    file = new File("target/filelanguage/test/bye.def.txt");
    GenericFile<File> gf = FileConsumer.asGenericFile("target/filelanguage", file, null, false);
    FileEndpoint endpoint = getMandatoryEndpoint(uri, FileEndpoint.class);
    Exchange answer = endpoint.createExchange(gf);
    endpoint.configureMessage(gf, answer.getIn());
    Calendar cal = Calendar.getInstance();
    cal.set(1974, Calendar.APRIL, 20);
    answer.getIn().setHeader("birthday", cal.getTime());
    cal.set(2008, Calendar.AUGUST, 8);
    answer.getOut().setHeader("special", cal.getTime());
    return answer;
}
Also used : Exchange(org.apache.camel.Exchange) Calendar(java.util.Calendar) FileEndpoint(org.apache.camel.component.file.FileEndpoint) GenericFile(org.apache.camel.component.file.GenericFile) File(java.io.File)

Example 30 with GenericFile

use of org.apache.camel.component.file.GenericFile in project camel by apache.

the class FileLanguageTest method createExchange.

public Exchange createExchange() {
    // create the file
    String uri = "file://target/filelanguage?fileExist=Override";
    template.sendBodyAndHeader(uri, "Hello World", Exchange.FILE_NAME, "test/hello.txt");
    // get the file handle
    file = new File("target/filelanguage/test/hello.txt");
    GenericFile<File> gf = FileConsumer.asGenericFile("target/filelanguage", file, null, false);
    FileEndpoint endpoint = getMandatoryEndpoint(uri, FileEndpoint.class);
    Exchange answer = endpoint.createExchange(gf);
    endpoint.configureMessage(gf, answer.getIn());
    Calendar cal = Calendar.getInstance();
    cal.set(1974, Calendar.APRIL, 20);
    answer.getIn().setHeader("birthday", cal.getTime());
    cal.set(2008, Calendar.AUGUST, 8);
    answer.getOut().setHeader("special", cal.getTime());
    return answer;
}
Also used : Exchange(org.apache.camel.Exchange) Calendar(java.util.Calendar) FileEndpoint(org.apache.camel.component.file.FileEndpoint) GenericFile(org.apache.camel.component.file.GenericFile) File(java.io.File)

Aggregations

GenericFile (org.apache.camel.component.file.GenericFile)34 File (java.io.File)25 IOException (java.io.IOException)11 InputStream (java.io.InputStream)11 Exchange (org.apache.camel.Exchange)8 ByteArrayOutputStream (java.io.ByteArrayOutputStream)7 GenericFileOperationFailedException (org.apache.camel.component.file.GenericFileOperationFailedException)7 UnsupportedEncodingException (java.io.UnsupportedEncodingException)4 CamelExchangeException (org.apache.camel.CamelExchangeException)4 Message (org.apache.camel.Message)4 ByteArrayInputStream (java.io.ByteArrayInputStream)3 FileOutputStream (java.io.FileOutputStream)3 OutputStream (java.io.OutputStream)3 Serializable (java.io.Serializable)3 FallbackConverter (org.apache.camel.FallbackConverter)3 TypeConverter (org.apache.camel.TypeConverter)3 WrappedFile (org.apache.camel.WrappedFile)3 FileEndpoint (org.apache.camel.component.file.FileEndpoint)3 MockEndpoint (org.apache.camel.component.mock.MockEndpoint)3 Test (org.junit.Test)3