Search in sources :

Example 21 with WildFlyCamelContext

use of org.wildfly.extension.camel.WildFlyCamelContext in project wildfly-camel by wildfly-extras.

the class SpringRedisIntegrationTest method testRedisRoute.

@Test
@SuppressWarnings("rawtypes")
public void testRedisRoute() throws Exception {
    Assume.assumeFalse("[#1701] Cannot start Redis server on Windows", EnvironmentUtils.isWindows());
    JedisConnectionFactory connectionFactory = new JedisConnectionFactory();
    connectionFactory.afterPropertiesSet();
    RedisTemplate redisTemplate = new RedisTemplate();
    redisTemplate.setConnectionFactory(connectionFactory);
    redisTemplate.afterPropertiesSet();
    CamelContextFactory contextFactory = ServiceLocator.getRequiredService(CamelContextFactory.class);
    WildFlyCamelContext camelctx = contextFactory.createCamelContext(getClass().getClassLoader());
    Context jndictx = camelctx.getNamingContext();
    jndictx.bind("redisTemplate", redisTemplate);
    camelctx.addRoutes(new RouteBuilder() {

        @Override
        public void configure() throws Exception {
            int port = Integer.parseInt(AvailablePortFinder.readServerData("redis-port"));
            from("direct:start").to("spring-redis://localhost:" + port + "?redisTemplate=#redisTemplate");
        }
    });
    camelctx.start();
    try {
        Object[] headers = new Object[] { RedisConstants.COMMAND, "SET", RedisConstants.KEY, "key1", RedisConstants.VALUE, "value" };
        ProducerTemplate producer = camelctx.createProducerTemplate();
        producer.send("direct:start", new Processor() {

            public void process(Exchange exchange) throws Exception {
                Message in = exchange.getIn();
                for (int i = 0; i < headers.length; i = i + 2) {
                    in.setHeader(headers[i].toString(), headers[i + 1]);
                }
            }
        });
        Assert.assertEquals("value", redisTemplate.opsForValue().get("key1"));
    } finally {
        camelctx.stop();
    }
}
Also used : Context(javax.naming.Context) WildFlyCamelContext(org.wildfly.extension.camel.WildFlyCamelContext) ProducerTemplate(org.apache.camel.ProducerTemplate) RedisTemplate(org.springframework.data.redis.core.RedisTemplate) Processor(org.apache.camel.Processor) RouteBuilder(org.apache.camel.builder.RouteBuilder) Message(org.apache.camel.Message) CamelContextFactory(org.wildfly.extension.camel.CamelContextFactory) Exchange(org.apache.camel.Exchange) JedisConnectionFactory(org.springframework.data.redis.connection.jedis.JedisConnectionFactory) WildFlyCamelContext(org.wildfly.extension.camel.WildFlyCamelContext) Test(org.junit.Test)

Example 22 with WildFlyCamelContext

use of org.wildfly.extension.camel.WildFlyCamelContext in project wildfly-camel by wildfly-extras.

the class S3IntegrationTest method testBucketOperations.

@Test
public void testBucketOperations() throws Exception {
    AmazonS3Client s3Client = provider.getClient();
    Assume.assumeNotNull("AWS client not null", s3Client);
    assertNoStaleBuckets(s3Client, "before");
    try {
        try {
            S3Utils.createBucket(s3Client, bucketName);
            WildFlyCamelContext camelctx = new WildFlyCamelContext();
            camelctx.getNamingContext().bind("s3Client", s3Client);
            camelctx.addRoutes(new RouteBuilder() {

                @Override
                public void configure() throws Exception {
                    String clientref = "amazonS3Client=#s3Client";
                    from("direct:upload").to("aws-s3://" + bucketName + "?" + clientref);
                    from("aws-s3://" + bucketName + "?" + clientref).to("seda:read");
                }
            });
            try {
                camelctx.start();
                try {
                    // Put object
                    Map<String, Object> headers = new HashMap<>();
                    headers.put(S3Constants.KEY, OBJECT_KEY);
                    ProducerTemplate producer = camelctx.createProducerTemplate();
                    String content = "My bucket content";
                    String result1 = producer.requestBodyAndHeaders("direct:upload", content, headers, String.class);
                    Assert.assertEquals(content, result1);
                    ConsumerTemplate consumer = camelctx.createConsumerTemplate();
                    String result2 = consumer.receiveBody("seda:read", String.class);
                    Assert.assertEquals(content, result2);
                } finally {
                    camelctx.stop();
                }
            } finally {
                s3Client.deleteObject(bucketName, OBJECT_KEY);
            }
        } finally {
            S3Utils.deleteBucket(s3Client, bucketName);
        }
    } finally {
        assertNoStaleBuckets(s3Client, "after");
    }
}
Also used : ProducerTemplate(org.apache.camel.ProducerTemplate) ConsumerTemplate(org.apache.camel.ConsumerTemplate) AmazonS3Client(com.amazonaws.services.s3.AmazonS3Client) RouteBuilder(org.apache.camel.builder.RouteBuilder) HashMap(java.util.HashMap) WildFlyCamelContext(org.wildfly.extension.camel.WildFlyCamelContext) Test(org.junit.Test)

Example 23 with WildFlyCamelContext

use of org.wildfly.extension.camel.WildFlyCamelContext in project wildfly-camel by wildfly-extras.

the class InfinispanIntegrationTest method setUp.

@Before
public void setUp() throws Exception {
    camelctx = new WildFlyCamelContext();
    cacheContainer = (CacheContainer) camelctx.getNamingContext().lookup(CONTAINER_NAME);
    cacheName = cacheContainer.getCache().getName();
}
Also used : WildFlyCamelContext(org.wildfly.extension.camel.WildFlyCamelContext) Before(org.junit.Before)

Example 24 with WildFlyCamelContext

use of org.wildfly.extension.camel.WildFlyCamelContext in project wildfly-camel by wildfly-extras.

the class AzureIntegrationTest method createCamelContext.

private CamelContext createCamelContext(StorageCredentials creds) throws Exception {
    WildFlyCamelContext camelctx = new WildFlyCamelContext();
    Context jndictx = camelctx.getNamingContext();
    jndictx.rebind("creds", creds);
    return camelctx;
}
Also used : CamelContext(org.apache.camel.CamelContext) OperationContext(com.microsoft.azure.storage.OperationContext) WildFlyCamelContext(org.wildfly.extension.camel.WildFlyCamelContext) Context(javax.naming.Context) WildFlyCamelContext(org.wildfly.extension.camel.WildFlyCamelContext)

Example 25 with WildFlyCamelContext

use of org.wildfly.extension.camel.WildFlyCamelContext in project wildfly-camel by wildfly-extras.

the class CaffeineLoadCacheIntegrationTest method before.

@Before
public void before() throws Exception {
    CacheLoader<Integer, Integer> cl = new CacheLoader<Integer, Integer>() {

        public Integer load(Integer key) throws Exception {
            return key + 1;
        }
    };
    cache = Caffeine.newBuilder().build(cl);
    camelctx = new WildFlyCamelContext();
    Context jndi = camelctx.getNamingContext();
    jndi.rebind("cache", cache);
}
Also used : WildFlyCamelContext(org.wildfly.extension.camel.WildFlyCamelContext) Context(javax.naming.Context) CacheLoader(com.github.benmanes.caffeine.cache.CacheLoader) WildFlyCamelContext(org.wildfly.extension.camel.WildFlyCamelContext) Before(org.junit.Before)

Aggregations

WildFlyCamelContext (org.wildfly.extension.camel.WildFlyCamelContext)26 Test (org.junit.Test)20 RouteBuilder (org.apache.camel.builder.RouteBuilder)18 ProducerTemplate (org.apache.camel.ProducerTemplate)14 Exchange (org.apache.camel.Exchange)8 Context (javax.naming.Context)6 Processor (org.apache.camel.Processor)6 HashMap (java.util.HashMap)4 MockEndpoint (org.apache.camel.component.mock.MockEndpoint)4 CamelContext (org.apache.camel.CamelContext)3 Before (org.junit.Before)3 AmazonDynamoDBClient (com.amazonaws.services.dynamodbv2.AmazonDynamoDBClient)2 AttributeValue (com.amazonaws.services.dynamodbv2.model.AttributeValue)2 TableDescription (com.amazonaws.services.dynamodbv2.model.TableDescription)2 AmazonSNSClient (com.amazonaws.services.sns.AmazonSNSClient)2 List (java.util.List)2 InitialContext (javax.naming.InitialContext)2 CamelContextFactory (org.wildfly.extension.camel.CamelContextFactory)2 AmazonCloudWatchClient (com.amazonaws.services.cloudwatch.AmazonCloudWatchClient)1 DimensionFilter (com.amazonaws.services.cloudwatch.model.DimensionFilter)1