Search in sources :

Example 6 with Consumer

use of org.apache.camel.Consumer 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 7 with Consumer

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

the class RestApiEndpoint method createConsumer.

@Override
public Consumer createConsumer(Processor processor) throws Exception {
    RestApiConsumerFactory factory = null;
    String cname = null;
    // the API then uses the api component (eg usually camel-swagger-java) to build the API
    if (getComponentName() != null) {
        Object comp = getCamelContext().getRegistry().lookupByName(getComponentName());
        if (comp != null && comp instanceof RestApiConsumerFactory) {
            factory = (RestApiConsumerFactory) comp;
        } else {
            comp = getCamelContext().getComponent(getComponentName());
            if (comp != null && comp instanceof RestApiConsumerFactory) {
                factory = (RestApiConsumerFactory) comp;
            }
        }
        if (factory == null) {
            if (comp != null) {
                throw new IllegalArgumentException("Component " + getComponentName() + " is not a RestApiConsumerFactory");
            } else {
                throw new NoSuchBeanException(getComponentName(), RestApiConsumerFactory.class.getName());
            }
        }
        cname = getComponentName();
    }
    // try all components
    if (factory == null) {
        for (String name : getCamelContext().getComponentNames()) {
            Component comp = getCamelContext().getComponent(name);
            if (comp != null && comp instanceof RestApiConsumerFactory) {
                factory = (RestApiConsumerFactory) comp;
                cname = name;
                break;
            }
        }
    }
    // lookup in registry
    if (factory == null) {
        Set<RestApiConsumerFactory> factories = getCamelContext().getRegistry().findByType(RestApiConsumerFactory.class);
        if (factories != null && factories.size() == 1) {
            factory = factories.iterator().next();
        }
    }
    if (factory != null) {
        // calculate the url to the rest API service
        RestConfiguration config = getCamelContext().getRestConfiguration(cname, true);
        // calculate the url to the rest API service
        String path = getPath();
        if (path != null && !path.startsWith("/")) {
            path = "/" + path;
        }
        Consumer consumer = factory.createApiConsumer(getCamelContext(), processor, path, config, getParameters());
        configureConsumer(consumer);
        return consumer;
    } else {
        throw new IllegalStateException("Cannot find RestApiConsumerFactory in Registry or as a Component to use");
    }
}
Also used : Consumer(org.apache.camel.Consumer) RestApiConsumerFactory(org.apache.camel.spi.RestApiConsumerFactory) NoSuchBeanException(org.apache.camel.NoSuchBeanException) RestConfiguration(org.apache.camel.spi.RestConfiguration) Component(org.apache.camel.Component)

Example 8 with Consumer

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

the class BrowseEndpoint method createConsumer.

public Consumer createConsumer(Processor processor) throws Exception {
    Consumer answer = new LoadBalancerConsumer(this, processor, loadBalancer);
    configureConsumer(answer);
    return answer;
}
Also used : Consumer(org.apache.camel.Consumer) LoadBalancerConsumer(org.apache.camel.processor.loadbalancer.LoadBalancerConsumer) LoadBalancerConsumer(org.apache.camel.processor.loadbalancer.LoadBalancerConsumer)

Example 9 with Consumer

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

the class DataSetEndpoint method createConsumer.

@Override
public Consumer createConsumer(Processor processor) throws Exception {
    Consumer answer = new DataSetConsumer(this, processor);
    configureConsumer(answer);
    return answer;
}
Also used : Consumer(org.apache.camel.Consumer)

Example 10 with Consumer

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

the class DirectVmEndpoint method createConsumer.

@Override
public Consumer createConsumer(Processor processor) throws Exception {
    Consumer answer = new DirectVmConsumer(this, new DirectVmProcessor(processor, this));
    configureConsumer(answer);
    return answer;
}
Also used : DirectConsumer(org.apache.camel.component.direct.DirectConsumer) Consumer(org.apache.camel.Consumer)

Aggregations

Consumer (org.apache.camel.Consumer)76 Endpoint (org.apache.camel.Endpoint)27 Processor (org.apache.camel.Processor)19 Exchange (org.apache.camel.Exchange)18 Test (org.junit.Test)18 HashMap (java.util.HashMap)10 RestConfiguration (org.apache.camel.spi.RestConfiguration)10 Producer (org.apache.camel.Producer)7 PollingConsumer (org.apache.camel.PollingConsumer)6 File (java.io.File)5 PollingConsumerPollStrategy (org.apache.camel.spi.PollingConsumerPollStrategy)5 FileNotFoundException (java.io.FileNotFoundException)4 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)4 SuspendableService (org.apache.camel.SuspendableService)4 ArrayList (java.util.ArrayList)3 CountDownLatch (java.util.concurrent.CountDownLatch)3 CamelContext (org.apache.camel.CamelContext)3 Component (org.apache.camel.Component)3 NoSuchBeanException (org.apache.camel.NoSuchBeanException)3 Route (org.apache.camel.Route)3