use of org.apache.camel.Endpoint in project camel by apache.
the class FromQueueThenConsumeFtpToMockTest method createRouteBuilder.
protected RouteBuilder createRouteBuilder() throws Exception {
return new RouteBuilder() {
public void configure() throws Exception {
// START SNIPPET: e2
from("seda:start").process(new Processor() {
public void process(final Exchange exchange) throws Exception {
// get the filename from our custome header we want to get from a remote server
String filename = exchange.getIn().getHeader("myfile", String.class);
// construct the total url for the ftp consumer
// add the fileName option with the file we want to consume
String url = getFtpUrl() + "&fileName=" + filename;
// create a ftp endpoint
Endpoint ftp = context.getEndpoint(url);
// create a polling consumer where we can poll the myfile from the ftp server
PollingConsumer consumer = ftp.createPollingConsumer();
// must start the consumer before we can receive
consumer.start();
// poll the file from the ftp server
Exchange result = consumer.receive();
// the result is the response from the FTP consumer (the downloaded file)
// replace the outher exchange with the content from the downloaded file
exchange.getIn().setBody(result.getIn().getBody());
// stop the consumer
consumer.stop();
}
}).to("mock:result");
// END SNIPPET: e2
}
};
}
use of org.apache.camel.Endpoint in project camel by apache.
the class FtpEndpointURISanitizedTest method testFtpConsumerUriSanitized.
@Test
public void testFtpConsumerUriSanitized() throws Exception {
Endpoint endpoint = context.getEndpoint(getFtpUrl());
Consumer consumer = endpoint.createConsumer(null);
assertFalse(consumer.toString().contains(password));
}
use of org.apache.camel.Endpoint in project camel by apache.
the class FtpConsumerLocalWorkDirectoryTest method prepareFtpServer.
private void prepareFtpServer() throws Exception {
// prepares the FTP Server by creating a file on the server that we want
// to unit
// test that we can pool
Endpoint endpoint = context.getEndpoint(getFtpUrl());
Exchange exchange = endpoint.createExchange();
exchange.getIn().setBody("Hello World");
exchange.getIn().setHeader(Exchange.FILE_NAME, "hello.txt");
Producer producer = endpoint.createProducer();
producer.start();
producer.process(exchange);
producer.stop();
}
use of org.apache.camel.Endpoint in project camel by apache.
the class FtpLoginTest method uploadFile.
private void uploadFile(String username, String password) throws Exception {
Endpoint endpoint = context.getEndpoint("ftp://" + username + "@localhost:" + getPort() + "/login?password=" + password);
Exchange exchange = endpoint.createExchange();
exchange.getIn().setBody("Hello World from FTPServer");
exchange.getIn().setHeader(Exchange.FILE_NAME, "report.txt");
Producer producer = endpoint.createProducer();
producer.start();
producer.process(exchange);
producer.stop();
}
use of org.apache.camel.Endpoint in project camel by apache.
the class FromFtpStartingDirAndFileNameClashTest method prepareFtpServer.
private void prepareFtpServer() throws Exception {
// prepares the FTP Server by creating a file on the server that we want to unit
// test that we can pool and store as a local file
Endpoint endpoint = context.getEndpoint(getFtpUrl());
Exchange exchange = endpoint.createExchange();
exchange.getIn().setBody("Hello World");
exchange.getIn().setHeader(Exchange.FILE_NAME, "hello-world.txt");
Producer producer = endpoint.createProducer();
producer.start();
producer.process(exchange);
producer.stop();
}
Aggregations