Search in sources :

Example 1 with CamelContextFactory

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

the class CamelContextFactoryProvider method lookup.

@Override
public Object lookup(ArquillianResource resource, Annotation... qualifiers) {
    if (serviceInstance.get() == null) {
        CamelContextFactory service;
        try {
            InitialContext initialContext = new InitialContext();
            service = (CamelContextFactory) initialContext.lookup(CamelConstants.CAMEL_CONTEXT_FACTORY_BINDING_NAME);
        } catch (NamingException ex) {
            throw new IllegalStateException(ex);
        }
        if (service != null) {
            serviceProducer.set(service);
        }
    }
    return serviceInstance.get();
}
Also used : NamingException(javax.naming.NamingException) CamelContextFactory(org.wildfly.extension.camel.CamelContextFactory) InitialContext(javax.naming.InitialContext)

Example 2 with CamelContextFactory

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

the class JNDIIntegrationTest method testCamelContextFactoryLookup.

@Test
public void testCamelContextFactoryLookup() throws Exception {
    InitialContext inicxt = new InitialContext();
    CamelContextFactory factory = (CamelContextFactory) inicxt.lookup(CamelConstants.CAMEL_CONTEXT_FACTORY_BINDING_NAME);
    WildFlyCamelContext camelctx = factory.createCamelContext();
    assertBeanBinding(camelctx);
}
Also used : CamelContextFactory(org.wildfly.extension.camel.CamelContextFactory) WildFlyCamelContext(org.wildfly.extension.camel.WildFlyCamelContext) InitialContext(javax.naming.InitialContext) Test(org.junit.Test)

Example 3 with CamelContextFactory

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

the class JNDIIntegrationTest method testCamelContextFactoryService.

@Test
public void testCamelContextFactoryService() throws Exception {
    CamelContextFactory contextFactory = ServiceLocator.getRequiredService(CamelContextFactory.class);
    WildFlyCamelContext camelctx = contextFactory.createCamelContext(getClass().getClassLoader());
    assertBeanBinding(camelctx);
}
Also used : CamelContextFactory(org.wildfly.extension.camel.CamelContextFactory) WildFlyCamelContext(org.wildfly.extension.camel.WildFlyCamelContext) Test(org.junit.Test)

Example 4 with CamelContextFactory

use of org.wildfly.extension.camel.CamelContextFactory 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 5 with CamelContextFactory

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

the class CamelContextFactoryBindingService method addService.

public static ServiceController<?> addService(final ServiceTarget serviceTarget) {
    final ContextNames.BindInfo bindInfo = ContextNames.bindInfoFor(CamelConstants.CAMEL_CONTEXT_FACTORY_BINDING_NAME);
    BinderService binderService = new BinderService(bindInfo.getBindName()) {

        @Override
        public synchronized void start(StartContext context) throws StartException {
            super.start(context);
            LOGGER.info("Bound camel naming object: {}", bindInfo.getAbsoluteJndiName());
        }

        @Override
        public synchronized void stop(StopContext context) {
            LOGGER.debug("Unbind camel naming object: {}", bindInfo.getAbsoluteJndiName());
            super.stop(context);
        }
    };
    Injector<ManagedReferenceFactory> injector = binderService.getManagedObjectInjector();
    ServiceBuilder<?> builder = serviceTarget.addService(bindInfo.getBinderServiceName(), binderService);
    builder.addDependency(bindInfo.getParentContextServiceName(), ServiceBasedNamingStore.class, binderService.getNamingStoreInjector());
    builder.addDependency(CamelConstants.CAMEL_CONTEXT_FACTORY_SERVICE_NAME, CamelContextFactory.class, new ManagedReferenceInjector<CamelContextFactory>(injector));
    return builder.install();
}
Also used : BinderService(org.jboss.as.naming.service.BinderService) StopContext(org.jboss.msc.service.StopContext) StartContext(org.jboss.msc.service.StartContext) ManagedReferenceFactory(org.jboss.as.naming.ManagedReferenceFactory) CamelContextFactory(org.wildfly.extension.camel.CamelContextFactory) ContextNames(org.jboss.as.naming.deployment.ContextNames)

Aggregations

CamelContextFactory (org.wildfly.extension.camel.CamelContextFactory)5 Test (org.junit.Test)3 WildFlyCamelContext (org.wildfly.extension.camel.WildFlyCamelContext)3 InitialContext (javax.naming.InitialContext)2 Context (javax.naming.Context)1 NamingException (javax.naming.NamingException)1 Exchange (org.apache.camel.Exchange)1 Message (org.apache.camel.Message)1 Processor (org.apache.camel.Processor)1 ProducerTemplate (org.apache.camel.ProducerTemplate)1 RouteBuilder (org.apache.camel.builder.RouteBuilder)1 ManagedReferenceFactory (org.jboss.as.naming.ManagedReferenceFactory)1 ContextNames (org.jboss.as.naming.deployment.ContextNames)1 BinderService (org.jboss.as.naming.service.BinderService)1 StartContext (org.jboss.msc.service.StartContext)1 StopContext (org.jboss.msc.service.StopContext)1 JedisConnectionFactory (org.springframework.data.redis.connection.jedis.JedisConnectionFactory)1 RedisTemplate (org.springframework.data.redis.core.RedisTemplate)1