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);
}
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;
}
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);
}
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;
}
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;
}
Aggregations