Search in sources :

Example 1 with DefaultCamelContext

use of org.apache.camel.impl.DefaultCamelContext in project camel by apache.

the class CamelContextOsgiProducer method produce.

@Override
public T produce(CreationalContext<T> ctx) {
    T context = super.produce(ctx);
    // Register the context in the OSGi registry
    BundleContext bundle = BundleContextUtils.getBundleContext(getClass());
    context.getManagementStrategy().addEventNotifier(new OsgiCamelContextPublisher(bundle));
    if (!(context instanceof DefaultCamelContext)) {
        // Fail fast for the time being to avoid side effects by some methods get declared on the CamelContext interface
        throw new InjectionException("Camel CDI requires Camel context [" + context.getName() + "] to be a subtype of DefaultCamelContext");
    }
    DefaultCamelContext adapted = context.adapt(DefaultCamelContext.class);
    adapted.setRegistry(OsgiCamelContextHelper.wrapRegistry(context, context.getRegistry(), bundle));
    CamelContextNameStrategy strategy = context.getNameStrategy();
    OsgiCamelContextHelper.osgiUpdate(adapted, bundle);
    // FIXME: the above call should not override explicit strategies provided by the end user or should decorate them instead of overriding them completely
    if (!(strategy instanceof DefaultCamelContextNameStrategy)) {
        context.setNameStrategy(strategy);
    }
    return context;
}
Also used : InjectionException(javax.enterprise.inject.InjectionException) DefaultCamelContextNameStrategy(org.apache.camel.impl.DefaultCamelContextNameStrategy) OsgiCamelContextPublisher(org.apache.camel.core.osgi.OsgiCamelContextPublisher) CamelContextNameStrategy(org.apache.camel.spi.CamelContextNameStrategy) DefaultCamelContextNameStrategy(org.apache.camel.impl.DefaultCamelContextNameStrategy) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) BundleContext(org.osgi.framework.BundleContext)

Example 2 with DefaultCamelContext

use of org.apache.camel.impl.DefaultCamelContext in project camel by apache.

the class CamelContextProducer method produce.

@Override
public T produce(CreationalContext<T> ctx) {
    T context = super.produce(ctx);
    // Do not override the name if it's been already set (in the bean constructor for example)
    if (context.getNameStrategy() instanceof DefaultCamelContextNameStrategy) {
        context.setNameStrategy(nameStrategy(annotated));
    }
    // Add bean registry and Camel injector
    if (context instanceof DefaultCamelContext) {
        DefaultCamelContext adapted = context.adapt(DefaultCamelContext.class);
        adapted.setRegistry(new CdiCamelRegistry(manager));
        adapted.setInjector(new CdiCamelInjector(context.getInjector(), manager));
    } else {
        // Fail fast for the time being to avoid side effects by the time these two methods get declared on the CamelContext interface
        throw new InjectionException("Camel CDI requires Camel context [" + context.getName() + "] to be a subtype of DefaultCamelContext");
    }
    // Add event notifier if at least one observer is present
    Set<Annotation> qualifiers = annotated.getAnnotations().stream().filter(isAnnotationType(Named.class).negate().and(q -> manager.isQualifier(q.annotationType()))).collect(toSet());
    qualifiers.add(ANY);
    if (qualifiers.size() == 1) {
        qualifiers.add(DEFAULT);
    }
    qualifiers.retainAll(extension.getObserverEvents());
    if (!qualifiers.isEmpty()) {
        context.getManagementStrategy().addEventNotifier(new CdiEventNotifier(manager, qualifiers));
    }
    return context;
}
Also used : InjectionException(javax.enterprise.inject.InjectionException) DefaultCamelContextNameStrategy(org.apache.camel.impl.DefaultCamelContextNameStrategy) DEFAULT(org.apache.camel.cdi.DefaultLiteral.DEFAULT) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) Annotation(java.lang.annotation.Annotation)

Example 3 with DefaultCamelContext

use of org.apache.camel.impl.DefaultCamelContext in project camel by apache.

the class XmlCdiBeanFactory method camelContextBean.

private SyntheticBean<?> camelContextBean(CamelContextFactoryBean factory, URL url) {
    Set<Annotation> annotations = new HashSet<>();
    annotations.add(ANY);
    if (hasId(factory)) {
        addAll(annotations, ContextName.Literal.of(factory.getId()), NamedLiteral.of(factory.getId()));
    } else {
        annotations.add(DEFAULT);
        factory.setImplicitId(true);
        factory.setId(new CdiCamelContextNameStrategy().getNextName());
    }
    annotations.add(APPLICATION_SCOPED);
    SyntheticAnnotated annotated = new SyntheticAnnotated(DefaultCamelContext.class, manager.createAnnotatedType(DefaultCamelContext.class).getTypeClosure(), annotations);
    return new SyntheticBean<>(manager, annotated, DefaultCamelContext.class, environment.camelContextInjectionTarget(new SyntheticInjectionTarget<>(() -> {
        DefaultCamelContext context = new DefaultCamelContext();
        factory.setContext(context);
        factory.setBeanManager(manager);
        return context;
    }, context -> {
        try {
            factory.afterPropertiesSet();
        } catch (Exception cause) {
            throw new CreationException(cause);
        }
    }), annotated, manager, extension), bean -> "imported Camel context with " + (factory.isImplicitId() ? "implicit " : "") + "id [" + factory.getId() + "] " + "from resource [" + url + "] " + "with qualifiers " + bean.getQualifiers());
}
Also used : CreationException(javax.enterprise.inject.CreationException) Annotation(java.lang.annotation.Annotation) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) IOException(java.io.IOException) CreationException(javax.enterprise.inject.CreationException) JAXBException(javax.xml.bind.JAXBException) HashSet(java.util.HashSet)

Example 4 with DefaultCamelContext

use of org.apache.camel.impl.DefaultCamelContext in project camel by apache.

the class CassandraAggregationRepositoryTest method setUp.

@Before
public void setUp() throws Exception {
    camelContext = new DefaultCamelContext();
    if (canTest()) {
        cluster = CassandraUnitUtils.cassandraCluster();
        session = cluster.connect(CassandraUnitUtils.KEYSPACE);
        aggregationRepository = new CassandraAggregationRepository(session);
        aggregationRepository.start();
    }
}
Also used : DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) Before(org.junit.Before)

Example 5 with DefaultCamelContext

use of org.apache.camel.impl.DefaultCamelContext in project camel by apache.

the class NamedCassandraAggregationRepositoryTest method setUp.

@Before
public void setUp() throws Exception {
    camelContext = new DefaultCamelContext();
    if (canTest()) {
        cluster = CassandraUnitUtils.cassandraCluster();
        session = cluster.connect(CassandraUnitUtils.KEYSPACE);
        aggregationRepository = new NamedCassandraAggregationRepository(session, "ID");
        aggregationRepository.setTable("NAMED_CAMEL_AGGREGATION");
        aggregationRepository.start();
    }
}
Also used : DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) Before(org.junit.Before)

Aggregations

DefaultCamelContext (org.apache.camel.impl.DefaultCamelContext)474 CamelContext (org.apache.camel.CamelContext)206 Test (org.junit.Test)183 DefaultExchange (org.apache.camel.impl.DefaultExchange)128 RouteBuilder (org.apache.camel.builder.RouteBuilder)101 Exchange (org.apache.camel.Exchange)91 Before (org.junit.Before)70 SimpleRegistry (org.apache.camel.impl.SimpleRegistry)61 RegisteredDelivery (org.jsmpp.bean.RegisteredDelivery)39 MockEndpoint (org.apache.camel.component.mock.MockEndpoint)38 ESMClass (org.jsmpp.bean.ESMClass)30 ProducerTemplate (org.apache.camel.ProducerTemplate)27 CountDownLatch (java.util.concurrent.CountDownLatch)15 Endpoint (org.apache.camel.Endpoint)13 FailedToCreateRouteException (org.apache.camel.FailedToCreateRouteException)13 Processor (org.apache.camel.Processor)12 RouteStartupOrder (org.apache.camel.spi.RouteStartupOrder)12 Address (org.jsmpp.bean.Address)11 SubmitMultiResult (org.jsmpp.bean.SubmitMultiResult)11 Date (java.util.Date)10