Search in sources :

Example 36 with Endpoint

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
        }
    };
}
Also used : Exchange(org.apache.camel.Exchange) PollingConsumer(org.apache.camel.PollingConsumer) Processor(org.apache.camel.Processor) RouteBuilder(org.apache.camel.builder.RouteBuilder) Endpoint(org.apache.camel.Endpoint) MockEndpoint(org.apache.camel.component.mock.MockEndpoint)

Example 37 with Endpoint

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));
}
Also used : Endpoint(org.apache.camel.Endpoint) Consumer(org.apache.camel.Consumer) Test(org.junit.Test)

Example 38 with Endpoint

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();
}
Also used : Exchange(org.apache.camel.Exchange) Endpoint(org.apache.camel.Endpoint) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) Producer(org.apache.camel.Producer)

Example 39 with Endpoint

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();
}
Also used : Exchange(org.apache.camel.Exchange) Endpoint(org.apache.camel.Endpoint) Producer(org.apache.camel.Producer)

Example 40 with Endpoint

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();
}
Also used : Exchange(org.apache.camel.Exchange) Endpoint(org.apache.camel.Endpoint) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) Producer(org.apache.camel.Producer)

Aggregations

Endpoint (org.apache.camel.Endpoint)564 Test (org.junit.Test)206 Exchange (org.apache.camel.Exchange)201 Producer (org.apache.camel.Producer)137 MockEndpoint (org.apache.camel.component.mock.MockEndpoint)89 Processor (org.apache.camel.Processor)43 Message (org.apache.camel.Message)38 CamelContext (org.apache.camel.CamelContext)32 HashMap (java.util.HashMap)28 Map (java.util.Map)28 Consumer (org.apache.camel.Consumer)27 RouteBuilder (org.apache.camel.builder.RouteBuilder)24 File (java.io.File)21 Route (org.apache.camel.Route)21 EventDrivenConsumerRoute (org.apache.camel.impl.EventDrivenConsumerRoute)18 CountDownLatch (java.util.concurrent.CountDownLatch)16 DefaultExchange (org.apache.camel.impl.DefaultExchange)16 SpanDecorator (org.apache.camel.opentracing.SpanDecorator)15 ArrayList (java.util.ArrayList)14 DefaultCamelContext (org.apache.camel.impl.DefaultCamelContext)14