Search in sources :

Example 21 with Endpoint

use of org.apache.camel.Endpoint in project camel by apache.

the class FreemarkerComponent method createEndpoint.

protected Endpoint createEndpoint(String uri, String remaining, Map<String, Object> parameters) throws Exception {
    // should we use regular configuration or no cache (content cache is default true)
    Configuration config;
    String encoding = getAndRemoveParameter(parameters, "encoding", String.class);
    boolean cache = getAndRemoveParameter(parameters, "contentCache", Boolean.class, Boolean.TRUE);
    int templateUpdateDelay = getAndRemoveParameter(parameters, "templateUpdateDelay", Integer.class, 0);
    if (cache) {
        config = getConfiguration();
        if (templateUpdateDelay > 0) {
            config.setTemplateUpdateDelay(templateUpdateDelay);
        }
    } else {
        config = getNoCacheConfiguration();
    }
    FreemarkerEndpoint endpoint = new FreemarkerEndpoint(uri, this, remaining);
    if (ObjectHelper.isNotEmpty(encoding)) {
        endpoint.setEncoding(encoding);
    }
    endpoint.setContentCache(cache);
    endpoint.setConfiguration(config);
    endpoint.setTemplateUpdateDelay(templateUpdateDelay);
    // if its a http resource then append any remaining parameters and update the resource uri
    if (ResourceHelper.isHttpUri(remaining)) {
        remaining = ResourceHelper.appendParameters(remaining, parameters);
        endpoint.setResourceUri(remaining);
    }
    return endpoint;
}
Also used : Configuration(freemarker.template.Configuration) Endpoint(org.apache.camel.Endpoint)

Example 22 with Endpoint

use of org.apache.camel.Endpoint in project camel by apache.

the class FromFtpDoNotDeleteFileIfProcessFailsTest 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 this file will NOT be deleted");
    exchange.getIn().setHeader(Exchange.FILE_NAME, "hello.txt");
    Producer producer = endpoint.createProducer();
    producer.start();
    producer.process(exchange);
    producer.stop();
    // assert file is created
    File file = new File(FTP_ROOT_DIR + "/deletefile/hello.txt");
    assertTrue("The file should exists", file.exists());
}
Also used : Exchange(org.apache.camel.Exchange) Endpoint(org.apache.camel.Endpoint) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) Producer(org.apache.camel.Producer) File(java.io.File)

Example 23 with Endpoint

use of org.apache.camel.Endpoint in project camel by apache.

the class FromFileToFtpDefaultRootRenameStrategyTest method prepareFtpServer.

private void prepareFtpServer() throws Exception {
    // create a binary file .. uploaded to the default root location
    Endpoint endpoint = context.getEndpoint(getFtpUrl());
    Exchange exchange = endpoint.createExchange();
    exchange.getIn().setBody(IOConverter.toFile("src/test/data/ftpbinarytest/logo.jpeg"));
    exchange.getIn().setHeader(Exchange.FILE_NAME, "logo.jpeg");
    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 24 with Endpoint

use of org.apache.camel.Endpoint in project camel by apache.

the class FromFtpPollFileOnlyTest 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("ftp://admin@localhost:" + getPort() + "/fileonly/?password=admin&binary=false");
    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) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) Producer(org.apache.camel.Producer)

Example 25 with Endpoint

use of org.apache.camel.Endpoint in project camel by apache.

the class FromFtpPreMoveFileExpressionTest 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 this file will be moved");
    exchange.getIn().setHeader(Exchange.FILE_NAME, "hello.txt");
    Producer producer = endpoint.createProducer();
    producer.start();
    producer.process(exchange);
    producer.stop();
    // assert file is created
    File file = new File(FTP_ROOT_DIR + "/movefile/hello.txt");
    assertTrue("The file should exists", file.exists());
}
Also used : Exchange(org.apache.camel.Exchange) Endpoint(org.apache.camel.Endpoint) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) Producer(org.apache.camel.Producer) File(java.io.File)

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