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        return ctx;
453    }
454
455    /**
456     * Apply additional configuration to the context
457     */
458    protected void configure(SpringCamelContext ctx) {
459        try {
460            // allow any custom configuration, such as when running in camel-spring-boot
461            if (applicationContext.containsBean("xmlCamelContextConfigurer")) {
462                XmlCamelContextConfigurer configurer = applicationContext.getBean("xmlCamelContextConfigurer", XmlCamelContextConfigurer.class);
463                if (configurer != null) {
464                    configurer.configure(applicationContext, ctx);
465                }
466            }
467        } catch (Exception e) {
468            // error during configuration
469            throw ObjectHelper.wrapRuntimeCamelException(e);
470        }
471    }
472
473    protected SpringCamelContext newCamelContext() {
474        return new SpringCamelContext(getApplicationContext());
475    }
476
477    public SpringCamelContext getContext(boolean create) {
478        if (context == null && create) {
479            context = createContext();
480            configure(context);
481        }
482        return context;
483    }
484
485    public void setContext(SpringCamelContext context) {
486        this.context = context;
487    }
488
489    public List<RouteDefinition> getRoutes() {
490        return routes;
491    }
492
493    /**
494     * Contains the Camel routes
495     */
496    public void setRoutes(List<RouteDefinition> routes) {
497        this.routes = routes;
498    }
499
500    public List<RestDefinition> getRests() {
501        return rests;
502    }
503
504    /**
505     * Contains the rest services defined using the rest-dsl
506     */
507    public void setRests(List<RestDefinition> rests) {
508        this.rests = rests;
509    }
510
511    public RestConfigurationDefinition getRestConfiguration() {
512        return restConfiguration;
513    }
514
515    /**
516     * Configuration for rest-dsl
517     */
518    public void setRestConfiguration(RestConfigurationDefinition restConfiguration) {
519        this.restConfiguration = restConfiguration;
520    }
521
522    public List<CamelEndpointFactoryBean> getEndpoints() {
523        return endpoints;
524    }
525
526    /**
527     * Configuration of endpoints
528     */
529    public void setEndpoints(List<CamelEndpointFactoryBean> endpoints) {
530        this.endpoints = endpoints;
531    }
532
533    public List<CamelRedeliveryPolicyFactoryBean> getRedeliveryPolicies() {
534        return redeliveryPolicies;
535    }
536
537    public List<InterceptDefinition> getIntercepts() {
538        return intercepts;
539    }
540
541    /**
542     * Configuration of interceptors.
543     */
544    public void setIntercepts(List<InterceptDefinition> intercepts) {
545        this.intercepts = intercepts;
546    }
547
548    public List<InterceptFromDefinition> getInterceptFroms() {
549        return interceptFroms;
550    }
551
552    /**
553     * Configuration of interceptors that triggers from the beginning of routes.
554     */
555    public void setInterceptFroms(List<InterceptFromDefinition> interceptFroms) {
556        this.interceptFroms = interceptFroms;
557    }
558
559    public List<InterceptSendToEndpointDefinition> getInterceptSendToEndpoints() {
560        return interceptSendToEndpoints;
561    }
562
563    /**
564     * Configuration of interceptors that triggers sending messages to endpoints.
565     */
566    public void setInterceptSendToEndpoints(List<InterceptSendToEndpointDefinition> interceptSendToEndpoints) {
567        this.interceptSendToEndpoints = interceptSendToEndpoints;
568    }
569
570    @Deprecated
571    public PropertiesDefinition getProperties() {
572        return properties;
573    }
574
575    @Override
576    public GlobalOptionsDefinition getGlobalOptions() {
577        return globalOptions;
578    }
579
580    /**
581     * Configuration of CamelContext properties such as limit of debug logging
582     * and other general options.
583     * 
584     * @deprecated Use {@link GlobalOptionsDefinition} instead.
585     */
586    @Deprecated
587    public void setProperties(PropertiesDefinition properties) {
588        this.properties = properties;
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    public String[] getPackages() {
600        return packages;
601    }
602
603    /**
604     * Sets the package names to be recursively searched for Java classes which
605     * extend {@link org.apache.camel.builder.RouteBuilder} to be auto-wired up to the
606     * {@link CamelContext} as a route. Note that classes are excluded if
607     * they are specifically configured in the spring.xml
608     * <p/>
609     * A more advanced configuration can be done using {@link #setPackageScan(org.apache.camel.model.PackageScanDefinition)}
610     *
611     * @param packages the package names which are recursively searched
612     * @see #setPackageScan(org.apache.camel.model.PackageScanDefinition)
613     */
614    public void setPackages(String[] packages) {
615        this.packages = packages;
616    }
617
618    public PackageScanDefinition getPackageScan() {
619        return packageScan;
620    }
621
622    /**
623     * Sets the package scanning information. Package scanning allows for the
624     * automatic discovery of certain camel classes at runtime for inclusion
625     * e.g. {@link org.apache.camel.builder.RouteBuilder} implementations
626     *
627     * @param packageScan the package scan
628     */
629    public void setPackageScan(PackageScanDefinition packageScan) {
630        this.packageScan = packageScan;
631    }
632
633    public ContextScanDefinition getContextScan() {
634        return contextScan;
635    }
636
637    /**
638     * Sets the context scanning (eg Spring's ApplicationContext) information.
639     * Context scanning allows for the automatic discovery of Camel routes runtime for inclusion
640     * e.g. {@link org.apache.camel.builder.RouteBuilder} implementations
641     *
642     * @param contextScan the context scan
643     */
644    public void setContextScan(ContextScanDefinition contextScan) {
645        this.contextScan = contextScan;
646    }
647
648    public CamelPropertyPlaceholderDefinition getCamelPropertyPlaceholder() {
649        return camelPropertyPlaceholder;
650    }
651
652    /**
653     * Configuration of property placeholder
654     */
655    public void setCamelPropertyPlaceholder(CamelPropertyPlaceholderDefinition camelPropertyPlaceholder) {
656        this.camelPropertyPlaceholder = camelPropertyPlaceholder;
657    }
658
659    public CamelStreamCachingStrategyDefinition getCamelStreamCachingStrategy() {
660        return camelStreamCachingStrategy;
661    }
662
663    /**
664     * Configuration of stream caching.
665     */
666    public void setCamelStreamCachingStrategy(CamelStreamCachingStrategyDefinition camelStreamCachingStrategy) {
667        this.camelStreamCachingStrategy = camelStreamCachingStrategy;
668    }
669
670    /**
671     * Configuration of JMX.
672     */
673    public void setCamelJMXAgent(CamelJMXAgentDefinition agent) {
674        camelJMXAgent = agent;
675    }
676
677    public String getTrace() {
678        return trace;
679    }
680
681    /**
682     * Sets whether tracing is enabled or not.
683     */
684    public void setTrace(String trace) {
685        this.trace = trace;
686    }
687
688    public String getMessageHistory() {
689        return messageHistory;
690    }
691
692    /**
693     * Sets whether message history is enabled or not.
694     */
695    public void setMessageHistory(String messageHistory) {
696        this.messageHistory = messageHistory;
697    }
698
699    public String getLogMask() {
700        return logMask;
701    }
702
703    /**
704     * Sets whether security mask for Logging is enabled or not.
705     */
706    public void setLogMask(String logMask) {
707        this.logMask = logMask;
708    }
709
710    public String getLogExhaustedMessageBody() {
711        return logExhaustedMessageBody;
712    }
713
714    /**
715     * Sets whether to log exhausted message body with message history.
716     */
717    public void setLogExhaustedMessageBody(String logExhaustedMessageBody) {
718        this.logExhaustedMessageBody = logExhaustedMessageBody;
719    }
720
721    public String getStreamCache() {
722        return streamCache;
723    }
724
725    /**
726     * Sets whether stream caching is enabled or not.
727     */
728    public void setStreamCache(String streamCache) {
729        this.streamCache = streamCache;
730    }
731
732    public String getDelayer() {
733        return delayer;
734    }
735
736    /**
737     * Sets a delay value in millis that a message is delayed at every step it takes in the route path,
738     * slowing the process down to better observe what is occurring
739     */
740    public void setDelayer(String delayer) {
741        this.delayer = delayer;
742    }
743
744    public String getHandleFault() {
745        return handleFault;
746    }
747
748    /**
749     * Sets whether fault handling is enabled or not (default is disabled).
750     */
751    public void setHandleFault(String handleFault) {
752        this.handleFault = handleFault;
753    }
754
755    public String getAutoStartup() {
756        return autoStartup;
757    }
758
759    /**
760     * Sets whether the object should automatically start when Camel starts.
761     * <p/>
762     * <b>Important:</b> Currently only routes can be disabled, as {@link CamelContext}s are always started.
763     * <br/>
764     * <b>Note:</b> When setting auto startup <tt>false</tt> on {@link CamelContext} then that takes precedence
765     * and <i>no</i> routes is started. You would need to start {@link CamelContext} explicit using
766     * the {@link org.apache.camel.CamelContext#start()} method, to start the context, and then
767     * you would need to start the routes manually using {@link CamelContext#startRoute(String)}.
768     */
769    public void setAutoStartup(String autoStartup) {
770        this.autoStartup = autoStartup;
771    }
772
773    public String getShutdownEager() {
774        return shutdownEager;
775    }
776
777    /**
778     * Whether to shutdown CamelContext eager when Spring is shutting down.
779     * This ensure a cleaner shutdown of Camel, as dependent bean's are not shutdown at this moment.
780     * The bean's will then be shutdown after camelContext.
781     */
782    public void setShutdownEager(String shutdownEager) {
783        this.shutdownEager = shutdownEager;
784    }
785
786    public String getRegisterEndpointIdsFromRoute() {
787        return registerEndpointIdsFromRoute;
788    }
789
790    /**
791     * Sets whether to register endpoints that has id attribute assigned in the Spring registry.
792     * <p/>
793     * This mode is by default false, but can be turned on for backwards compatibility.
794     */
795    public void setRegisterEndpointIdsFromRoute(String registerEndpointIdsFromRoute) {
796        this.registerEndpointIdsFromRoute = registerEndpointIdsFromRoute;
797    }
798
799    public String getUseMDCLogging() {
800        return useMDCLogging;
801    }
802
803    /**
804     * Set whether <a href="http://www.slf4j.org/api/org/slf4j/MDC.html">MDC</a> is enabled.
805     */
806    public void setUseMDCLogging(String useMDCLogging) {
807        this.useMDCLogging = useMDCLogging;
808    }
809
810    public String getUseDataType() {
811        return useDataType;
812    }
813
814    /**
815     * Whether to enable using data type on Camel messages.
816     * <p/>
817     * Data type are automatic turned on if:
818     * <ul>
819     *   <li>one ore more routes has been explicit configured with input and output types</li>
820     *   <li>when using rest-dsl with binding turned on</li>
821     * </ul>
822     * Otherwise data type is default off.
823     */
824    public void setUseDataType(String useDataType) {
825        this.useDataType = useDataType;
826    }
827
828    public String getUseBreadcrumb() {
829        return useBreadcrumb;
830    }
831
832    /**
833     * Set whether breadcrumb is enabled.
834     */
835    public void setUseBreadcrumb(String useBreadcrumb) {
836        this.useBreadcrumb = useBreadcrumb;
837    }
838
839    public String getAllowUseOriginalMessage() {
840        return allowUseOriginalMessage;
841    }
842
843    /**
844     * Sets whether to allow access to the original message from Camel's error handler,
845     * or from {@link org.apache.camel.spi.UnitOfWork#getOriginalInMessage()}.
846     * <p/>
847     * Turning this off can optimize performance, as defensive copy of the original message is not needed.
848     */
849    public void setAllowUseOriginalMessage(String allowUseOriginalMessage) {
850        this.allowUseOriginalMessage = allowUseOriginalMessage;
851    }
852
853    public String getRuntimeEndpointRegistryEnabled() {
854        return runtimeEndpointRegistryEnabled;
855    }
856
857    /**
858     * Sets whether {@link org.apache.camel.spi.RuntimeEndpointRegistry} is enabled.
859     */
860    public void setRuntimeEndpointRegistryEnabled(String runtimeEndpointRegistryEnabled) {
861        this.runtimeEndpointRegistryEnabled = runtimeEndpointRegistryEnabled;
862    }
863
864    public String getManagementNamePattern() {
865        return managementNamePattern;
866    }
867
868    /**
869     * The naming pattern for creating the CamelContext management name.
870     */
871    public void setManagementNamePattern(String managementNamePattern) {
872        this.managementNamePattern = managementNamePattern;
873    }
874
875    public String getThreadNamePattern() {
876        return threadNamePattern;
877    }
878
879    /**
880     * Sets the thread name pattern used for creating the full thread name.
881     * <p/>
882     * The default pattern is: <tt>Camel (#camelId#) thread ##counter# - #name#</tt>
883     * <p/>
884     * Where <tt>#camelId#</tt> is the name of the {@link org.apache.camel.CamelContext}
885     * <br/>and <tt>#counter#</tt> is a unique incrementing counter.
886     * <br/>and <tt>#name#</tt> is the regular thread name.
887     * <br/>You can also use <tt>#longName#</tt> is the long thread name which can includes endpoint parameters etc.
888     */
889    public void setThreadNamePattern(String threadNamePattern) {
890        this.threadNamePattern = threadNamePattern;
891    }
892
893    @Deprecated
894    public Boolean getLazyLoadTypeConverters() {
895        return lazyLoadTypeConverters;
896    }
897
898    /**
899     * Sets whether type converters should be loaded lazy
900     */
901    @Deprecated
902    public void setLazyLoadTypeConverters(Boolean lazyLoadTypeConverters) {
903        this.lazyLoadTypeConverters = lazyLoadTypeConverters;
904    }
905
906    @Override
907    public Boolean getLoadTypeConverters() {
908        return loadTypeConverters;
909    }
910
911    /**
912     * Sets whether to load custom type converters by scanning classpath.
913     * This can be turned off if you are only using Camel components
914     * that does not provide type converters which is needed at runtime.
915     * In such situations setting this option to false, can speedup starting
916     * Camel.
917     *
918     * @param loadTypeConverters whether to load custom type converters.
919     */
920    public void setLoadTypeConverters(Boolean loadTypeConverters) {
921        this.loadTypeConverters = loadTypeConverters;
922    }
923
924    public Boolean getTypeConverterStatisticsEnabled() {
925        return typeConverterStatisticsEnabled;
926    }
927
928    /**
929     * Sets whether or not type converter statistics is enabled.
930     * <p/>
931     * By default the type converter utilization statistics is disabled.
932     * <b>Notice:</b> If enabled then there is a slight performance impact under very heavy load.
933     * <p/>
934     * You can enable/disable the statistics at runtime using the
935     * {@link org.apache.camel.spi.TypeConverterRegistry#getStatistics()#setTypeConverterStatisticsEnabled(Boolean)} method,
936     * or from JMX on the {@link org.apache.camel.api.management.mbean.ManagedTypeConverterRegistryMBean} mbean.
937     */
938    public void setTypeConverterStatisticsEnabled(Boolean typeConverterStatisticsEnabled) {
939        this.typeConverterStatisticsEnabled = typeConverterStatisticsEnabled;
940    }
941
942    public TypeConverterExists getTypeConverterExists() {
943        return typeConverterExists;
944    }
945
946    /**
947     * What should happen when attempting to add a duplicate type converter.
948     * <p/>
949     * The default behavior is to override the existing.
950     */
951    public void setTypeConverterExists(TypeConverterExists typeConverterExists) {
952        this.typeConverterExists = typeConverterExists;
953    }
954
955    public LoggingLevel getTypeConverterExistsLoggingLevel() {
956        return typeConverterExistsLoggingLevel;
957    }
958
959    /**
960     * The logging level to use when logging that a type converter already exists when attempting to add a duplicate type converter.
961     * <p/>
962     * The default logging level is <tt>WARN</tt>
963     */
964    public void setTypeConverterExistsLoggingLevel(LoggingLevel typeConverterExistsLoggingLevel) {
965        this.typeConverterExistsLoggingLevel = typeConverterExistsLoggingLevel;
966    }
967
968    public CamelJMXAgentDefinition getCamelJMXAgent() {
969        return camelJMXAgent;
970    }
971
972    public List<RouteBuilderDefinition> getBuilderRefs() {
973        return builderRefs;
974    }
975
976    /**
977     * Refers to Java {@link RouteBuilder} instances to include as routes in this CamelContext.
978     */
979    public void setBuilderRefs(List<RouteBuilderDefinition> builderRefs) {
980        this.builderRefs = builderRefs;
981    }
982
983    public List<RouteContextRefDefinition> getRouteRefs() {
984        return routeRefs;
985    }
986
987    /**
988     * Refers to XML routes to include as routes in this CamelContext.
989     */
990    public void setRouteRefs(List<RouteContextRefDefinition> routeRefs) {
991        this.routeRefs = routeRefs;
992    }
993
994    public List<RestContextRefDefinition> getRestRefs() {
995        return restRefs;
996    }
997
998    /**
999     * Refers to XML rest-dsl to include as REST services in this CamelContext.
1000     */
1001    public void setRestRefs(List<RestContextRefDefinition> restRefs) {
1002        this.restRefs = restRefs;
1003    }
1004
1005    public String getErrorHandlerRef() {
1006        return errorHandlerRef;
1007    }
1008
1009    /**
1010     * Sets the name of the error handler object used to default the error handling strategy
1011     */
1012    public void setErrorHandlerRef(String errorHandlerRef) {
1013        this.errorHandlerRef = errorHandlerRef;
1014    }
1015
1016    /**
1017     * Configuration of data formats.
1018     */
1019    public void setDataFormats(DataFormatsDefinition dataFormats) {
1020        this.dataFormats = dataFormats;
1021    }
1022
1023    public DataFormatsDefinition getDataFormats() {
1024        return dataFormats;
1025    }
1026
1027    /**
1028     * Configuration of transformers.
1029     */
1030    public void setTransformers(TransformersDefinition transformers) {
1031        this.transformers = transformers;
1032    }
1033
1034    public TransformersDefinition getTransformers() {
1035        return transformers;
1036    }
1037
1038    /**
1039     * Configuration of validators.
1040     */
1041    public void setValidators(ValidatorsDefinition validators) {
1042        this.validators = validators;
1043    }
1044
1045    public ValidatorsDefinition getValidators() {
1046        return validators;
1047    }
1048
1049    /**
1050     * Configuration of redelivery settings.
1051     */
1052    public void setRedeliveryPolicies(List<CamelRedeliveryPolicyFactoryBean> redeliveryPolicies) {
1053        this.redeliveryPolicies = redeliveryPolicies;
1054    }
1055
1056    @Override
1057    public List<AbstractCamelFactoryBean<?>> getBeansFactory() {
1058        return beansFactory;
1059    }
1060
1061    /**
1062     * Miscellaneous configurations
1063     */
1064    public void setBeansFactory(List<AbstractCamelFactoryBean<?>> beansFactory) {
1065        this.beansFactory = beansFactory;
1066    }
1067
1068    @Override
1069    public List<?> getBeans() {
1070        return beans;
1071    }
1072
1073    /**
1074     * Miscellaneous configurations
1075     */
1076    public void setBeans(List<?> beans) {
1077        this.beans = beans;
1078    }
1079
1080    @Override
1081    public ServiceCallConfigurationDefinition getDefaultServiceCallConfiguration() {
1082        return defaultServiceCallConfiguration;
1083    }
1084
1085    /**
1086     * ServiceCall EIP default configuration
1087     */
1088    public void setDefaultServiceCallConfiguration(ServiceCallConfigurationDefinition defaultServiceCallConfiguration) {
1089        this.defaultServiceCallConfiguration = defaultServiceCallConfiguration;
1090    }
1091
1092    @Override
1093    public List<ServiceCallConfigurationDefinition> getServiceCallConfigurations() {
1094        return serviceCallConfigurations;
1095    }
1096
1097    /**
1098     * ServiceCall EIP configurations
1099     */
1100    public void setServiceCallConfigurations(List<ServiceCallConfigurationDefinition> serviceCallConfigurations) {
1101        this.serviceCallConfigurations = serviceCallConfigurations;
1102    }
1103
1104    @Override
1105    public List<HystrixConfigurationDefinition> getHystrixConfigurations() {
1106        return hystrixConfigurations;
1107    }
1108
1109    @Override
1110    public HystrixConfigurationDefinition getDefaultHystrixConfiguration() {
1111        return defaultHystrixConfiguration;
1112    }
1113
1114    /**
1115     * Hystrix EIP default configuration
1116     */
1117    public void setDefaultHystrixConfiguration(HystrixConfigurationDefinition defaultHystrixConfiguration) {
1118        this.defaultHystrixConfiguration = defaultHystrixConfiguration;
1119    }
1120
1121    /**
1122     * Hystrix EIP configurations
1123     */
1124    public void setHystrixConfigurations(List<HystrixConfigurationDefinition> hystrixConfigurations) {
1125        this.hystrixConfigurations = hystrixConfigurations;
1126    }
1127
1128    /**
1129     * Configuration of error handlers that triggers on exceptions thrown.
1130     */
1131    public void setOnExceptions(List<OnExceptionDefinition> onExceptions) {
1132        this.onExceptions = onExceptions;
1133    }
1134
1135    public List<OnExceptionDefinition> getOnExceptions() {
1136        return onExceptions;
1137    }
1138
1139    public List<OnCompletionDefinition> getOnCompletions() {
1140        return onCompletions;
1141    }
1142
1143    /**
1144     * Configuration of sub routes to run at the completion of routing.
1145     */
1146    public void setOnCompletions(List<OnCompletionDefinition> onCompletions) {
1147        this.onCompletions = onCompletions;
1148    }
1149
1150    public ShutdownRoute getShutdownRoute() {
1151        return shutdownRoute;
1152    }
1153
1154    /**
1155     * Sets the ShutdownRoute option for routes.
1156     */
1157    public void setShutdownRoute(ShutdownRoute shutdownRoute) {
1158        this.shutdownRoute = shutdownRoute;
1159    }
1160
1161    public ShutdownRunningTask getShutdownRunningTask() {
1162        return shutdownRunningTask;
1163    }
1164
1165    /**
1166     * Sets the ShutdownRunningTask option to use when shutting down a route.
1167     */
1168    public void setShutdownRunningTask(ShutdownRunningTask shutdownRunningTask) {
1169        this.shutdownRunningTask = shutdownRunningTask;
1170    }
1171
1172    public List<ThreadPoolProfileDefinition> getThreadPoolProfiles() {
1173        return threadPoolProfiles;
1174    }
1175
1176    /**
1177     * Configuration of thread pool profiles.
1178     */
1179    public void setThreadPoolProfiles(List<ThreadPoolProfileDefinition> threadPoolProfiles) {
1180        this.threadPoolProfiles = threadPoolProfiles;
1181    }
1182
1183    public List<CamelThreadPoolFactoryBean> getThreadPools() {
1184        return threadPools;
1185    }
1186
1187    /**
1188     * Configuration of thread pool
1189     */
1190    public void setThreadPools(List<CamelThreadPoolFactoryBean> threadPools) {
1191        this.threadPools = threadPools;
1192    }
1193
1194    public String getDependsOn() {
1195        return dependsOn;
1196    }
1197
1198    /**
1199     * List of other bean id's this CamelContext depends up. Multiple bean id's can be separated by comma.
1200     */
1201    public void setDependsOn(String dependsOn) {
1202        this.dependsOn = dependsOn;
1203    }
1204    
1205    public boolean isImplicitId() {
1206        return implicitId;
1207    }
1208    
1209    public void setImplicitId(boolean flag) {
1210        implicitId = flag;
1211    }
1212}