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);
}
}
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"));
}
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();
}
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);
}
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());
}
Aggregations