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