Search in sources :

Example 61 with PollingConsumer

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

the class CamelUserProvisioningManager method reactivate.

@Override
@SuppressWarnings("unchecked")
public Pair<String, List<PropagationStatus>> reactivate(final StatusPatch statusPatch, final boolean nullPriorityAsync) {
    PollingConsumer pollingConsumer = getConsumer("direct:statusPort");
    Map<String, Object> props = new HashMap<>();
    props.put("key", statusPatch.getKey());
    props.put("statusPatch", statusPatch);
    props.put("nullPriorityAsync", nullPriorityAsync);
    if (statusPatch.isOnSyncope()) {
        sendMessage("direct:reactivateUser", statusPatch.getKey(), props);
    } else {
        WorkflowResult<String> updated = new WorkflowResult<>(statusPatch.getKey(), null, statusPatch.getType().name().toLowerCase());
        sendMessage("direct:userStatusPropagation", updated, 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) WorkflowResult(org.apache.syncope.core.provisioning.api.WorkflowResult) HashMap(java.util.HashMap)

Example 62 with PollingConsumer

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

the class CamelUserProvisioningManager method unlink.

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

Example 63 with PollingConsumer

use of org.apache.camel.PollingConsumer in project wildfly-camel by wildfly-extras.

the class CXFWSSecureProducerIntegrationTest method testEndpointRouteWithInvalidCredentials.

@Test
public void testEndpointRouteWithInvalidCredentials() throws Exception {
    deployer.deploy(SIMPLE_WAR);
    try {
        CamelContext camelctx = new DefaultCamelContext();
        camelctx.addRoutes(new RouteBuilder() {

            @Override
            public void configure() throws Exception {
                from("direct:start").doTry().to("cxf://" + getEndpointAddress("/simple", "baduser", "badpassword")).doCatch(Exception.class).setBody(exceptionMessage()).to("direct:error").end();
            }
        });
        PollingConsumer pollingConsumer = camelctx.getEndpoint("direct:error").createPollingConsumer();
        pollingConsumer.start();
        camelctx.start();
        try {
            ProducerTemplate producer = camelctx.createProducerTemplate();
            producer.requestBody("direct:start", "Kermit", String.class);
            String result = pollingConsumer.receive(3000).getIn().getBody(String.class);
            Assert.assertTrue(result.contains("401: Unauthorized"));
        } finally {
            camelctx.stop();
        }
    } finally {
        deployer.undeploy(SIMPLE_WAR);
    }
}
Also used : DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) CamelContext(org.apache.camel.CamelContext) ProducerTemplate(org.apache.camel.ProducerTemplate) PollingConsumer(org.apache.camel.PollingConsumer) RouteBuilder(org.apache.camel.builder.RouteBuilder) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) Test(org.junit.Test)

Example 64 with PollingConsumer

use of org.apache.camel.PollingConsumer in project wildfly-camel by wildfly-extras.

the class TransactedJMSIntegrationTest method testJMSTransactionToDLQ.

@Test
public void testJMSTransactionToDLQ() throws Exception {
    CamelContext camelctx = new DefaultCamelContext();
    camelctx.addComponent("jms", jmsComponent);
    camelctx.addRoutes(configureJmsRoutes());
    camelctx.start();
    PollingConsumer consumer = camelctx.getEndpoint("seda:dlq").createPollingConsumer();
    consumer.start();
    // Send a message to queue camel-jms-queue-one
    Connection connection = connectionFactory.createConnection();
    sendMessage(connection, JmsQueue.QUEUE_ONE.getJndiName(), "Hello Bob");
    // The JMS transaction should have been rolled back and the message sent to the DLQ
    String result = consumer.receive().getIn().getBody(String.class);
    Assert.assertNotNull(result);
    Assert.assertEquals("Hello Bob", result);
    connection.close();
    camelctx.stop();
}
Also used : DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) CamelContext(org.apache.camel.CamelContext) PollingConsumer(org.apache.camel.PollingConsumer) Connection(javax.jms.Connection) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) Test(org.junit.Test)

Example 65 with PollingConsumer

use of org.apache.camel.PollingConsumer in project wildfly-camel by wildfly-extras.

the class SQLIntegrationTest method testSQLEndpoint.

@Test
public void testSQLEndpoint() throws Exception {
    Assert.assertNotNull("DataSource not null", dataSource);
    CamelContext camelctx = new DefaultCamelContext();
    camelctx.addRoutes(new RouteBuilder() {

        @Override
        public void configure() throws Exception {
            from("sql:select name from information_schema.users?dataSource=java:jboss/datasources/ExampleDS").to("seda:end");
        }
    });
    PollingConsumer pollingConsumer = camelctx.getEndpoint("seda:end").createPollingConsumer();
    pollingConsumer.start();
    camelctx.start();
    try {
        String result = (String) pollingConsumer.receive(3000).getIn().getBody(Map.class).get("NAME");
        Assert.assertEquals("SA", result);
    } finally {
        camelctx.stop();
    }
}
Also used : CamelContext(org.apache.camel.CamelContext) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) PollingConsumer(org.apache.camel.PollingConsumer) RouteBuilder(org.apache.camel.builder.RouteBuilder) CDIRouteBuilder(org.wildfly.camel.test.sql.subA.CDIRouteBuilder) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) Test(org.junit.Test)

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