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