001/*
002 * Licensed to the Apache Software Foundation (ASF) under one or more
003 * contributor license agreements.  See the NOTICE file distributed with
004 * this work for additional information regarding copyright ownership.
005 * The ASF licenses this file to You under the Apache License, Version 2.0
006 * (the "License"); you may not use this file except in compliance with
007 * the License.  You may obtain a copy of the License at
008 *
009 *      http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017package org.apache.camel.spring;
018
019import java.util.ArrayList;
020import java.util.List;
021import java.util.Map;
022
023import javax.xml.bind.annotation.XmlAccessType;
024import javax.xml.bind.annotation.XmlAccessorType;
025import javax.xml.bind.annotation.XmlAttribute;
026import javax.xml.bind.annotation.XmlElement;
027import javax.xml.bind.annotation.XmlElements;
028import javax.xml.bind.annotation.XmlRootElement;
029import javax.xml.bind.annotation.XmlTransient;
030
031import org.apache.camel.CamelContext;
032import org.apache.camel.LoggingLevel;
033import org.apache.camel.RoutesBuilder;
034import org.apache.camel.RuntimeCamelException;
035import org.apache.camel.ShutdownRoute;
036import org.apache.camel.ShutdownRunningTask;
037import org.apache.camel.TypeConverterExists;
038import org.apache.camel.builder.RouteBuilder;
039import org.apache.camel.component.properties.PropertiesComponent;
040import org.apache.camel.core.xml.AbstractCamelContextFactoryBean;
041import org.apache.camel.core.xml.AbstractCamelFactoryBean;
042import org.apache.camel.core.xml.CamelJMXAgentDefinition;
043import org.apache.camel.core.xml.CamelPropertyPlaceholderDefinition;
044import org.apache.camel.core.xml.CamelProxyFactoryDefinition;
045import org.apache.camel.core.xml.CamelServiceExporterDefinition;
046import org.apache.camel.core.xml.CamelStreamCachingStrategyDefinition;
047import org.apache.camel.model.ContextScanDefinition;
048import org.apache.camel.model.GlobalOptionsDefinition;
049import org.apache.camel.model.HystrixConfigurationDefinition;
050import org.apache.camel.model.InterceptDefinition;
051import org.apache.camel.model.InterceptFromDefinition;
052import org.apache.camel.model.InterceptSendToEndpointDefinition;
053import org.apache.camel.model.OnCompletionDefinition;
054import org.apache.camel.model.OnExceptionDefinition;
055import org.apache.camel.model.PackageScanDefinition;
056import org.apache.camel.model.Resilience4jConfigurationDefinition;
057import org.apache.camel.model.RestContextRefDefinition;
058import org.apache.camel.model.RouteBuilderDefinition;
059import org.apache.camel.model.RouteContextRefDefinition;
060import org.apache.camel.model.RouteDefinition;
061import org.apache.camel.model.ThreadPoolProfileDefinition;
062import org.apache.camel.model.cloud.ServiceCallConfigurationDefinition;
063import org.apache.camel.model.dataformat.DataFormatsDefinition;
064import org.apache.camel.model.rest.RestConfigurationDefinition;
065import org.apache.camel.model.rest.RestDefinition;
066import org.apache.camel.model.transformer.TransformersDefinition;
067import org.apache.camel.model.validator.ValidatorsDefinition;
068import org.apache.camel.spi.Metadata;
069import org.apache.camel.spi.PackageScanFilter;
070import org.apache.camel.spi.Registry;
071import org.apache.camel.spring.spi.BridgePropertyPlaceholderConfigurer;
072import org.apache.camel.spring.spi.XmlCamelContextConfigurer;
073import org.apache.camel.support.CamelContextHelper;
074import org.apache.camel.util.StopWatch;
075import org.slf4j.Logger;
076import org.slf4j.LoggerFactory;
077import org.springframework.beans.factory.DisposableBean;
078import org.springframework.beans.factory.FactoryBean;
079import org.springframework.beans.factory.InitializingBean;
080import org.springframework.beans.factory.config.BeanPostProcessor;
081import org.springframework.context.ApplicationContext;
082import org.springframework.context.ApplicationContextAware;
083import org.springframework.context.ApplicationListener;
084import org.springframework.context.Lifecycle;
085import org.springframework.context.Phased;
086import org.springframework.context.event.ContextRefreshedEvent;
087import org.springframework.core.Ordered;
088
089import static org.apache.camel.RuntimeCamelException.wrapRuntimeCamelException;
090
091/**
092 * CamelContext using XML configuration.
093 */
094@Metadata(label = "spring,configuration")
095@XmlRootElement(name = "camelContext")
096@XmlAccessorType(XmlAccessType.FIELD)
097public class CamelContextFactoryBean extends AbstractCamelContextFactoryBean<SpringCamelContext>
098        implements FactoryBean<SpringCamelContext>, InitializingBean, DisposableBean, ApplicationContextAware, Lifecycle,
099        Phased, ApplicationListener<ContextRefreshedEvent>, Ordered {
100
101    private static final Logger LOG = LoggerFactory.getLogger(CamelContextFactoryBean.class);
102
103    @XmlAttribute(name = "depends-on") @Metadata(displayName = "Depends On")
104    private String dependsOn;
105    @XmlAttribute
106    private String trace;
107    @XmlAttribute
108    private String tracePattern;
109    @XmlAttribute @Metadata(defaultValue = "true")
110    private String messageHistory;
111    @XmlAttribute @Metadata(defaultValue = "false")
112    private String logMask;
113    @XmlAttribute
114    private String logExhaustedMessageBody;
115    @XmlAttribute
116    private String streamCache;
117    @XmlAttribute
118    private String delayer;
119    @XmlAttribute
120    private String errorHandlerRef;
121    @XmlAttribute @Metadata(defaultValue = "true")
122    private String autoStartup;
123    @XmlAttribute @Metadata(defaultValue = "true")
124    private String shutdownEager;
125    @XmlAttribute @Metadata(displayName = "Use MDC Logging")
126    private String useMDCLogging;
127    @XmlAttribute @Metadata(displayName = "MDC Logging Keys Pattern")
128    private String mdcLoggingKeysPattern;
129    @XmlAttribute
130    private String useDataType;
131    @XmlAttribute
132    private String useBreadcrumb;
133    @XmlAttribute
134    private String allowUseOriginalMessage;
135    @XmlAttribute
136    private String runtimeEndpointRegistryEnabled;
137    @XmlAttribute @Metadata(defaultValue = "#name#")
138    private String managementNamePattern;
139    @XmlAttribute @Metadata(defaultValue = "Camel (#camelId#) thread ##counter# - #name#")
140    private String threadNamePattern;
141    @XmlAttribute @Metadata(defaultValue = "Default")
142    private ShutdownRoute shutdownRoute;
143    @XmlAttribute @Metadata(defaultValue = "CompleteCurrentTaskOnly")
144    private ShutdownRunningTask shutdownRunningTask;
145    @XmlAttribute @Metadata(defaultValue = "true")
146    private Boolean loadTypeConverters;
147    @XmlAttribute
148    private Boolean typeConverterStatisticsEnabled;
149    @XmlAttribute @Metadata(defaultValue = "Override")
150    private TypeConverterExists typeConverterExists;
151    @XmlAttribute @Metadata(defaultValue = "WARN")
152    private LoggingLevel typeConverterExistsLoggingLevel;
153    @XmlElement(name = "globalOptions")
154    private GlobalOptionsDefinition globalOptions;
155    @XmlElement(name = "propertyPlaceholder", type = CamelPropertyPlaceholderDefinition.class)
156    private CamelPropertyPlaceholderDefinition camelPropertyPlaceholder;
157    @XmlElement(name = "package")
158    private String[] packages = {};
159    @XmlElement(name = "packageScan", type = PackageScanDefinition.class)
160    private PackageScanDefinition packageScan;
161    @XmlElement(name = "contextScan", type = ContextScanDefinition.class)
162    private ContextScanDefinition contextScan;
163    @XmlElement(name = "streamCaching", type = CamelStreamCachingStrategyDefinition.class)
164    private CamelStreamCachingStrategyDefinition camelStreamCachingStrategy;
165    @XmlElement(name = "jmxAgent", type = CamelJMXAgentDefinition.class) @Metadata(displayName = "JMX Agent")
166    private CamelJMXAgentDefinition camelJMXAgent;
167    @XmlElements({
168            @XmlElement(name = "template", type = CamelProducerTemplateFactoryBean.class),
169            @XmlElement(name = "fluentTemplate", type = CamelFluentProducerTemplateFactoryBean.class),
170            @XmlElement(name = "consumerTemplate", type = CamelConsumerTemplateFactoryBean.class)})
171    private List<AbstractCamelFactoryBean<?>> beansFactory;
172    @XmlElements({
173        @XmlElement(name = "proxy", type = CamelProxyFactoryDefinition.class),
174        @XmlElement(name = "export", type = CamelServiceExporterDefinition.class),
175        @XmlElement(name = "errorHandler", type = ErrorHandlerDefinition.class) })
176    private List<?> beans;
177    @XmlElement(name = "defaultServiceCallConfiguration")
178    private ServiceCallConfigurationDefinition defaultServiceCallConfiguration;
179    @XmlElement(name = "serviceCallConfiguration", type = ServiceCallConfigurationDefinition.class)
180    private List<ServiceCallConfigurationDefinition> serviceCallConfigurations;
181    @XmlElement(name = "defaultHystrixConfiguration")
182    private HystrixConfigurationDefinition defaultHystrixConfiguration;
183    @XmlElement(name = "hystrixConfiguration", type = HystrixConfigurationDefinition.class)
184    private List<HystrixConfigurationDefinition> hystrixConfigurations;
185    @XmlElement(name = "defaultResilience4jConfiguration")
186    private Resilience4jConfigurationDefinition defaultResilience4jConfiguration;
187    @XmlElement(name = "resilience4jConfiguration", type = Resilience4jConfigurationDefinition.class)
188    private List<Resilience4jConfigurationDefinition> resilience4jConfigurations;
189    @XmlElement(name = "routeBuilder")
190    private List<RouteBuilderDefinition> builderRefs = new ArrayList<>();
191    @XmlElement(name = "routeContextRef")
192    private List<RouteContextRefDefinition> routeRefs = new ArrayList<>();
193    @XmlElement(name = "restContextRef")
194    private List<RestContextRefDefinition> restRefs = new ArrayList<>();
195    @XmlElement(name = "threadPoolProfile")
196    private List<ThreadPoolProfileDefinition> threadPoolProfiles;
197    @XmlElement(name = "threadPool")
198    private List<CamelThreadPoolFactoryBean> threadPools;
199    @XmlElement(name = "endpoint")
200    private List<CamelEndpointFactoryBean> endpoints;
201    @XmlElement(name = "dataFormats")
202    private DataFormatsDefinition dataFormats;
203    @XmlElement(name = "transformers")
204    private TransformersDefinition transformers;
205    @XmlElement(name = "validators")
206    private ValidatorsDefinition validators;
207    @XmlElement(name = "redeliveryPolicyProfile")
208    private List<CamelRedeliveryPolicyFactoryBean> redeliveryPolicies;
209    @XmlElement(name = "onException")
210    private List<OnExceptionDefinition> onExceptions = new ArrayList<>();
211    @XmlElement(name = "onCompletion")
212    private List<OnCompletionDefinition> onCompletions = new ArrayList<>();
213    @XmlElement(name = "intercept")
214    private List<InterceptDefinition> intercepts = new ArrayList<>();
215    @XmlElement(name = "interceptFrom")
216    private List<InterceptFromDefinition> interceptFroms = new ArrayList<>();
217    @XmlElement(name = "interceptSendToEndpoint")
218    private List<InterceptSendToEndpointDefinition> interceptSendToEndpoints = new ArrayList<>();
219    @XmlElement(name = "restConfiguration")
220    private RestConfigurationDefinition restConfiguration;
221    @XmlElement(name = "rest")
222    private List<RestDefinition> rests = new ArrayList<>();
223    @XmlElement(name = "route")
224    private List<RouteDefinition> routes = new ArrayList<>();
225    @XmlTransient
226    private SpringCamelContext context;
227    @XmlTransient
228    private ClassLoader contextClassLoaderOnStart;
229    @XmlTransient
230    private ApplicationContext applicationContext;
231    @XmlTransient
232    private BeanPostProcessor beanPostProcessor;
233    @XmlTransient
234    private boolean implicitId;
235
236    @Override
237    public Class<SpringCamelContext> getObjectType() {
238        return SpringCamelContext.class;
239    }
240
241    @Override
242    protected <S> S getBeanForType(Class<S> clazz) {
243        S bean = null;
244        String[] names = getApplicationContext().getBeanNamesForType(clazz, true, true);
245        if (names.length == 1) {
246            bean = getApplicationContext().getBean(names[0], clazz);
247        }
248        if (bean == null) {
249            ApplicationContext parentContext = getApplicationContext().getParent();
250            if (parentContext != null) {
251                names = parentContext.getBeanNamesForType(clazz, true, true);
252                if (names.length == 1) {
253                    bean = parentContext.getBean(names[0], clazz);
254                }
255            }
256        }
257        return bean;
258    }
259
260    @Override
261    protected void findRouteBuildersByPackageScan(String[] packages, PackageScanFilter filter, List<RoutesBuilder> builders) throws Exception {
262        // add filter to class resolver which then will filter
263        getContext().getPackageScanClassResolver().addFilter(filter);
264
265        PackageScanRouteBuilderFinder finder = new PackageScanRouteBuilderFinder(getContext(), packages, getContextClassLoaderOnStart(),
266                                                                                 getBeanPostProcessor(), getContext().getPackageScanClassResolver());
267        finder.appendBuilders(builders);
268
269        // and remove the filter
270        getContext().getPackageScanClassResolver().removeFilter(filter);
271    }
272
273    @Override
274    protected void findRouteBuildersByContextScan(PackageScanFilter filter, boolean includeNonSingletons, List<RoutesBuilder> builders) throws Exception {
275        ContextScanRouteBuilderFinder finder = new ContextScanRouteBuilderFinder(getContext(), filter, includeNonSingletons);
276        finder.appendBuilders(builders);
277    }
278
279    @Override
280    protected void initBeanPostProcessor(SpringCamelContext context) {
281        if (beanPostProcessor != null) {
282            if (beanPostProcessor instanceof ApplicationContextAware) {
283                ((ApplicationContextAware) beanPostProcessor).setApplicationContext(applicationContext);
284            }
285            if (beanPostProcessor instanceof CamelBeanPostProcessor) {
286                ((CamelBeanPostProcessor) beanPostProcessor).setCamelContext(getContext());
287            }
288            // register the bean post processor on camel context
289            if (beanPostProcessor instanceof org.apache.camel.spi.CamelBeanPostProcessor) {
290                context.setBeanPostProcessor((org.apache.camel.spi.CamelBeanPostProcessor) beanPostProcessor);
291            }
292        }
293    }
294
295    @Override
296    protected void postProcessBeforeInit(RouteBuilder builder) {
297        if (beanPostProcessor != null) {
298            // Inject the annotated resource
299            beanPostProcessor.postProcessBeforeInitialization(builder, builder.toString());
300        }
301    }
302
303    @Override
304    public void afterPropertiesSet() throws Exception {
305        StopWatch watch = new StopWatch();
306
307        super.afterPropertiesSet();
308
309        Boolean shutdownEager = CamelContextHelper.parseBoolean(getContext(), getShutdownEager());
310        if (shutdownEager != null) {
311            LOG.debug("Using shutdownEager: {}", shutdownEager);
312            getContext().setShutdownEager(shutdownEager);
313        }
314
315        LOG.debug("afterPropertiesSet() took {} millis", watch.taken());
316    }
317
318    @Override
319    protected void initCustomRegistry(SpringCamelContext context) {
320        Registry registry = getBeanForType(Registry.class);
321        if (registry != null) {
322            LOG.info("Using custom Registry: {}", registry);
323            context.setRegistry(registry);
324        }
325    }
326
327    @Override
328    protected void initPropertyPlaceholder() throws Exception {
329        super.initPropertyPlaceholder();
330
331        Map<String, BridgePropertyPlaceholderConfigurer> beans = applicationContext.getBeansOfType(BridgePropertyPlaceholderConfigurer.class);
332        if (beans.size() == 1) {
333            // setup properties component that uses this beans
334            BridgePropertyPlaceholderConfigurer configurer = beans.values().iterator().next();
335            String id = beans.keySet().iterator().next();
336            LOG.info("Bridging Camel and Spring property placeholder configurer with id: {}", id);
337
338            // get properties component
339            PropertiesComponent pc = (PropertiesComponent) getContext().getPropertiesComponent();
340            // use the spring system properties mode which has a different value than Camel may have
341            pc.setSystemPropertiesMode(configurer.getSystemPropertiesMode());
342
343            // replace existing resolver with us
344            configurer.setParser(pc.getPropertiesParser());
345            // use the bridge to handle the resolve and parsing
346            pc.setPropertiesParser(configurer);
347            // use the bridge as property source
348            pc.addPropertiesSource(configurer);
349
350        } else if (beans.size() > 1) {
351            LOG.warn("Cannot bridge Camel and Spring property placeholders, as exact only 1 bean of type BridgePropertyPlaceholderConfigurer"
352                    + " must be defined, was {} beans defined.", beans.size());
353        }
354    }
355
356    @Override
357    public void start() {
358        try {
359            setupRoutes();
360        } catch (Exception e) {
361            throw wrapRuntimeCamelException(e);
362        }
363
364        // when the routes are setup we need to start the Camel context
365        context.start();
366    }
367
368    @Override
369    public void stop() {
370        if (context != null) {
371            context.stop();
372        }
373    }
374
375    @Override
376    public boolean isRunning() {
377        return context != null && context.isRunning();
378    }
379
380    @Override
381    public int getPhase() {
382        // the factory starts the context from
383        // onApplicationEvent(ContextRefreshedEvent) so the phase we're
384        // in only influences when the context is to be stopped, and
385        // we want the CamelContext to be first in line to get stopped
386        // if we wanted the phase to be considered while starting, we
387        // would need to implement SmartLifecycle (see
388        // DefaultLifecycleProcessor::startBeans)
389        // we use LOWEST_PRECEDENCE here as this is taken into account
390        // only when stopping and then in reversed order
391        return LOWEST_PRECEDENCE - 1;
392    }
393
394    @Override
395    public int getOrder() {
396        // CamelContextFactoryBean implements Ordered so that it's the 
397        // second to last in ApplicationListener to receive events,
398        // SpringCamelContext should be the last one, this is important
399        // for startup as we want all resources to be ready and all
400        // routes added to the context (see setupRoutes() and
401        // org.apache.camel.spring.boot.RoutesCollector)
402        return LOWEST_PRECEDENCE - 1;
403    }
404
405    @Override
406    public void onApplicationEvent(final ContextRefreshedEvent event) {
407        // start the CamelContext when the Spring ApplicationContext is
408        // done initializing, as the last step in ApplicationContext
409        // being started/refreshed, there could be a race condition with
410        // other ApplicationListeners that react to
411        // ContextRefreshedEvent but this is the best that we can do
412        start();
413    }
414
415    // Properties
416    // -------------------------------------------------------------------------
417
418    public ApplicationContext getApplicationContext() {
419        if (applicationContext == null) {
420            throw new IllegalArgumentException("No applicationContext has been injected!");
421        }
422        return applicationContext;
423    }
424
425    @Override
426    public void setApplicationContext(ApplicationContext applicationContext) {
427        this.applicationContext = applicationContext;
428    }
429
430    public void setBeanPostProcessor(BeanPostProcessor postProcessor) {
431        this.beanPostProcessor = postProcessor;
432    }
433
434    public BeanPostProcessor getBeanPostProcessor() {
435        return beanPostProcessor;
436    }
437
438    // Implementation methods
439    // -------------------------------------------------------------------------
440
441    /**
442     * Create the context
443     */
444    protected SpringCamelContext createContext() {
445        SpringCamelContext ctx = newCamelContext();
446        ctx.setName(getId());
447
448        return ctx;
449    }
450
451    /**
452     * Apply additional configuration to the context
453     */
454    protected void configure(SpringCamelContext ctx) {
455        try {
456            // allow any custom configuration, such as when running in camel-spring-boot
457            if (applicationContext.containsBean("xmlCamelContextConfigurer")) {
458                XmlCamelContextConfigurer configurer = applicationContext.getBean("xmlCamelContextConfigurer", XmlCamelContextConfigurer.class);
459                if (configurer != null) {
460                    configurer.configure(applicationContext, ctx);
461                }
462            }
463        } catch (Exception e) {
464            // error during configuration
465            throw RuntimeCamelException.wrapRuntimeCamelException(e);
466        }
467    }
468
469    protected SpringCamelContext newCamelContext() {
470        return new SpringCamelContext(getApplicationContext());
471    }
472
473    @Override
474    public SpringCamelContext getContext(boolean create) {
475        if (context == null && create) {
476            context = createContext();
477            configure(context);
478            context.init();
479        }
480        return context;
481    }
482
483    public void setContext(SpringCamelContext context) {
484        this.context = context;
485    }
486
487    @Override
488    public List<RouteDefinition> getRoutes() {
489        return routes;
490    }
491
492    /**
493     * Contains the Camel routes
494     */
495    @Override
496    public void setRoutes(List<RouteDefinition> routes) {
497        this.routes = routes;
498    }
499
500    @Override
501    public List<RestDefinition> getRests() {
502        return rests;
503    }
504
505    /**
506     * Contains the rest services defined using the rest-dsl
507     */
508    @Override
509    public void setRests(List<RestDefinition> rests) {
510        this.rests = rests;
511    }
512
513    @Override
514    public RestConfigurationDefinition getRestConfiguration() {
515        return restConfiguration;
516    }
517
518    /**
519     * Configuration for rest-dsl
520     */
521    public void setRestConfiguration(RestConfigurationDefinition restConfiguration) {
522        this.restConfiguration = restConfiguration;
523    }
524
525    @Override
526    public List<CamelEndpointFactoryBean> getEndpoints() {
527        return endpoints;
528    }
529
530    /**
531     * Configuration of endpoints
532     */
533    public void setEndpoints(List<CamelEndpointFactoryBean> endpoints) {
534        this.endpoints = endpoints;
535    }
536
537    @Override
538    public List<CamelRedeliveryPolicyFactoryBean> getRedeliveryPolicies() {
539        return redeliveryPolicies;
540    }
541
542    @Override
543    public List<InterceptDefinition> getIntercepts() {
544        return intercepts;
545    }
546
547    /**
548     * Configuration of interceptors.
549     */
550    public void setIntercepts(List<InterceptDefinition> intercepts) {
551        this.intercepts = intercepts;
552    }
553
554    @Override
555    public List<InterceptFromDefinition> getInterceptFroms() {
556        return interceptFroms;
557    }
558
559    /**
560     * Configuration of interceptors that triggers from the beginning of routes.
561     */
562    public void setInterceptFroms(List<InterceptFromDefinition> interceptFroms) {
563        this.interceptFroms = interceptFroms;
564    }
565
566    @Override
567    public List<InterceptSendToEndpointDefinition> getInterceptSendToEndpoints() {
568        return interceptSendToEndpoints;
569    }
570
571    /**
572     * Configuration of interceptors that triggers sending messages to endpoints.
573     */
574    public void setInterceptSendToEndpoints(List<InterceptSendToEndpointDefinition> interceptSendToEndpoints) {
575        this.interceptSendToEndpoints = interceptSendToEndpoints;
576    }
577
578    @Override
579    public GlobalOptionsDefinition getGlobalOptions() {
580        return globalOptions;
581    }
582
583    /**
584     * Configuration of CamelContext properties such as limit of debug logging
585     * and other general options.
586     */
587    public void setGlobalOptions(GlobalOptionsDefinition globalOptions) {
588        this.globalOptions = globalOptions;
589    }
590
591    @Override
592    public String[] getPackages() {
593        return packages;
594    }
595
596    /**
597     * Sets the package names to be recursively searched for Java classes which
598     * extend {@link org.apache.camel.builder.RouteBuilder} to be auto-wired up to the
599     * {@link CamelContext} as a route. Note that classes are excluded if
600     * they are specifically configured in the spring.xml
601     * <p/>
602     * A more advanced configuration can be done using {@link #setPackageScan(org.apache.camel.model.PackageScanDefinition)}
603     *
604     * @param packages the package names which are recursively searched
605     * @see #setPackageScan(org.apache.camel.model.PackageScanDefinition)
606     */
607    public void setPackages(String[] packages) {
608        this.packages = packages;
609    }
610
611    @Override
612    public PackageScanDefinition getPackageScan() {
613        return packageScan;
614    }
615
616    /**
617     * Sets the package scanning information. Package scanning allows for the
618     * automatic discovery of certain camel classes at runtime for inclusion
619     * e.g. {@link org.apache.camel.builder.RouteBuilder} implementations
620     *
621     * @param packageScan the package scan
622     */
623    @Override
624    public void setPackageScan(PackageScanDefinition packageScan) {
625        this.packageScan = packageScan;
626    }
627
628    @Override
629    public ContextScanDefinition getContextScan() {
630        return contextScan;
631    }
632
633    /**
634     * Sets the context scanning (eg Spring's ApplicationContext) information.
635     * Context scanning allows for the automatic discovery of Camel routes runtime for inclusion
636     * e.g. {@link org.apache.camel.builder.RouteBuilder} implementations
637     *
638     * @param contextScan the context scan
639     */
640    @Override
641    public void setContextScan(ContextScanDefinition contextScan) {
642        this.contextScan = contextScan;
643    }
644
645    @Override
646    public CamelPropertyPlaceholderDefinition getCamelPropertyPlaceholder() {
647        return camelPropertyPlaceholder;
648    }
649
650    /**
651     * Configuration of property placeholder
652     */
653    public void setCamelPropertyPlaceholder(CamelPropertyPlaceholderDefinition camelPropertyPlaceholder) {
654        this.camelPropertyPlaceholder = camelPropertyPlaceholder;
655    }
656
657    @Override
658    public CamelStreamCachingStrategyDefinition getCamelStreamCachingStrategy() {
659        return camelStreamCachingStrategy;
660    }
661
662    /**
663     * Configuration of stream caching.
664     */
665    public void setCamelStreamCachingStrategy(CamelStreamCachingStrategyDefinition camelStreamCachingStrategy) {
666        this.camelStreamCachingStrategy = camelStreamCachingStrategy;
667    }
668
669    /**
670     * Configuration of JMX Agent.
671     */
672    public void setCamelJMXAgent(CamelJMXAgentDefinition agent) {
673        camelJMXAgent = agent;
674    }
675
676    @Override
677    public String getTrace() {
678        return trace;
679    }
680
681    /**
682     * Sets whether tracing is enabled or not.
683     */
684    public void setTrace(String trace) {
685        this.trace = trace;
686    }
687
688    @Override
689    public String getTracePattern() {
690        return tracePattern;
691    }
692
693    /**
694     * Tracing pattern to match which node EIPs to trace.
695     * For example to match all To EIP nodes, use to*.
696     * The pattern matches by node and route id's
697     * Multiple patterns can be separated by comma.
698     */
699    public void setTracePattern(String tracePattern) {
700        this.tracePattern = tracePattern;
701    }
702
703    @Override
704    public String getMessageHistory() {
705        return messageHistory;
706    }
707
708    /**
709     * Sets whether message history is enabled or not.
710     */
711    public void setMessageHistory(String messageHistory) {
712        this.messageHistory = messageHistory;
713    }
714
715    @Override
716    public String getLogMask() {
717        return logMask;
718    }
719
720    /**
721     * Sets whether security mask for Logging is enabled or not.
722     */
723    public void setLogMask(String logMask) {
724        this.logMask = logMask;
725    }
726
727    @Override
728    public String getLogExhaustedMessageBody() {
729        return logExhaustedMessageBody;
730    }
731
732    /**
733     * Sets whether to log exhausted message body with message history.
734     */
735    public void setLogExhaustedMessageBody(String logExhaustedMessageBody) {
736        this.logExhaustedMessageBody = logExhaustedMessageBody;
737    }
738
739    @Override
740    public String getStreamCache() {
741        return streamCache;
742    }
743
744    /**
745     * Sets whether stream caching is enabled or not.
746     */
747    public void setStreamCache(String streamCache) {
748        this.streamCache = streamCache;
749    }
750
751    @Override
752    public String getDelayer() {
753        return delayer;
754    }
755
756    /**
757     * Sets a delay value in millis that a message is delayed at every step it takes in the route path,
758     * slowing the process down to better observe what is occurring
759     */
760    public void setDelayer(String delayer) {
761        this.delayer = delayer;
762    }
763
764    @Override
765    public String getAutoStartup() {
766        return autoStartup;
767    }
768
769    /**
770     * Sets whether the object should automatically start when Camel starts.
771     * <p/>
772     * <b>Important:</b> Currently only routes can be disabled, as {@link CamelContext}s are always started.
773     * <br/>
774     * <b>Note:</b> When setting auto startup <tt>false</tt> on {@link CamelContext} then that takes precedence
775     * and <i>no</i> routes is started. You would need to start {@link CamelContext} explicit using
776     * the {@link org.apache.camel.CamelContext#start()} method, to start the context, and then
777     * you would need to start the routes manually using {@link org.apache.camel.spi.RouteController#startRoute(String)}.
778     */
779    public void setAutoStartup(String autoStartup) {
780        this.autoStartup = autoStartup;
781    }
782
783    public String getShutdownEager() {
784        return shutdownEager;
785    }
786
787    /**
788     * Whether to shutdown CamelContext eager when Spring is shutting down.
789     * This ensure a cleaner shutdown of Camel, as dependent bean's are not shutdown at this moment.
790     * The bean's will then be shutdown after camelContext.
791     */
792    public void setShutdownEager(String shutdownEager) {
793        this.shutdownEager = shutdownEager;
794    }
795
796    @Override
797    public String getUseMDCLogging() {
798        return useMDCLogging;
799    }
800
801    /**
802     * Set whether <a href="http://www.slf4j.org/api/org/slf4j/MDC.html">MDC</a> is enabled.
803     */
804    public void setUseMDCLogging(String useMDCLogging) {
805        this.useMDCLogging = useMDCLogging;
806    }
807
808    public String getMDCLoggingKeysPattern() {
809        return mdcLoggingKeysPattern;
810    }
811
812    /**
813     * Sets the pattern used for determine which custom MDC keys to propagate during message routing when
814     * the routing engine continues routing asynchronously for the given message. Setting this pattern to * will
815     * propagate all custom keys. Or setting the pattern to foo*,bar* will propagate any keys starting with
816     * either foo or bar.
817     * Notice that a set of standard Camel MDC keys are always propagated which starts with camel. as key name.
818     *
819     * The match rules are applied in this order (case insensitive):
820     *
821     * 1. exact match, returns true
822     * 2. wildcard match (pattern ends with a * and the name starts with the pattern), returns true
823     * 3. regular expression match, returns true
824     * 4. otherwise returns false
825     */
826    public void setMDCLoggingKeysPattern(String mdcLoggingKeysPattern) {
827        this.mdcLoggingKeysPattern = mdcLoggingKeysPattern;
828    }
829
830    @Override
831    public String getUseDataType() {
832        return useDataType;
833    }
834
835    /**
836     * Whether to enable using data type on Camel messages.
837     * <p/>
838     * Data type are automatic turned on if:
839     * <ul>
840     *   <li>one ore more routes has been explicit configured with input and output types</li>
841     *   <li>when using rest-dsl with binding turned on</li>
842     * </ul>
843     * Otherwise data type is default off.
844     */
845    public void setUseDataType(String useDataType) {
846        this.useDataType = useDataType;
847    }
848
849    @Override
850    public String getUseBreadcrumb() {
851        return useBreadcrumb;
852    }
853
854    /**
855     * Set whether breadcrumb is enabled.
856     */
857    public void setUseBreadcrumb(String useBreadcrumb) {
858        this.useBreadcrumb = useBreadcrumb;
859    }
860
861    @Override
862    public String getAllowUseOriginalMessage() {
863        return allowUseOriginalMessage;
864    }
865
866    /**
867     * Sets whether to allow access to the original message from Camel's error handler,
868     * or from {@link org.apache.camel.spi.UnitOfWork#getOriginalInMessage()}.
869     * <p/>
870     * Turning this off can optimize performance, as defensive copy of the original message is not needed.
871     */
872    public void setAllowUseOriginalMessage(String allowUseOriginalMessage) {
873        this.allowUseOriginalMessage = allowUseOriginalMessage;
874    }
875
876    @Override
877    public String getRuntimeEndpointRegistryEnabled() {
878        return runtimeEndpointRegistryEnabled;
879    }
880
881    /**
882     * Sets whether {@link org.apache.camel.spi.RuntimeEndpointRegistry} is enabled.
883     */
884    public void setRuntimeEndpointRegistryEnabled(String runtimeEndpointRegistryEnabled) {
885        this.runtimeEndpointRegistryEnabled = runtimeEndpointRegistryEnabled;
886    }
887
888    @Override
889    public String getManagementNamePattern() {
890        return managementNamePattern;
891    }
892
893    /**
894     * The naming pattern for creating the CamelContext management name.
895     */
896    public void setManagementNamePattern(String managementNamePattern) {
897        this.managementNamePattern = managementNamePattern;
898    }
899
900    @Override
901    public String getThreadNamePattern() {
902        return threadNamePattern;
903    }
904
905    /**
906     * Sets the thread name pattern used for creating the full thread name.
907     * <p/>
908     * The default pattern is: <tt>Camel (#camelId#) thread ##counter# - #name#</tt>
909     * <p/>
910     * Where <tt>#camelId#</tt> is the name of the {@link org.apache.camel.CamelContext}
911     * <br/>and <tt>#counter#</tt> is a unique incrementing counter.
912     * <br/>and <tt>#name#</tt> is the regular thread name.
913     * <br/>You can also use <tt>#longName#</tt> is the long thread name which can includes endpoint parameters etc.
914     */
915    public void setThreadNamePattern(String threadNamePattern) {
916        this.threadNamePattern = threadNamePattern;
917    }
918
919    @Override
920    public Boolean getLoadTypeConverters() {
921        return loadTypeConverters;
922    }
923
924    /**
925     * Sets whether to load custom type converters by scanning classpath.
926     * This can be turned off if you are only using Camel components
927     * that does not provide type converters which is needed at runtime.
928     * In such situations setting this option to false, can speedup starting
929     * Camel.
930     *
931     * @param loadTypeConverters whether to load custom type converters.
932     */
933    public void setLoadTypeConverters(Boolean loadTypeConverters) {
934        this.loadTypeConverters = loadTypeConverters;
935    }
936
937    @Override
938    public Boolean getTypeConverterStatisticsEnabled() {
939        return typeConverterStatisticsEnabled;
940    }
941
942    /**
943     * Sets whether or not type converter statistics is enabled.
944     * <p/>
945     * By default the type converter utilization statistics is disabled.
946     * <b>Notice:</b> If enabled then there is a slight performance impact under very heavy load.
947     * <p/>
948     * You can enable/disable the statistics at runtime using the
949     * {@link org.apache.camel.spi.TypeConverterRegistry#getStatistics()#setTypeConverterStatisticsEnabled(Boolean)} method,
950     * or from JMX on the {@link org.apache.camel.api.management.mbean.ManagedTypeConverterRegistryMBean} mbean.
951     */
952    public void setTypeConverterStatisticsEnabled(Boolean typeConverterStatisticsEnabled) {
953        this.typeConverterStatisticsEnabled = typeConverterStatisticsEnabled;
954    }
955
956    @Override
957    public TypeConverterExists getTypeConverterExists() {
958        return typeConverterExists;
959    }
960
961    /**
962     * What should happen when attempting to add a duplicate type converter.
963     * <p/>
964     * The default behavior is to override the existing.
965     */
966    public void setTypeConverterExists(TypeConverterExists typeConverterExists) {
967        this.typeConverterExists = typeConverterExists;
968    }
969
970    @Override
971    public LoggingLevel getTypeConverterExistsLoggingLevel() {
972        return typeConverterExistsLoggingLevel;
973    }
974
975    /**
976     * The logging level to use when logging that a type converter already exists when attempting to add a duplicate type converter.
977     * <p/>
978     * The default logging level is <tt>WARN</tt>
979     */
980    public void setTypeConverterExistsLoggingLevel(LoggingLevel typeConverterExistsLoggingLevel) {
981        this.typeConverterExistsLoggingLevel = typeConverterExistsLoggingLevel;
982    }
983
984    @Override
985    public CamelJMXAgentDefinition getCamelJMXAgent() {
986        return camelJMXAgent;
987    }
988
989    @Override
990    public List<RouteBuilderDefinition> getBuilderRefs() {
991        return builderRefs;
992    }
993
994    /**
995     * Refers to Java {@link RouteBuilder} instances to include as routes in this CamelContext.
996     */
997    public void setBuilderRefs(List<RouteBuilderDefinition> builderRefs) {
998        this.builderRefs = builderRefs;
999    }
1000
1001    @Override
1002    public List<RouteContextRefDefinition> getRouteRefs() {
1003        return routeRefs;
1004    }
1005
1006    /**
1007     * Refers to XML routes to include as routes in this CamelContext.
1008     */
1009    public void setRouteRefs(List<RouteContextRefDefinition> routeRefs) {
1010        this.routeRefs = routeRefs;
1011    }
1012
1013    @Override
1014    public List<RestContextRefDefinition> getRestRefs() {
1015        return restRefs;
1016    }
1017
1018    /**
1019     * Refers to XML rest-dsl to include as REST services in this CamelContext.
1020     */
1021    public void setRestRefs(List<RestContextRefDefinition> restRefs) {
1022        this.restRefs = restRefs;
1023    }
1024
1025    @Override
1026    public String getErrorHandlerRef() {
1027        return errorHandlerRef;
1028    }
1029
1030    /**
1031     * Sets the name of the error handler object used to default the error handling strategy
1032     */
1033    public void setErrorHandlerRef(String errorHandlerRef) {
1034        this.errorHandlerRef = errorHandlerRef;
1035    }
1036
1037    /**
1038     * Configuration of data formats.
1039     */
1040    public void setDataFormats(DataFormatsDefinition dataFormats) {
1041        this.dataFormats = dataFormats;
1042    }
1043
1044    @Override
1045    public DataFormatsDefinition getDataFormats() {
1046        return dataFormats;
1047    }
1048
1049    /**
1050     * Configuration of transformers.
1051     */
1052    public void setTransformers(TransformersDefinition transformers) {
1053        this.transformers = transformers;
1054    }
1055
1056    @Override
1057    public TransformersDefinition getTransformers() {
1058        return transformers;
1059    }
1060
1061    /**
1062     * Configuration of validators.
1063     */
1064    public void setValidators(ValidatorsDefinition validators) {
1065        this.validators = validators;
1066    }
1067
1068    @Override
1069    public ValidatorsDefinition getValidators() {
1070        return validators;
1071    }
1072
1073    /**
1074     * Configuration of redelivery settings.
1075     */
1076    public void setRedeliveryPolicies(List<CamelRedeliveryPolicyFactoryBean> redeliveryPolicies) {
1077        this.redeliveryPolicies = redeliveryPolicies;
1078    }
1079
1080    @Override
1081    public List<AbstractCamelFactoryBean<?>> getBeansFactory() {
1082        return beansFactory;
1083    }
1084
1085    /**
1086     * Miscellaneous configurations
1087     */
1088    public void setBeansFactory(List<AbstractCamelFactoryBean<?>> beansFactory) {
1089        this.beansFactory = beansFactory;
1090    }
1091
1092    @Override
1093    public List<?> getBeans() {
1094        return beans;
1095    }
1096
1097    /**
1098     * Miscellaneous configurations
1099     */
1100    public void setBeans(List<?> beans) {
1101        this.beans = beans;
1102    }
1103
1104    @Override
1105    public ServiceCallConfigurationDefinition getDefaultServiceCallConfiguration() {
1106        return defaultServiceCallConfiguration;
1107    }
1108
1109    /**
1110     * ServiceCall EIP default configuration
1111     */
1112    public void setDefaultServiceCallConfiguration(ServiceCallConfigurationDefinition defaultServiceCallConfiguration) {
1113        this.defaultServiceCallConfiguration = defaultServiceCallConfiguration;
1114    }
1115
1116    @Override
1117    public List<ServiceCallConfigurationDefinition> getServiceCallConfigurations() {
1118        return serviceCallConfigurations;
1119    }
1120
1121    /**
1122     * ServiceCall EIP configurations
1123     */
1124    public void setServiceCallConfigurations(List<ServiceCallConfigurationDefinition> serviceCallConfigurations) {
1125        this.serviceCallConfigurations = serviceCallConfigurations;
1126    }
1127
1128    @Override
1129    public List<HystrixConfigurationDefinition> getHystrixConfigurations() {
1130        return hystrixConfigurations;
1131    }
1132
1133    @Override
1134    public HystrixConfigurationDefinition getDefaultHystrixConfiguration() {
1135        return defaultHystrixConfiguration;
1136    }
1137
1138    /**
1139     * Hystrix EIP default configuration
1140     */
1141    public void setDefaultHystrixConfiguration(HystrixConfigurationDefinition defaultHystrixConfiguration) {
1142        this.defaultHystrixConfiguration = defaultHystrixConfiguration;
1143    }
1144
1145    /**
1146     * Hystrix Circuit Breaker EIP configurations
1147     */
1148    public void setHystrixConfigurations(List<HystrixConfigurationDefinition> hystrixConfigurations) {
1149        this.hystrixConfigurations = hystrixConfigurations;
1150    }
1151
1152    @Override
1153    public Resilience4jConfigurationDefinition getDefaultResilience4jConfiguration() {
1154        return defaultResilience4jConfiguration;
1155    }
1156
1157    /**
1158     * Resilience4j EIP default configuration
1159     */
1160    public void setDefaultResilience4jConfiguration(Resilience4jConfigurationDefinition defaultResilience4jConfiguration) {
1161        this.defaultResilience4jConfiguration = defaultResilience4jConfiguration;
1162    }
1163
1164    @Override
1165    public List<Resilience4jConfigurationDefinition> getResilience4jConfigurations() {
1166        return resilience4jConfigurations;
1167    }
1168
1169    /**
1170     * Resilience4j Circuit Breaker EIP configurations
1171     */
1172    public void setResilience4jConfigurations(List<Resilience4jConfigurationDefinition> resilience4jConfigurations) {
1173        this.resilience4jConfigurations = resilience4jConfigurations;
1174    }
1175
1176    /**
1177     * Configuration of error handlers that triggers on exceptions thrown.
1178     */
1179    public void setOnExceptions(List<OnExceptionDefinition> onExceptions) {
1180        this.onExceptions = onExceptions;
1181    }
1182
1183    @Override
1184    public List<OnExceptionDefinition> getOnExceptions() {
1185        return onExceptions;
1186    }
1187
1188    @Override
1189    public List<OnCompletionDefinition> getOnCompletions() {
1190        return onCompletions;
1191    }
1192
1193    /**
1194     * Configuration of sub routes to run at the completion of routing.
1195     */
1196    public void setOnCompletions(List<OnCompletionDefinition> onCompletions) {
1197        this.onCompletions = onCompletions;
1198    }
1199
1200    @Override
1201    public ShutdownRoute getShutdownRoute() {
1202        return shutdownRoute;
1203    }
1204
1205    /**
1206     * Sets the ShutdownRoute option for routes.
1207     */
1208    public void setShutdownRoute(ShutdownRoute shutdownRoute) {
1209        this.shutdownRoute = shutdownRoute;
1210    }
1211
1212    @Override
1213    public ShutdownRunningTask getShutdownRunningTask() {
1214        return shutdownRunningTask;
1215    }
1216
1217    /**
1218     * Sets the ShutdownRunningTask option to use when shutting down a route.
1219     */
1220    public void setShutdownRunningTask(ShutdownRunningTask shutdownRunningTask) {
1221        this.shutdownRunningTask = shutdownRunningTask;
1222    }
1223
1224    @Override
1225    public List<ThreadPoolProfileDefinition> getThreadPoolProfiles() {
1226        return threadPoolProfiles;
1227    }
1228
1229    /**
1230     * Configuration of thread pool profiles.
1231     */
1232    public void setThreadPoolProfiles(List<ThreadPoolProfileDefinition> threadPoolProfiles) {
1233        this.threadPoolProfiles = threadPoolProfiles;
1234    }
1235
1236    public List<CamelThreadPoolFactoryBean> getThreadPools() {
1237        return threadPools;
1238    }
1239
1240    /**
1241     * Configuration of thread pool
1242     */
1243    public void setThreadPools(List<CamelThreadPoolFactoryBean> threadPools) {
1244        this.threadPools = threadPools;
1245    }
1246
1247    @Override
1248    public String getDependsOn() {
1249        return dependsOn;
1250    }
1251
1252    /**
1253     * List of other bean id's this CamelContext depends up. Multiple bean id's can be separated by comma.
1254     */
1255    public void setDependsOn(String dependsOn) {
1256        this.dependsOn = dependsOn;
1257    }
1258    
1259    public boolean isImplicitId() {
1260        return implicitId;
1261    }
1262    
1263    public void setImplicitId(boolean flag) {
1264        implicitId = flag;
1265    }
1266}