Search in sources :

Example 1 with Consumer

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

the class XmlServiceExporterBean method create.

@Override
public T create(CreationalContext<T> creationalContext) {
    try {
        CamelContext context = isNotEmpty(exporter.getCamelContextId()) ? getReferenceByName(manager, exporter.getCamelContextId(), CamelContext.class).get() : getReference(manager, CamelContext.class, this.context);
        Bean<?> bean = manager.resolve(manager.getBeans(exporter.getServiceRef()));
        if (bean == null) {
            throw new UnsatisfiedResolutionException("No bean with name [" + exporter.getServiceRef() + "] is deployed!");
        }
        @SuppressWarnings("unchecked") T service = (T) manager.getReference(bean, type, manager.createCreationalContext(bean));
        Endpoint endpoint = getMandatoryEndpoint(context, exporter.getUri());
        try {
            // need to start endpoint before we create consumer
            startService(endpoint);
            Consumer consumer = endpoint.createConsumer(new BeanProcessor(service, context));
            // add and start consumer
            context.addService(consumer, true, true);
        } catch (Exception cause) {
            throw new FailedToCreateConsumerException(endpoint, cause);
        }
        return service;
    } catch (Exception cause) {
        throw new CreationException("Error while creating instance for " + this, cause);
    }
}
Also used : CamelContext(org.apache.camel.CamelContext) FailedToCreateConsumerException(org.apache.camel.FailedToCreateConsumerException) CamelContextHelper.getMandatoryEndpoint(org.apache.camel.util.CamelContextHelper.getMandatoryEndpoint) Endpoint(org.apache.camel.Endpoint) Consumer(org.apache.camel.Consumer) BeanProcessor(org.apache.camel.component.bean.BeanProcessor) UnsatisfiedResolutionException(javax.enterprise.inject.UnsatisfiedResolutionException) CreationException(javax.enterprise.inject.CreationException) FailedToCreateConsumerException(org.apache.camel.FailedToCreateConsumerException) UnsatisfiedResolutionException(javax.enterprise.inject.UnsatisfiedResolutionException) CreationException(javax.enterprise.inject.CreationException)

Example 2 with Consumer

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

the class CMISConsumerTest method getAllContentFromServerOrderedFromRootToLeaves.

@Test
public void getAllContentFromServerOrderedFromRootToLeaves() throws Exception {
    resultEndpoint.expectedMessageCount(5);
    Consumer treeBasedConsumer = createConsumerFor(getUrl() + "?pageSize=50");
    treeBasedConsumer.start();
    resultEndpoint.assertIsSatisfied();
    treeBasedConsumer.stop();
    List<Exchange> exchanges = resultEndpoint.getExchanges();
    assertTrue(getNodeNameForIndex(exchanges, 0).equals("RootFolder"));
    assertTrue(getNodeNameForIndex(exchanges, 1).equals("Folder1"));
    assertTrue(getNodeNameForIndex(exchanges, 2).equals("Folder2"));
    assertTrue(getNodeNameForIndex(exchanges, 3).contains(".txt"));
    assertTrue(getNodeNameForIndex(exchanges, 4).contains(".txt"));
}
Also used : Exchange(org.apache.camel.Exchange) Consumer(org.apache.camel.Consumer) Test(org.junit.Test)

Example 3 with Consumer

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

the class CMISConsumerTest method consumeDocumentsWithQuery.

@Test
public void consumeDocumentsWithQuery() throws Exception {
    resultEndpoint.expectedMessageCount(2);
    Consumer queryBasedConsumer = createConsumerFor(getUrl() + "?query=SELECT * FROM cmis:document");
    queryBasedConsumer.start();
    resultEndpoint.assertIsSatisfied();
    queryBasedConsumer.stop();
}
Also used : Consumer(org.apache.camel.Consumer) Test(org.junit.Test)

Example 4 with Consumer

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

the class DropboxConsumerTest method shouldCreateGetConsumer.

@Test
public void shouldCreateGetConsumer() throws Exception {
    // Given
    Endpoint dropboxEndpoint1 = context.getEndpoint("dropbox://get?accessToken={{accessToken}}&clientIdentifier={{clientIdentifier}}&remotePath=/path");
    // When
    Consumer consumer1 = dropboxEndpoint1.createConsumer(null);
    // Then
    Assert.assertTrue(consumer1 instanceof DropboxScheduledPollGetConsumer);
    // Given
    Endpoint dropboxEndpoint2 = context.getEndpoint("dropbox://get?accessToken={{accessToken}}&clientIdentifier={{clientIdentifier}}&remotePath=/path with spaces/file");
    // When
    Consumer consumer2 = dropboxEndpoint2.createConsumer(null);
    // Then
    Assert.assertTrue(consumer2 instanceof DropboxScheduledPollGetConsumer);
}
Also used : Endpoint(org.apache.camel.Endpoint) DropboxScheduledPollGetConsumer(org.apache.camel.component.dropbox.integration.consumer.DropboxScheduledPollGetConsumer) Consumer(org.apache.camel.Consumer) DropboxScheduledPollGetConsumer(org.apache.camel.component.dropbox.integration.consumer.DropboxScheduledPollGetConsumer) Test(org.junit.Test)

Example 5 with Consumer

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

the class FtpConsumerThrowExceptionOnLoginFailedTest method testBadLogin.

@Test
public void testBadLogin() throws Exception {
    getMockEndpoint("mock:result").expectedMessageCount(0);
    assertTrue(latch.await(5, TimeUnit.SECONDS));
    assertMockEndpointsSatisfied();
    // consumer should be stopped
    Thread.sleep(1000);
    Consumer consumer = context.getRoute("foo").getConsumer();
    assertTrue("Consumer should be stopped", ((ServiceSupport) consumer).isStopped());
}
Also used : Consumer(org.apache.camel.Consumer) Test(org.junit.Test)

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