Search in sources :

Example 41 with Endpoint

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

the class FtpConsumerBodyAsStringTest 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 42 with Endpoint

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

the class FromFtpToBinaryFilesTest 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
    String ftpUrl = "ftp://admin@localhost:" + getPort() + "/incoming?password=admin&binary=true" + "&consumer.delay=2000&recursive=false";
    Endpoint endpoint = context.getEndpoint(ftpUrl);
    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();
    ftpUrl = "ftp://admin@localhost:" + getPort() + "/incoming/a?password=admin&binary=true" + "&consumer.delay=2000&recursive=false";
    endpoint = context.getEndpoint(ftpUrl);
    exchange = endpoint.createExchange();
    exchange.getIn().setBody(IOConverter.toFile("src/test/data/ftpbinarytest/logo1.jpeg"));
    exchange.getIn().setHeader(Exchange.FILE_NAME, "logo1.jpeg");
    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 43 with Endpoint

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

the class FromFtpToFileNoFileNameHeaderTest 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 from FTPServer");
    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 44 with Endpoint

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

the class DefaultFluentProducerTemplate method request.

@Override
@SuppressWarnings("unchecked")
public <T> T request(Class<T> type) throws CamelExecutionException {
    // Determine the target endpoint
    final Endpoint target = target();
    // Create the default processor if not provided.
    final Supplier<Processor> processorSupplier = this.processorSupplier.orElse(() -> defaultProcessor());
    T result;
    if (type == Exchange.class) {
        result = (T) template().request(target, processorSupplier.get());
    } else if (type == Message.class) {
        Exchange exchange = template().request(target, processorSupplier.get());
        result = exchange.hasOut() ? (T) exchange.getOut() : (T) exchange.getIn();
    } else {
        Exchange exchange = template().send(target, ExchangePattern.InOut, processorSupplier.get(), resultProcessors.get(type));
        result = context.getTypeConverter().convertTo(type, ExchangeHelper.extractResultBody(exchange, exchange.getPattern()));
    }
    return result;
}
Also used : Exchange(org.apache.camel.Exchange) ConvertBodyProcessor(org.apache.camel.processor.ConvertBodyProcessor) Processor(org.apache.camel.Processor) Endpoint(org.apache.camel.Endpoint) Message(org.apache.camel.Message)

Example 45 with Endpoint

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

the class BuilderSupport method endpoint.

/**
     * Resolves the given URI to an endpoint
     *
     * @param uri  the uri to resolve
     * @throws NoSuchEndpointException if the endpoint URI could not be resolved
     * @return the endpoint
     */
public Endpoint endpoint(String uri) throws NoSuchEndpointException {
    ObjectHelper.notNull(uri, "uri");
    Endpoint endpoint = getContext().getEndpoint(uri);
    if (endpoint == null) {
        throw new NoSuchEndpointException(uri);
    }
    return endpoint;
}
Also used : Endpoint(org.apache.camel.Endpoint) NoSuchEndpointException(org.apache.camel.NoSuchEndpointException)

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