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