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();
}
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);
}
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);
}
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();
}
}
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();
}
Aggregations