Search in sources :

Example 66 with PollingConsumer

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

the class AhcWSSIntegrationTest method testAsyncWssRoute.

@Test
public void testAsyncWssRoute() throws Exception {
    CamelContext camelctx = new DefaultCamelContext();
    camelctx.addRoutes(new RouteBuilder() {

        @Override
        public void configure() throws Exception {
            from("direct:start").to("ahc-wss:" + WEBSOCKET_ENDPOINT);
            from("ahc-wss:" + WEBSOCKET_ENDPOINT).to("seda:end");
        }
    });
    WsComponent wsComponent = (WsComponent) camelctx.getComponent("ahc-wss");
    wsComponent.setSslContextParameters(defineSSLContextClientParameters());
    PollingConsumer consumer = camelctx.getEndpoint("seda:end").createPollingConsumer();
    consumer.start();
    camelctx.start();
    try {
        ProducerTemplate producer = camelctx.createProducerTemplate();
        producer.sendBody("direct:start", "Kermit");
        Exchange exchange = consumer.receive(1000);
        Assert.assertEquals("Hello Kermit", exchange.getIn().getBody(String.class));
    } finally {
        camelctx.stop();
    }
}
Also used : CamelContext(org.apache.camel.CamelContext) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) Exchange(org.apache.camel.Exchange) ProducerTemplate(org.apache.camel.ProducerTemplate) PollingConsumer(org.apache.camel.PollingConsumer) RouteBuilder(org.apache.camel.builder.RouteBuilder) WsComponent(org.apache.camel.component.ahc.ws.WsComponent) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) Test(org.junit.Test)

Example 67 with PollingConsumer

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

the class DynamoDBStreamsIntegrationTest method testKeyValueOperations.

@Test
public void testKeyValueOperations() throws Exception {
    AmazonDynamoDBClient ddbClient = ddbProvider.getClient();
    Assume.assumeNotNull("AWS client not null", ddbClient);
    DynamoDBUtils.assertNoStaleTables(ddbClient, "before");
    try {
        try {
            TableDescription description = DynamoDBUtils.createTable(ddbClient, tableName);
            Assert.assertEquals("ACTIVE", description.getTableStatus());
            WildFlyCamelContext camelctx = new WildFlyCamelContext();
            camelctx.getNamingContext().bind("ddbClientB", ddbClient);
            camelctx.getNamingContext().bind("dbsClientB", dbsProvider.getClient());
            camelctx.addRoutes(new RouteBuilder() {

                @Override
                public void configure() throws Exception {
                    from("direct:start").to("aws-ddb://" + tableName + "?amazonDDBClient=#ddbClientB");
                    from("aws-ddbstream://" + tableName + "?amazonDynamoDbStreamsClient=#dbsClientB").to("seda:end");
                }
            });
            PollingConsumer pollingConsumer = camelctx.getEndpoint("seda:end").createPollingConsumer();
            pollingConsumer.start();
            camelctx.start();
            try {
                DynamoDBUtils.putItem(camelctx, "Book 103 Title");
                String result = ((AttributeValue) DynamoDBUtils.getItem(camelctx).get("Title")).getS();
                Assert.assertEquals("Book 103 Title", result);
                Exchange exchange = pollingConsumer.receive(3000);
                Assert.assertNull(exchange);
                DynamoDBUtils.updItem(camelctx, "Book 103 Update");
                result = ((AttributeValue) DynamoDBUtils.getItem(camelctx).get("Title")).getS();
                Assert.assertEquals("Book 103 Update", result);
                exchange = pollingConsumer.receive(3000);
                StreamRecord record = exchange.getIn().getBody(Record.class).getDynamodb();
                Map<String, AttributeValue> oldImage = record.getOldImage();
                Map<String, AttributeValue> newImage = record.getNewImage();
                Assert.assertEquals("Book 103 Title", oldImage.get("Title").getS());
                Assert.assertEquals("Book 103 Update", newImage.get("Title").getS());
            } finally {
                camelctx.stop();
            }
        } finally {
            DynamoDBUtils.deleteTable(ddbClient, tableName);
        }
    } finally {
        DynamoDBUtils.assertNoStaleTables(ddbClient, "after");
    }
}
Also used : PollingConsumer(org.apache.camel.PollingConsumer) AttributeValue(com.amazonaws.services.dynamodbv2.model.AttributeValue) StreamRecord(com.amazonaws.services.dynamodbv2.model.StreamRecord) RouteBuilder(org.apache.camel.builder.RouteBuilder) TableDescription(com.amazonaws.services.dynamodbv2.model.TableDescription) Exchange(org.apache.camel.Exchange) AmazonDynamoDBClient(com.amazonaws.services.dynamodbv2.AmazonDynamoDBClient) StreamRecord(com.amazonaws.services.dynamodbv2.model.StreamRecord) Record(com.amazonaws.services.dynamodbv2.model.Record) WildFlyCamelContext(org.wildfly.extension.camel.WildFlyCamelContext) Test(org.junit.Test)

Example 68 with PollingConsumer

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

the class ActiveMQIntegrationTest method testCustomMessageConverter.

@Test
public void testCustomMessageConverter() throws Exception {
    MessageConverter converter = new MessageConverter() {

        @Override
        public Message toMessage(Object o, Session session) throws JMSException, MessageConversionException {
            return null;
        }

        @Override
        public Object fromMessage(Message message) throws JMSException, MessageConversionException {
            TextMessage originalMessage = (TextMessage) message;
            TextMessage modifiedMessage = new ActiveMQTextMessage();
            modifiedMessage.setText(originalMessage.getText() + " Modified");
            return modifiedMessage;
        }
    };
    context.bind("messageConverter", converter);
    CamelContext camelctx = new DefaultCamelContext();
    camelctx.addRoutes(new RouteBuilder() {

        @Override
        public void configure() throws Exception {
            fromF("activemq:queue:%s?connectionFactory=java:/ActiveMQConnectionFactory&messageConverter=#messageConverter", QUEUE_NAME).transform(simple("Hello ${body.getText()}")).to("seda:end");
        }
    });
    PollingConsumer pollingConsumer = camelctx.getEndpoint("seda:end").createPollingConsumer();
    pollingConsumer.start();
    camelctx.start();
    try {
        ConnectionFactory connectionFactory = lookupConnectionFactory();
        Connection con = connectionFactory.createConnection();
        try {
            sendMessage(con, "Kermit");
            String result = pollingConsumer.receive(3000).getIn().getBody(String.class);
            Assert.assertEquals("Hello Kermit Modified", result);
        } finally {
            con.close();
        }
    } finally {
        camelctx.stop();
        context.unbind("messageConverter");
    }
}
Also used : DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) CamelContext(org.apache.camel.CamelContext) PollingConsumer(org.apache.camel.PollingConsumer) ActiveMQTextMessage(org.apache.activemq.command.ActiveMQTextMessage) Message(javax.jms.Message) TextMessage(javax.jms.TextMessage) RouteBuilder(org.apache.camel.builder.RouteBuilder) Connection(javax.jms.Connection) MessageConverter(org.springframework.jms.support.converter.MessageConverter) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) NamingException(javax.naming.NamingException) MessageConversionException(org.springframework.jms.support.converter.MessageConversionException) JMSException(javax.jms.JMSException) ActiveMQTextMessage(org.apache.activemq.command.ActiveMQTextMessage) ConnectionFactory(javax.jms.ConnectionFactory) ActiveMQTextMessage(org.apache.activemq.command.ActiveMQTextMessage) TextMessage(javax.jms.TextMessage) Session(javax.jms.Session) Test(org.junit.Test)

Example 69 with PollingConsumer

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

the class AhcWSIntegrationTest method testAsyncWsRoute.

@Test
public void testAsyncWsRoute() throws Exception {
    CamelContext camelctx = new DefaultCamelContext();
    camelctx.addRoutes(new RouteBuilder() {

        @Override
        public void configure() throws Exception {
            from("direct:start").to("ahc-ws:" + WEBSOCKET_ENDPOINT);
            from("ahc-ws:" + WEBSOCKET_ENDPOINT).to("seda:end");
        }
    });
    PollingConsumer consumer = camelctx.getEndpoint("seda:end").createPollingConsumer();
    consumer.start();
    camelctx.start();
    try {
        ProducerTemplate producer = camelctx.createProducerTemplate();
        producer.sendBody("direct:start", "Kermit");
        Exchange exchange = consumer.receive(1000);
        Assert.assertEquals("Hello Kermit", exchange.getIn().getBody(String.class));
    } finally {
        camelctx.stop();
    }
}
Also used : DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) CamelContext(org.apache.camel.CamelContext) Exchange(org.apache.camel.Exchange) 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 70 with PollingConsumer

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

the class AtomIntegrationTest method testConsumeAtomFeed.

@Test
public void testConsumeAtomFeed() throws Exception {
    CamelContext camelctx = new DefaultCamelContext();
    camelctx.addRoutes(new RouteBuilder() {

        @Override
        public void configure() throws Exception {
            from("atom://http://localhost:8080/atom-test/atom/feed?splitEntries=true").to("seda:end");
        }
    });
    PollingConsumer pollingConsumer = camelctx.getEndpoint("seda:end").createPollingConsumer();
    pollingConsumer.start();
    camelctx.start();
    try {
        Entry result = pollingConsumer.receive(5000).getIn().getBody(Entry.class);
        Assert.assertEquals(FeedConstants.ENTRY_TITLE, result.getTitle());
        Assert.assertEquals(FeedConstants.ENTRY_CONTENT, result.getContent());
    } finally {
        camelctx.stop();
    }
}
Also used : CamelContext(org.apache.camel.CamelContext) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) PollingConsumer(org.apache.camel.PollingConsumer) Entry(org.apache.abdera.model.Entry) RouteBuilder(org.apache.camel.builder.RouteBuilder) 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