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