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