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