Search in sources :

Example 46 with PollingConsumer

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

the class FtpConsumerDeleteNoWritePermissionTest method testConsumerDeleteNoWritePermission.

@Test
public void testConsumerDeleteNoWritePermission() throws Exception {
    PollingConsumer consumer = context.getEndpoint(getFtpUrl()).createPollingConsumer();
    consumer.start();
    Exchange out = consumer.receive(3000);
    assertNotNull("Should get the file", out);
    try {
        // give consumer time to try to delete the file
        Thread.sleep(1000);
        consumer.stop();
    } catch (GenericFileOperationFailedException fofe) {
    // expected, ignore
    }
}
Also used : Exchange(org.apache.camel.Exchange) PollingConsumer(org.apache.camel.PollingConsumer) GenericFileOperationFailedException(org.apache.camel.component.file.GenericFileOperationFailedException) Test(org.junit.Test)

Example 47 with PollingConsumer

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

the class InvalidConfigurationTest method testSMTPSCanNotBeUsedForConsumingMails.

@Test
public void testSMTPSCanNotBeUsedForConsumingMails() throws Exception {
    Endpoint endpoint = context.getEndpoint("smtps://localhost?username=james");
    PollingConsumer consumer = endpoint.createPollingConsumer();
    try {
        consumer.start();
        fail("Should have thrown NoSuchProviderException as stmp protocol cannot be used for consuming mails");
    } catch (IllegalArgumentException e) {
    // expected
    }
}
Also used : PollingConsumer(org.apache.camel.PollingConsumer) Endpoint(org.apache.camel.Endpoint) Test(org.junit.Test)

Example 48 with PollingConsumer

use of org.apache.camel.PollingConsumer in project syncope by apache.

the class AbstractCamelProvisioningManager method getConsumer.

protected PollingConsumer getConsumer(final String uri) {
    if (!knownURIs.contains(uri)) {
        knownURIs.add(uri);
        Endpoint endpoint = contextFactory.getCamelContext().getEndpoint(uri);
        PollingConsumer pollingConsumer = null;
        try {
            pollingConsumer = endpoint.createPollingConsumer();
            consumerMap.put(uri, pollingConsumer);
            pollingConsumer.start();
        } catch (Exception ex) {
            LOG.error("Unexpected error in Consumer creation ", ex);
        }
        return pollingConsumer;
    } else {
        return consumerMap.get(uri);
    }
}
Also used : PollingConsumer(org.apache.camel.PollingConsumer) Endpoint(org.apache.camel.Endpoint)

Example 49 with PollingConsumer

use of org.apache.camel.PollingConsumer in project syncope by apache.

the class CamelAnyObjectProvisioningManager method update.

@Transactional(propagation = Propagation.REQUIRES_NEW)
@Override
@SuppressWarnings("unchecked")
public Pair<AnyObjectPatch, List<PropagationStatus>> update(final AnyObjectPatch anyPatch, final Set<String> excludedResources, final boolean nullPriorityAsync) {
    PollingConsumer pollingConsumer = getConsumer("direct:updateAnyObjectPort");
    Map<String, Object> props = new HashMap<>();
    props.put("excludedResources", excludedResources);
    props.put("nullPriorityAsync", nullPriorityAsync);
    sendMessage("direct:updateAnyObject", anyPatch, props);
    Exchange exchange = pollingConsumer.receive();
    if (exchange.getProperty(Exchange.EXCEPTION_CAUGHT) != null) {
        throw (RuntimeException) exchange.getProperty(Exchange.EXCEPTION_CAUGHT);
    }
    return exchange.getIn().getBody(Pair.class);
}
Also used : Exchange(org.apache.camel.Exchange) PollingConsumer(org.apache.camel.PollingConsumer) HashMap(java.util.HashMap) Transactional(org.springframework.transaction.annotation.Transactional)

Example 50 with PollingConsumer

use of org.apache.camel.PollingConsumer in project syncope by apache.

the class CamelAnyObjectProvisioningManager method unlink.

@Override
public String unlink(final AnyObjectPatch anyObjectPatch) {
    PollingConsumer pollingConsumer = getConsumer("direct:unlinkAnyObjectPort");
    sendMessage("direct:unlinkAnyObject", anyObjectPatch);
    Exchange exchange = pollingConsumer.receive();
    if (exchange.getProperty(Exchange.EXCEPTION_CAUGHT) != null) {
        throw (RuntimeException) exchange.getProperty(Exchange.EXCEPTION_CAUGHT);
    }
    return exchange.getIn().getBody(AnyObjectPatch.class).getKey();
}
Also used : Exchange(org.apache.camel.Exchange) PollingConsumer(org.apache.camel.PollingConsumer) AnyObjectPatch(org.apache.syncope.common.lib.patch.AnyObjectPatch)

Aggregations

PollingConsumer (org.apache.camel.PollingConsumer)73 Exchange (org.apache.camel.Exchange)41 Test (org.junit.Test)27 HashMap (java.util.HashMap)21 CamelContext (org.apache.camel.CamelContext)21 DefaultCamelContext (org.apache.camel.impl.DefaultCamelContext)21 RouteBuilder (org.apache.camel.builder.RouteBuilder)19 Endpoint (org.apache.camel.Endpoint)10 Connection (javax.jms.Connection)9 Transactional (org.springframework.transaction.annotation.Transactional)9 ConnectionFactory (javax.jms.ConnectionFactory)7 JMSException (javax.jms.JMSException)7 MessageConversionException (org.springframework.jms.support.converter.MessageConversionException)5 ProducerTemplate (org.apache.camel.ProducerTemplate)4 WorkflowResult (org.apache.syncope.core.provisioning.api.WorkflowResult)4 Message (javax.jms.Message)3 Session (javax.jms.Session)3 TextMessage (javax.jms.TextMessage)3 ActiveMQTextMessage (org.apache.activemq.command.ActiveMQTextMessage)3 File (java.io.File)2